#include<bits/stdc++.h>
#define maxn 500010
using namespace std;
long long int maxx[maxn],p[maxn];
pair<long long int,int> s[maxn];
int main()
{
int n; cin>>n;
for(int i = 1;i<=n;i++) cin>>s[i].first>>s[i].second;
sort(s+1,s+n+1);
long long int suma = 0;
for(int i = 0;i<n;i++){
suma+=s[i].second;
p[i] = suma;
}
for(int i = 1;i<=n;i++){
maxx[i] = max(maxx[i-1],s[i].first-p[i-1]);
}
long long int res = 0;
for(int i = 1;i<=n;i++){
res = max(res,p[i]-s[i].first+maxx[i]);
}
cout<<res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |