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;
const int N = 2e5+55;
const long long inf = 1e16+66;
int32_t main()
{
int n;
cin>>n;
vector<pair<long long,long long>>v(n);
for(int i = 0; i < n; i++){
cin>>v[i].first>>v[i].second;
}
sort(v.begin() , v.end());
reverse(v.begin() , v.end());
long long pre[n+1];
pre[0] = 0;
for(int i=1;i<=n;i++){
pre[i] = pre[i-1] + v[i - 1].second;
}
long long mini = inf , res = 0;
for(int i=1;i<=n;i++){
mini=min(mini,pre[i-1] + v[i - 1].first);
res=max(res,pre[i] + v[i - 1].first - mini);
}
cout << res;
return 0;
}
/*
1 1 2 2 3 3 4 4
1
*/
# | 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... |