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>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<pair<int,int>> arr(N);
for(int i = 0;i<N;++i) cin >> arr[i].f >> arr[i].s;
sort(arr.begin(),arr.end());
vector<int> pref(N); pref[0] = arr[0].s;
for(int i = 1;i<N;++i) pref[i] = pref[i-1]+arr[i].s;
int ans = -1, mincur = -arr[0].f;
for(int i = 1;i<N;++i){
int cur = pref[i-1]-arr[i].f;
mincur = min(mincur,cur);
ans = max(ans,cur+arr[i].s-mincur);
//cout << ans << " " << mincur << " " << cur << "\n";
}
cout << ans << "\n";
return 0;
}
# | 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... |