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> v[600000];
long long maxi=0, minid=0, maxid=0, S=0;
int main()
{
cin>>N;
for (int i=0; i<N; i++){
long long a, b;
cin>>a>>b;
v[i]={a, b};
}
sort(v, v+N);
for (int i=0; i<N; i++){
S=v[i].second;
minid=v[i].first;
maxid=v[i].first;
maxi=max(maxi, (S-(maxid-minid)));
for (int j=i+1; j<N; j++){
S+=v[j].second;
maxid=max(maxid, v[j].first);
minid=min(minid, v[j].first);
maxi=max(maxi, (S-(maxid-minid)));
}
}
cout<<maxi;
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... |