/*
sort by size
use same algo as max continuous subsequence sum
keep adding next picture until it would be better to not take previous
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
#define s <<" "<<
#define w cout
#define e "\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
const int MAXN=500000, INF=1000000000000000000;
///500,000,000
int N, curr, out;
pair <int, int> inp[MAXN];
main() {
//ifstream cin("test.in");
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
ffi cin >> inp[i].a >> inp[i].b;
sort(inp, inp+N);
curr = out = inp[0].b;
For (i, 1, N) {
/// add value, subtract size - size[i-1]
curr += inp[i].b - (inp[i].a - inp[i-1].a);
curr = max(curr, inp[i].b);
out = max(out, curr);
}
w<< out<<e;
}
Compilation message
art.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
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 |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
3 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
828 KB |
Output is correct |
# |
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 |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
3 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
828 KB |
Output is correct |
12 |
Correct |
2 ms |
828 KB |
Output is correct |
13 |
Correct |
2 ms |
828 KB |
Output is correct |
14 |
Correct |
2 ms |
828 KB |
Output is correct |
15 |
Correct |
2 ms |
828 KB |
Output is correct |
16 |
Correct |
2 ms |
828 KB |
Output is correct |
17 |
Correct |
2 ms |
828 KB |
Output is correct |
18 |
Correct |
2 ms |
916 KB |
Output is correct |
19 |
Correct |
3 ms |
916 KB |
Output is correct |
20 |
Correct |
2 ms |
916 KB |
Output is correct |
21 |
Correct |
2 ms |
916 KB |
Output is correct |
22 |
Correct |
2 ms |
916 KB |
Output is correct |
23 |
Correct |
3 ms |
916 KB |
Output is correct |
24 |
Correct |
2 ms |
916 KB |
Output is correct |
25 |
Correct |
2 ms |
916 KB |
Output is correct |
26 |
Correct |
3 ms |
916 KB |
Output is correct |
# |
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 |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
3 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
828 KB |
Output is correct |
12 |
Correct |
2 ms |
828 KB |
Output is correct |
13 |
Correct |
2 ms |
828 KB |
Output is correct |
14 |
Correct |
2 ms |
828 KB |
Output is correct |
15 |
Correct |
2 ms |
828 KB |
Output is correct |
16 |
Correct |
2 ms |
828 KB |
Output is correct |
17 |
Correct |
2 ms |
828 KB |
Output is correct |
18 |
Correct |
2 ms |
916 KB |
Output is correct |
19 |
Correct |
3 ms |
916 KB |
Output is correct |
20 |
Correct |
2 ms |
916 KB |
Output is correct |
21 |
Correct |
2 ms |
916 KB |
Output is correct |
22 |
Correct |
2 ms |
916 KB |
Output is correct |
23 |
Correct |
3 ms |
916 KB |
Output is correct |
24 |
Correct |
2 ms |
916 KB |
Output is correct |
25 |
Correct |
2 ms |
916 KB |
Output is correct |
26 |
Correct |
3 ms |
916 KB |
Output is correct |
27 |
Correct |
7 ms |
1036 KB |
Output is correct |
28 |
Correct |
5 ms |
1192 KB |
Output is correct |
29 |
Correct |
4 ms |
1308 KB |
Output is correct |
30 |
Correct |
4 ms |
1468 KB |
Output is correct |
31 |
Correct |
5 ms |
1596 KB |
Output is correct |
32 |
Correct |
5 ms |
1852 KB |
Output is correct |
33 |
Correct |
5 ms |
1852 KB |
Output is correct |
34 |
Correct |
5 ms |
1936 KB |
Output is correct |
35 |
Correct |
4 ms |
2060 KB |
Output is correct |
36 |
Correct |
4 ms |
2216 KB |
Output is correct |
37 |
Correct |
4 ms |
2316 KB |
Output is correct |
38 |
Correct |
4 ms |
2444 KB |
Output is correct |
39 |
Correct |
5 ms |
2600 KB |
Output is correct |
40 |
Correct |
4 ms |
2756 KB |
Output is correct |
41 |
Correct |
4 ms |
2884 KB |
Output is correct |
42 |
Correct |
5 ms |
2952 KB |
Output is correct |
43 |
Correct |
5 ms |
3080 KB |
Output is correct |
44 |
Correct |
5 ms |
3364 KB |
Output is correct |
45 |
Correct |
4 ms |
3364 KB |
Output is correct |
46 |
Correct |
4 ms |
3468 KB |
Output is correct |
47 |
Correct |
5 ms |
3596 KB |
Output is correct |
48 |
Correct |
4 ms |
3724 KB |
Output is correct |
49 |
Correct |
4 ms |
3852 KB |
Output is correct |
50 |
Correct |
4 ms |
3980 KB |
Output is correct |
51 |
Correct |
5 ms |
4108 KB |
Output is correct |
# |
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 |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
3 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
2 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
828 KB |
Output is correct |
12 |
Correct |
2 ms |
828 KB |
Output is correct |
13 |
Correct |
2 ms |
828 KB |
Output is correct |
14 |
Correct |
2 ms |
828 KB |
Output is correct |
15 |
Correct |
2 ms |
828 KB |
Output is correct |
16 |
Correct |
2 ms |
828 KB |
Output is correct |
17 |
Correct |
2 ms |
828 KB |
Output is correct |
18 |
Correct |
2 ms |
916 KB |
Output is correct |
19 |
Correct |
3 ms |
916 KB |
Output is correct |
20 |
Correct |
2 ms |
916 KB |
Output is correct |
21 |
Correct |
2 ms |
916 KB |
Output is correct |
22 |
Correct |
2 ms |
916 KB |
Output is correct |
23 |
Correct |
3 ms |
916 KB |
Output is correct |
24 |
Correct |
2 ms |
916 KB |
Output is correct |
25 |
Correct |
2 ms |
916 KB |
Output is correct |
26 |
Correct |
3 ms |
916 KB |
Output is correct |
27 |
Correct |
7 ms |
1036 KB |
Output is correct |
28 |
Correct |
5 ms |
1192 KB |
Output is correct |
29 |
Correct |
4 ms |
1308 KB |
Output is correct |
30 |
Correct |
4 ms |
1468 KB |
Output is correct |
31 |
Correct |
5 ms |
1596 KB |
Output is correct |
32 |
Correct |
5 ms |
1852 KB |
Output is correct |
33 |
Correct |
5 ms |
1852 KB |
Output is correct |
34 |
Correct |
5 ms |
1936 KB |
Output is correct |
35 |
Correct |
4 ms |
2060 KB |
Output is correct |
36 |
Correct |
4 ms |
2216 KB |
Output is correct |
37 |
Correct |
4 ms |
2316 KB |
Output is correct |
38 |
Correct |
4 ms |
2444 KB |
Output is correct |
39 |
Correct |
5 ms |
2600 KB |
Output is correct |
40 |
Correct |
4 ms |
2756 KB |
Output is correct |
41 |
Correct |
4 ms |
2884 KB |
Output is correct |
42 |
Correct |
5 ms |
2952 KB |
Output is correct |
43 |
Correct |
5 ms |
3080 KB |
Output is correct |
44 |
Correct |
5 ms |
3364 KB |
Output is correct |
45 |
Correct |
4 ms |
3364 KB |
Output is correct |
46 |
Correct |
4 ms |
3468 KB |
Output is correct |
47 |
Correct |
5 ms |
3596 KB |
Output is correct |
48 |
Correct |
4 ms |
3724 KB |
Output is correct |
49 |
Correct |
4 ms |
3852 KB |
Output is correct |
50 |
Correct |
4 ms |
3980 KB |
Output is correct |
51 |
Correct |
5 ms |
4108 KB |
Output is correct |
52 |
Correct |
249 ms |
24656 KB |
Output is correct |
53 |
Correct |
245 ms |
37184 KB |
Output is correct |
54 |
Correct |
229 ms |
49848 KB |
Output is correct |
55 |
Correct |
243 ms |
62600 KB |
Output is correct |
56 |
Correct |
235 ms |
75196 KB |
Output is correct |
57 |
Correct |
231 ms |
88040 KB |
Output is correct |
58 |
Correct |
230 ms |
100548 KB |
Output is correct |
59 |
Correct |
231 ms |
113264 KB |
Output is correct |
60 |
Correct |
231 ms |
126076 KB |
Output is correct |
61 |
Correct |
251 ms |
138540 KB |
Output is correct |
62 |
Correct |
239 ms |
151152 KB |
Output is correct |
63 |
Correct |
232 ms |
163792 KB |
Output is correct |
64 |
Correct |
236 ms |
176616 KB |
Output is correct |
65 |
Correct |
235 ms |
189240 KB |
Output is correct |
66 |
Correct |
226 ms |
201840 KB |
Output is correct |
67 |
Correct |
230 ms |
214576 KB |
Output is correct |
68 |
Correct |
237 ms |
227176 KB |
Output is correct |