#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin>>n;
vector<pair<long long, long long>> vect(n);
for (long long i=0;i<n;i++) cin>>vect[i].first>>vect[i].second;
sort(vect.begin(), vect.end());
long long s=0, e=0, sum=vect[0].second, best=vect[0].second;
while (e<n){
if (s==e){
e++;
if (e==n) break;
sum+=vect[e].second;
if (best<sum-vect[e].first+vect[s].first) best=sum-vect[e].first+vect[s].first;
continue;
}
if (vect[s].first>vect[s].first+vect[s].second){
s++;
sum-=vect[s-1].second;
if (best<sum-vect[e].first+vect[s].first) best=sum-vect[e].first+vect[s].first;
continue;
}
e++;
if (e==n) break;
sum+=vect[e].second;
if (best<sum-vect[e].first+vect[s].first) best=sum-vect[e].first+vect[s].first;
}
cout<<best<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |