#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)
using namespace std;
typedef long long ll;
const int N = 500002;
struct data{
ll a, b;
} a[N];
bool cmp(data a1, data a2){
return a1.a < a2.a;
}
int n; ll f[N];
int main(){
ios_base::sync_with_stdio(0);
cin >> n;
f1(i, n) cin >> a[i].a >> a[i].b;
sort(a + 1, a + n + 1, cmp);
ll ma = 0;
f1(i, n){
f[i] = a[i].b;
f[i] = max(f[i], ma + a[i].b - a[i].a);
ma = max(ma, f[i] + a[i].a);
}
cout << *max_element(f + 1, f + n + 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
572 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
3 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
572 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
3 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
3 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
2 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
776 KB |
Output is correct |
25 |
Correct |
2 ms |
784 KB |
Output is correct |
26 |
Correct |
2 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
572 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
3 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
3 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
2 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
776 KB |
Output is correct |
25 |
Correct |
2 ms |
784 KB |
Output is correct |
26 |
Correct |
2 ms |
792 KB |
Output is correct |
27 |
Correct |
5 ms |
1056 KB |
Output is correct |
28 |
Correct |
4 ms |
1184 KB |
Output is correct |
29 |
Correct |
5 ms |
1312 KB |
Output is correct |
30 |
Correct |
5 ms |
1440 KB |
Output is correct |
31 |
Correct |
4 ms |
1568 KB |
Output is correct |
32 |
Correct |
4 ms |
1696 KB |
Output is correct |
33 |
Correct |
4 ms |
1824 KB |
Output is correct |
34 |
Correct |
4 ms |
1952 KB |
Output is correct |
35 |
Correct |
4 ms |
2080 KB |
Output is correct |
36 |
Correct |
4 ms |
2320 KB |
Output is correct |
37 |
Correct |
5 ms |
2324 KB |
Output is correct |
38 |
Correct |
4 ms |
2464 KB |
Output is correct |
39 |
Correct |
4 ms |
2592 KB |
Output is correct |
40 |
Correct |
4 ms |
2600 KB |
Output is correct |
41 |
Correct |
4 ms |
2848 KB |
Output is correct |
42 |
Correct |
4 ms |
2972 KB |
Output is correct |
43 |
Correct |
4 ms |
3100 KB |
Output is correct |
44 |
Correct |
4 ms |
3228 KB |
Output is correct |
45 |
Correct |
4 ms |
3356 KB |
Output is correct |
46 |
Correct |
4 ms |
3484 KB |
Output is correct |
47 |
Correct |
4 ms |
3616 KB |
Output is correct |
48 |
Correct |
4 ms |
3744 KB |
Output is correct |
49 |
Correct |
5 ms |
3872 KB |
Output is correct |
50 |
Correct |
4 ms |
4000 KB |
Output is correct |
51 |
Correct |
4 ms |
4128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
572 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
2 ms |
572 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
2 ms |
572 KB |
Output is correct |
8 |
Correct |
3 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
3 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
2 ms |
744 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
776 KB |
Output is correct |
25 |
Correct |
2 ms |
784 KB |
Output is correct |
26 |
Correct |
2 ms |
792 KB |
Output is correct |
27 |
Correct |
5 ms |
1056 KB |
Output is correct |
28 |
Correct |
4 ms |
1184 KB |
Output is correct |
29 |
Correct |
5 ms |
1312 KB |
Output is correct |
30 |
Correct |
5 ms |
1440 KB |
Output is correct |
31 |
Correct |
4 ms |
1568 KB |
Output is correct |
32 |
Correct |
4 ms |
1696 KB |
Output is correct |
33 |
Correct |
4 ms |
1824 KB |
Output is correct |
34 |
Correct |
4 ms |
1952 KB |
Output is correct |
35 |
Correct |
4 ms |
2080 KB |
Output is correct |
36 |
Correct |
4 ms |
2320 KB |
Output is correct |
37 |
Correct |
5 ms |
2324 KB |
Output is correct |
38 |
Correct |
4 ms |
2464 KB |
Output is correct |
39 |
Correct |
4 ms |
2592 KB |
Output is correct |
40 |
Correct |
4 ms |
2600 KB |
Output is correct |
41 |
Correct |
4 ms |
2848 KB |
Output is correct |
42 |
Correct |
4 ms |
2972 KB |
Output is correct |
43 |
Correct |
4 ms |
3100 KB |
Output is correct |
44 |
Correct |
4 ms |
3228 KB |
Output is correct |
45 |
Correct |
4 ms |
3356 KB |
Output is correct |
46 |
Correct |
4 ms |
3484 KB |
Output is correct |
47 |
Correct |
4 ms |
3616 KB |
Output is correct |
48 |
Correct |
4 ms |
3744 KB |
Output is correct |
49 |
Correct |
5 ms |
3872 KB |
Output is correct |
50 |
Correct |
4 ms |
4000 KB |
Output is correct |
51 |
Correct |
4 ms |
4128 KB |
Output is correct |
52 |
Correct |
263 ms |
28252 KB |
Output is correct |
53 |
Correct |
259 ms |
40856 KB |
Output is correct |
54 |
Correct |
278 ms |
53704 KB |
Output is correct |
55 |
Correct |
269 ms |
66216 KB |
Output is correct |
56 |
Correct |
280 ms |
78808 KB |
Output is correct |
57 |
Correct |
272 ms |
91484 KB |
Output is correct |
58 |
Correct |
269 ms |
104256 KB |
Output is correct |
59 |
Correct |
253 ms |
116900 KB |
Output is correct |
60 |
Correct |
257 ms |
129416 KB |
Output is correct |
61 |
Correct |
257 ms |
141932 KB |
Output is correct |
62 |
Correct |
257 ms |
143440 KB |
Output is correct |
63 |
Correct |
268 ms |
143544 KB |
Output is correct |
64 |
Correct |
272 ms |
143600 KB |
Output is correct |
65 |
Correct |
253 ms |
143600 KB |
Output is correct |
66 |
Correct |
269 ms |
143600 KB |
Output is correct |
67 |
Correct |
275 ms |
143648 KB |
Output is correct |
68 |
Correct |
261 ms |
143648 KB |
Output is correct |