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;
pair<long long, long long> arr[500005];
long long pre[500005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i<=N; i++){
cin >> arr[i].first >> arr[i].second;
}
sort(arr+1, arr+1+N);
for(int i = 1; i<=N; i++){
pre[i] = pre[i-1] + arr[i].second;
}
long long mn = LLONG_MAX/4;
long long ans = 0;
for(int i = 1; i<=N; i++){
ans = max(ans, pre[i] - arr[i].first - mn);
mn = min(mn, - arr[i].first + pre[i-1]);
}
cout << ans << "\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... |