#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define st first
#define nd second
#define pb push_back
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
vector<pair<ll,ll>> sortowane;
ll a,b;
for(int i=1;i<=n;i++){
cin>>a>>b;
sortowane.pb({a,b});
}
sort(sortowane.begin(),sortowane.end());
ll wyn = 0,akt = 0,pref=0,suma=0;
akt = sortowane[0].nd;
suma += sortowane[0].nd;
for(int i=1;i<n;i++){
akt += sortowane[i].nd - (sortowane[i].st - sortowane[i-1].st);
pref = max(pref,sortowane[i].st - sortowane[0].st - suma);
suma += sortowane[i].nd;
wyn = max(wyn,akt+pref);
}
cout<<wyn<<"\n";
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... |