#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 10;
int n;
int a[N], b[N];
int st[4 * N];
int lzy[4 * N];
void propagate(int index, int l, int mid, int r) {
if(2 * index + 1 < 4 * N) {
st[2 * index] += lzy[index];
lzy[2 * index] += lzy[index];
st[2 * index + 1] += lzy[index];
lzy[2 * index + 1] += lzy[index];
lzy[index] = 0;
}
}
void update(int index, int l, int r, int L, int R, int val) {
if(l > r || r < L || R < l) return;
if(L <= l && r <= R) {
st[index] += val;
lzy[index] += val;
return;
}
int mid = (l + r) >> 1;
propagate(index, l, mid, r);
update(2 * index, l, mid, L, R, val);
update(2 * index + 1, mid + 1, r, L, R, val);
st[index] = max(st[2 * index], st[2 * index + 1]);
}
int get(int index, int l, int r, int L, int R) {
if(l > r || r < L || R < l) return 0;
if(L <= l && r <= R) return st[index];
int mid = (l + r) >> 1;
propagate(index, l, mid, r);
return max(get(2 * index, l, mid, L, R), get(2 * index + 1, mid + 1, r, L, R));
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
pair<int, int> p[n + 1];
for(int i = 1; i <= n; i++) {
p[i].first = a[i];
p[i].second = b[i];
}
sort(p + 1, p + n + 1);
for(int i = 1; i <= n; i++) {
a[i] = p[i].first;
b[i] = p[i].second;
}
int res = 0;
for(int i = 1; i <= n; i++) {
update(1, 1, n, i, i, a[i]);
update(1, 1, n, 1, i, b[i]);
res = max(res, get(1, 1, n, 1, i) - a[i]);
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
5 ms |
856 KB |
Output is correct |
28 |
Correct |
6 ms |
852 KB |
Output is correct |
29 |
Correct |
6 ms |
856 KB |
Output is correct |
30 |
Correct |
5 ms |
852 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
6 ms |
772 KB |
Output is correct |
33 |
Correct |
6 ms |
840 KB |
Output is correct |
34 |
Correct |
7 ms |
852 KB |
Output is correct |
35 |
Correct |
6 ms |
804 KB |
Output is correct |
36 |
Correct |
6 ms |
880 KB |
Output is correct |
37 |
Correct |
5 ms |
784 KB |
Output is correct |
38 |
Correct |
4 ms |
792 KB |
Output is correct |
39 |
Correct |
11 ms |
872 KB |
Output is correct |
40 |
Correct |
5 ms |
848 KB |
Output is correct |
41 |
Correct |
6 ms |
784 KB |
Output is correct |
42 |
Correct |
8 ms |
848 KB |
Output is correct |
43 |
Correct |
5 ms |
800 KB |
Output is correct |
44 |
Correct |
5 ms |
844 KB |
Output is correct |
45 |
Correct |
5 ms |
792 KB |
Output is correct |
46 |
Correct |
7 ms |
852 KB |
Output is correct |
47 |
Correct |
9 ms |
852 KB |
Output is correct |
48 |
Correct |
6 ms |
856 KB |
Output is correct |
49 |
Correct |
5 ms |
852 KB |
Output is correct |
50 |
Correct |
4 ms |
852 KB |
Output is correct |
51 |
Correct |
5 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
5 ms |
856 KB |
Output is correct |
28 |
Correct |
6 ms |
852 KB |
Output is correct |
29 |
Correct |
6 ms |
856 KB |
Output is correct |
30 |
Correct |
5 ms |
852 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
6 ms |
772 KB |
Output is correct |
33 |
Correct |
6 ms |
840 KB |
Output is correct |
34 |
Correct |
7 ms |
852 KB |
Output is correct |
35 |
Correct |
6 ms |
804 KB |
Output is correct |
36 |
Correct |
6 ms |
880 KB |
Output is correct |
37 |
Correct |
5 ms |
784 KB |
Output is correct |
38 |
Correct |
4 ms |
792 KB |
Output is correct |
39 |
Correct |
11 ms |
872 KB |
Output is correct |
40 |
Correct |
5 ms |
848 KB |
Output is correct |
41 |
Correct |
6 ms |
784 KB |
Output is correct |
42 |
Correct |
8 ms |
848 KB |
Output is correct |
43 |
Correct |
5 ms |
800 KB |
Output is correct |
44 |
Correct |
5 ms |
844 KB |
Output is correct |
45 |
Correct |
5 ms |
792 KB |
Output is correct |
46 |
Correct |
7 ms |
852 KB |
Output is correct |
47 |
Correct |
9 ms |
852 KB |
Output is correct |
48 |
Correct |
6 ms |
856 KB |
Output is correct |
49 |
Correct |
5 ms |
852 KB |
Output is correct |
50 |
Correct |
4 ms |
852 KB |
Output is correct |
51 |
Correct |
5 ms |
844 KB |
Output is correct |
52 |
Correct |
574 ms |
45068 KB |
Output is correct |
53 |
Correct |
531 ms |
44912 KB |
Output is correct |
54 |
Correct |
555 ms |
45012 KB |
Output is correct |
55 |
Correct |
500 ms |
44988 KB |
Output is correct |
56 |
Correct |
473 ms |
44940 KB |
Output is correct |
57 |
Correct |
490 ms |
44936 KB |
Output is correct |
58 |
Correct |
535 ms |
45000 KB |
Output is correct |
59 |
Correct |
490 ms |
44988 KB |
Output is correct |
60 |
Correct |
495 ms |
44980 KB |
Output is correct |
61 |
Correct |
533 ms |
44876 KB |
Output is correct |
62 |
Correct |
497 ms |
44988 KB |
Output is correct |
63 |
Correct |
520 ms |
45068 KB |
Output is correct |
64 |
Correct |
499 ms |
44920 KB |
Output is correct |
65 |
Correct |
485 ms |
44948 KB |
Output is correct |
66 |
Correct |
492 ms |
44948 KB |
Output is correct |
67 |
Correct |
497 ms |
45048 KB |
Output is correct |
68 |
Correct |
483 ms |
45004 KB |
Output is correct |