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 maxn 500009
using namespace std;
pair<long long,long long> a[maxn];
long long A[maxn], s[maxn], B[maxn];
main(){
long long n;
cin >> n;
for(long long i= 1; i <= n; i++)
cin >> a[i].first >> a[i].second;
sort(a + 1, a + n + 1);
for(long long i = 1; i <= n; i++){
s[i] = s[i - 1] + a[i] . second;
}
for(long long i = 1 ; i <= n; i++){
A[i] = s[i] - a[i] . first;
B[i] = -a[i] .first + s[i - 1];
}
long long MI = 1e18, ans = -1e18;
for(long long i = 1; i <= n; i++){
MI = min(MI, B[i]);
ans = max(ans, A[i] - MI);
}
cout<< ans << endl;
}
Compilation message (stderr)
art.cpp:6:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | 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... |