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 main(){
int n;
cin>>n;
pair<long long, long long> arr[n];
for(int i=0; i<n; i++){
cin>>arr[i].first>>arr[i].second;
}
sort(arr, arr+n);
long long pref[n];
pref[0] = arr[0].second;
for(int i=1; i<n; i++){
pref[i] = pref[i-1] + arr[i].second;
}
long long ans = 0;
for(int l=0; l<n; l++){
for(int r=l; r<n; r++){
long long sum = pref[r];
if(l != 0) sum -= pref[l-1];
ans = max(ans, sum-(arr[r].first-arr[l].first));
}
}
cout<<ans<<endl;
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... |