#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
using namespace std;
long n;
long long maxa[1100000] = {}, upd[1100000] = {};
void updf(long i, long s, long e, long l, long u, long long d) {
if (upd[i] != 0) {
maxa[i] += upd[i];
if (s != e) {
upd[i * 2 + 1] += upd[i];
upd[i * 2 + 2] += upd[i];
}
upd[i] = 0;
}
if (s > e || s > u || e < l) {
return;
}
if (s >= l && e <= u) {
maxa[i] += d;
if (s != e) {
upd[i * 2 + 1] += d;
upd[i * 2 + 2] += d;
}
return;
}
updf(i * 2 + 1, s, (s + e)/2, l, u, d);
updf(i * 2 + 2, (s + e)/2 + 1, e, l, u, d);
maxa[i] = max(maxa[i * 2 + 1], maxa[i * 2 + 2]);
}
void updh(long l, long u, long long d) {
long a = 0, b = 0;
updf(a, b, n-1, l, u, d);
}
long long maxf(long i, long s, long e, long l, long u) {
if (upd[i] != 0) {
maxa[i] += upd[i];
if (s != e) {
upd[i * 2 + 1] += upd[i];
upd[i * 2 + 2] += upd[i];
}
upd[i] = 0;
}
if (s > e || s > u || e < l) {
return -1000;
}
if (s >= l && e <= u) {
return maxa[i];
}
return max(maxf(2*i+1, s, (s+e)/2, l, u), maxf(2*i+2, (s+e)/2+1, e, l, u));
}
long long maxh(long l, long u) {
long a = 0, b = 0;
return maxf(a, b, n-1, l, u);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
vector< pair <long long,long> > vect;
for (int i = 0; i < n; i++) {
long long a;
long b;
cin >> a >> b;
vect.push_back( make_pair(a, b) );
}
sort(vect.begin(), vect.end());
long a = 0;
pair<long long, long> tp = vect[0];
long long size = tp.first, ans = 0;
updh(a, a, (long long) tp.second);
for (int i = 1; i < n; i++) {
tp = vect[i];
updh(a, i-1, size-tp.first);
updh(a, i, tp.second);
long long m = maxh(a, i);
ans = max(ans, m);
size = tp.first;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
416 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
416 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
896 KB |
Output is correct |
28 |
Correct |
5 ms |
896 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
6 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
896 KB |
Output is correct |
32 |
Correct |
7 ms |
896 KB |
Output is correct |
33 |
Correct |
5 ms |
896 KB |
Output is correct |
34 |
Correct |
8 ms |
896 KB |
Output is correct |
35 |
Correct |
6 ms |
896 KB |
Output is correct |
36 |
Correct |
5 ms |
896 KB |
Output is correct |
37 |
Correct |
5 ms |
896 KB |
Output is correct |
38 |
Correct |
5 ms |
896 KB |
Output is correct |
39 |
Correct |
5 ms |
896 KB |
Output is correct |
40 |
Correct |
5 ms |
1024 KB |
Output is correct |
41 |
Correct |
7 ms |
896 KB |
Output is correct |
42 |
Correct |
5 ms |
896 KB |
Output is correct |
43 |
Correct |
5 ms |
896 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
5 ms |
896 KB |
Output is correct |
46 |
Correct |
6 ms |
1024 KB |
Output is correct |
47 |
Correct |
5 ms |
896 KB |
Output is correct |
48 |
Correct |
5 ms |
896 KB |
Output is correct |
49 |
Correct |
6 ms |
896 KB |
Output is correct |
50 |
Correct |
5 ms |
896 KB |
Output is correct |
51 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
416 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
896 KB |
Output is correct |
28 |
Correct |
5 ms |
896 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
6 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
896 KB |
Output is correct |
32 |
Correct |
7 ms |
896 KB |
Output is correct |
33 |
Correct |
5 ms |
896 KB |
Output is correct |
34 |
Correct |
8 ms |
896 KB |
Output is correct |
35 |
Correct |
6 ms |
896 KB |
Output is correct |
36 |
Correct |
5 ms |
896 KB |
Output is correct |
37 |
Correct |
5 ms |
896 KB |
Output is correct |
38 |
Correct |
5 ms |
896 KB |
Output is correct |
39 |
Correct |
5 ms |
896 KB |
Output is correct |
40 |
Correct |
5 ms |
1024 KB |
Output is correct |
41 |
Correct |
7 ms |
896 KB |
Output is correct |
42 |
Correct |
5 ms |
896 KB |
Output is correct |
43 |
Correct |
5 ms |
896 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
5 ms |
896 KB |
Output is correct |
46 |
Correct |
6 ms |
1024 KB |
Output is correct |
47 |
Correct |
5 ms |
896 KB |
Output is correct |
48 |
Correct |
5 ms |
896 KB |
Output is correct |
49 |
Correct |
6 ms |
896 KB |
Output is correct |
50 |
Correct |
5 ms |
896 KB |
Output is correct |
51 |
Correct |
5 ms |
896 KB |
Output is correct |
52 |
Correct |
609 ms |
25044 KB |
Output is correct |
53 |
Correct |
653 ms |
37332 KB |
Output is correct |
54 |
Correct |
620 ms |
37480 KB |
Output is correct |
55 |
Correct |
602 ms |
37588 KB |
Output is correct |
56 |
Correct |
612 ms |
37460 KB |
Output is correct |
57 |
Correct |
599 ms |
37464 KB |
Output is correct |
58 |
Correct |
600 ms |
37332 KB |
Output is correct |
59 |
Correct |
600 ms |
37332 KB |
Output is correct |
60 |
Correct |
598 ms |
37460 KB |
Output is correct |
61 |
Correct |
606 ms |
37332 KB |
Output is correct |
62 |
Correct |
595 ms |
37332 KB |
Output is correct |
63 |
Correct |
606 ms |
37332 KB |
Output is correct |
64 |
Correct |
616 ms |
37460 KB |
Output is correct |
65 |
Correct |
627 ms |
37460 KB |
Output is correct |
66 |
Correct |
605 ms |
37332 KB |
Output is correct |
67 |
Correct |
610 ms |
37452 KB |
Output is correct |
68 |
Correct |
606 ms |
37392 KB |
Output is correct |