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 <iostream>
#include <algorithm>
#include <utility>
#define pii pair<int,int>
#define F first
#define S second
#define int long long int
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int maxN = 5e5 + 326;
pii vals[maxN];
int N, ans, maxVal;
//(vals[r].S - vals[l - 1].S) - (vals[r].F - vals[l].F)
//(vals[r].S - vals[r].F) + (vals[l].F - vals[l - 1].S)
signed main(){
ericxiao;
cin >> N;
for(int i = 1; i <= N; i++) cin >> vals[i].F >> vals[i].S;
sort(vals + 1, vals + N + 1);
for(int i = 1; i <= N; i++) vals[i].S += vals[i - 1].S;
ans = vals[N].S - vals[N - 1].S;
maxVal = vals[N].S - vals[N].F;
for(int i = N - 1; i; i--){
ans = max(ans, maxVal + vals[i].F - vals[i - 1].S);
ans = max(ans, vals[i].S - vals[i - 1].S);
maxVal = max(maxVal, vals[i].S - vals[i].F);
}
cout << ans << endl;
}
# | 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... |