#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PUB push_back
struct art{
ll sz, val;
};
int N;
ll pref[500005], ans = 0;
vector<art> data;
bool comp(art a, art b){
if(a.sz == b.sz) return a.val < b.val;
return a.sz < b.sz;
}
int main(){
cin >> N;
data.PUB({0,0});
for(int i=1;i<=N;i++){
ll a, b;
cin >> a >> b;
data.PUB({a, b});
}
sort(data.begin(), data.end(), comp);
for(int i=1;i<=N;i++) pref[i] = pref[i-1]+data[i].val;
int l=1;
ll bef=0;
for(int i=1;i<=N;i++){
ll tmp = (pref[i]-pref[l-1])-(data[i].sz-data[l].sz);
if(bef > tmp){
l=i;
tmp = (pref[i]-pref[l-1])-(data[i].sz-data[l].sz);
}
bef = tmp;
ans = max(ans, tmp);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
412 KB |
Output is correct |
5 |
Incorrect |
2 ms |
428 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
412 KB |
Output is correct |
5 |
Incorrect |
2 ms |
428 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
412 KB |
Output is correct |
5 |
Incorrect |
2 ms |
428 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
412 KB |
Output is correct |
5 |
Incorrect |
2 ms |
428 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |