#include<bits/stdc++.h>
using namespace std;
int main(){
vector<pair<long long,long long>> V;
long long n;
cin>>n;
for(long long i=0;i<n;i++){
long long a,b;
cin>>a>>b;
V.push_back(make_pair(a,b));
}
sort(V.begin(),V.end());
long long sum=0,best=0,i=0;
for (int k=0;k<n; k++) {
if(V[k].second>sum+V[k].second-(V[k].first-V[i].first)){
i=k;
sum=V[k].second;
}else{
sum+=V[k].second;
}
best = max(best,sum-(V[k].first-V[i].first));
}
cout << best << "\n";
}
# | 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... |