// created : 2026/02/08 18:40:30
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
void solve()
{
int n;
cin >> n;
vector<pair<int, int>> vt;
for (int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
vt.pb({x, y});
}
sort(all(vt));
int maxi = 0;
for (int i = 0; i < n; i++)
{
int l = i + 1, r = n - 1;
while (l <= r)
{
int m = (r + l) / 2;
int sum = 0, a = LLONG_MIN, b = LLONG_MAX;
bool check = false;
for (int j = i; j < m; j++)
{
a = max(vt[j].first, a), b = min(vt[j].first, b);
sum += vt[j].second;
if (maxi < sum - (a - b))
{
maxi = sum - (a - b);
check = true;
}
}
if (check)
{
l = m + 1;
}
else
{
r = m - 1;
}
}
}
cout << maxi << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |