This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n;
vector<long long> p;
vector<pair<long long, int>> a;
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++){
int y;
long long x;
cin >> x >> y;
a.push_back({x, y});
}
sort(a.begin(), a.end());
p.resize(n, 0ll);
for(int i = 0; i < n; i ++){
if(i > 0) p[i] = p[i - 1];
p[i] += a[i].second;
}
int j = 0;
long long mx = 0;
long long mn = LONG_MAX;
for(int i = 0; i < n; i ++){
long long x = (i == 0 ? 0 : p[i - 1]) - a[i].first;
if(x < mn){
mn = x;
j = i;
}
long long sum = p[i];
if(j > 0) sum -= p[j - 1];
mx = max(mx, sum - (a[i].first - a[j].first));
}
cout << mx << "\n";
}
# | 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... |