//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
void solve() {
int n;
cin >> n;
vector<pair<ll, ll>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end());
// vector<pair<ll, ll>> b;
// for (auto p : a) {
// if (b.empty())
// b.push_back(p);
// else if (b.back().first == p.first) {
// b.back().second += p.second;
// } else
// b.push_back(p);
// }
ll ans = a[0].second;
ll sum = a[0].second;
for (int i = 1; i < n; i++) {
sum += a[i].second - (a[i].first - a[i - 1].first);
if(sum < a[i].second)
sum = a[i].second;
ans = max(ans,sum);
}
cout << ans;
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
292 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
292 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
292 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
292 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
292 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
5 ms |
432 KB |
Output is correct |
29 |
Correct |
5 ms |
412 KB |
Output is correct |
30 |
Correct |
5 ms |
480 KB |
Output is correct |
31 |
Correct |
5 ms |
460 KB |
Output is correct |
32 |
Correct |
5 ms |
432 KB |
Output is correct |
33 |
Correct |
8 ms |
428 KB |
Output is correct |
34 |
Correct |
5 ms |
460 KB |
Output is correct |
35 |
Correct |
6 ms |
492 KB |
Output is correct |
36 |
Correct |
6 ms |
420 KB |
Output is correct |
37 |
Correct |
5 ms |
428 KB |
Output is correct |
38 |
Correct |
5 ms |
460 KB |
Output is correct |
39 |
Correct |
6 ms |
424 KB |
Output is correct |
40 |
Correct |
5 ms |
460 KB |
Output is correct |
41 |
Correct |
5 ms |
460 KB |
Output is correct |
42 |
Correct |
5 ms |
460 KB |
Output is correct |
43 |
Correct |
5 ms |
460 KB |
Output is correct |
44 |
Correct |
5 ms |
460 KB |
Output is correct |
45 |
Correct |
5 ms |
432 KB |
Output is correct |
46 |
Correct |
5 ms |
460 KB |
Output is correct |
47 |
Correct |
5 ms |
460 KB |
Output is correct |
48 |
Correct |
6 ms |
476 KB |
Output is correct |
49 |
Correct |
6 ms |
428 KB |
Output is correct |
50 |
Correct |
6 ms |
476 KB |
Output is correct |
51 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
292 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
292 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
5 ms |
432 KB |
Output is correct |
29 |
Correct |
5 ms |
412 KB |
Output is correct |
30 |
Correct |
5 ms |
480 KB |
Output is correct |
31 |
Correct |
5 ms |
460 KB |
Output is correct |
32 |
Correct |
5 ms |
432 KB |
Output is correct |
33 |
Correct |
8 ms |
428 KB |
Output is correct |
34 |
Correct |
5 ms |
460 KB |
Output is correct |
35 |
Correct |
6 ms |
492 KB |
Output is correct |
36 |
Correct |
6 ms |
420 KB |
Output is correct |
37 |
Correct |
5 ms |
428 KB |
Output is correct |
38 |
Correct |
5 ms |
460 KB |
Output is correct |
39 |
Correct |
6 ms |
424 KB |
Output is correct |
40 |
Correct |
5 ms |
460 KB |
Output is correct |
41 |
Correct |
5 ms |
460 KB |
Output is correct |
42 |
Correct |
5 ms |
460 KB |
Output is correct |
43 |
Correct |
5 ms |
460 KB |
Output is correct |
44 |
Correct |
5 ms |
460 KB |
Output is correct |
45 |
Correct |
5 ms |
432 KB |
Output is correct |
46 |
Correct |
5 ms |
460 KB |
Output is correct |
47 |
Correct |
5 ms |
460 KB |
Output is correct |
48 |
Correct |
6 ms |
476 KB |
Output is correct |
49 |
Correct |
6 ms |
428 KB |
Output is correct |
50 |
Correct |
6 ms |
476 KB |
Output is correct |
51 |
Correct |
5 ms |
460 KB |
Output is correct |
52 |
Correct |
480 ms |
20640 KB |
Output is correct |
53 |
Correct |
485 ms |
20640 KB |
Output is correct |
54 |
Correct |
486 ms |
20644 KB |
Output is correct |
55 |
Correct |
502 ms |
20640 KB |
Output is correct |
56 |
Correct |
487 ms |
20676 KB |
Output is correct |
57 |
Correct |
492 ms |
20676 KB |
Output is correct |
58 |
Correct |
494 ms |
20636 KB |
Output is correct |
59 |
Correct |
482 ms |
20752 KB |
Output is correct |
60 |
Correct |
471 ms |
20640 KB |
Output is correct |
61 |
Correct |
476 ms |
20516 KB |
Output is correct |
62 |
Correct |
473 ms |
20640 KB |
Output is correct |
63 |
Correct |
482 ms |
20640 KB |
Output is correct |
64 |
Correct |
483 ms |
20764 KB |
Output is correct |
65 |
Correct |
471 ms |
20764 KB |
Output is correct |
66 |
Correct |
462 ms |
20676 KB |
Output is correct |
67 |
Correct |
473 ms |
20636 KB |
Output is correct |
68 |
Correct |
470 ms |
20644 KB |
Output is correct |