#include <bits/stdc++.h>
using namespace std;
int n, k;
pair <int, int> a[500009];
int d[100009];
struct dp {
int val1;
int val2;
int res;
int val;
} f[500009];
void bai4 (){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
sort (a + 1, a + n + 1);
int toiuu = 1;
int res = a[1].second;
f[1].res = a[1].second;
f[1].val1 = a[1].first;
f[1].val2 = a[1].first;
f[1].val = f[1].res + f[1].val2;
for (int i = 2; i <= n; i++){
f[i].res = a[i].second;
f[i].val1 = a[i].first;
f[i].val2 = a[i].first;
f[i].val = f[i].res + f[i].val2;
int x = f[toiuu].val - a[i].first + a[i].second;
if (x > f[i].res){
f[i].res = x;
f[i].val1 = f[toiuu].val1;
f[i].val2 = a[i].first;
f[i].val = f[i].res + f[i].val2;
}
if (f[i].val > f[toiuu].val){
toiuu = i;
}
res = max (res, f[i].res);
}
cout << res;
}
signed main (){
ios_base::sync_with_stdio (false);
cin.tie (NULL);
cout.tie (NULL);
bai4 ();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |