#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5 + 5;
int N;
ll A[MAXN], V[MAXN], S[MAXN], ans;
pll in[MAXN];
void f(int s, int e, int l, int r) {
if(r < l) return;
int mid = l + r >> 1;
int k = -1;
ll val = 0;
for(int i=max(s, mid); i<=e; i++) {
if(val < S[i] - S[mid-1] - A[i] + A[mid]) {
val = S[i] - S[mid-1] - A[i] + A[mid];
k = i;
}
}
ans = max(ans, val);
f(s, k, l, mid-1); f(k, e, mid+1, r);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N;
for(int i=1; i<=N; i++) cin >> in[i].fi >> in[i].se;
sort(in+1, in+1+N);
for(int i=1; i<=N; i++) A[i] = in[i].fi, V[i] = in[i].se, S[i] = S[i-1] + V[i];
f(1, N, 1, N);
cout << ans;
}
Compilation message
art.cpp: In function 'void f(int, int, int, int)':
art.cpp:19:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
0 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
0 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
404 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
0 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
404 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
5 ms |
760 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
5 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
636 KB |
Output is correct |
36 |
Correct |
5 ms |
760 KB |
Output is correct |
37 |
Correct |
4 ms |
732 KB |
Output is correct |
38 |
Correct |
3 ms |
760 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
760 KB |
Output is correct |
41 |
Correct |
5 ms |
760 KB |
Output is correct |
42 |
Correct |
5 ms |
632 KB |
Output is correct |
43 |
Correct |
5 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
632 KB |
Output is correct |
45 |
Correct |
6 ms |
672 KB |
Output is correct |
46 |
Correct |
5 ms |
632 KB |
Output is correct |
47 |
Correct |
6 ms |
760 KB |
Output is correct |
48 |
Correct |
6 ms |
760 KB |
Output is correct |
49 |
Correct |
5 ms |
632 KB |
Output is correct |
50 |
Correct |
5 ms |
760 KB |
Output is correct |
51 |
Correct |
6 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
0 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
404 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
5 ms |
632 KB |
Output is correct |
31 |
Correct |
5 ms |
760 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
33 |
Correct |
5 ms |
632 KB |
Output is correct |
34 |
Correct |
5 ms |
760 KB |
Output is correct |
35 |
Correct |
5 ms |
636 KB |
Output is correct |
36 |
Correct |
5 ms |
760 KB |
Output is correct |
37 |
Correct |
4 ms |
732 KB |
Output is correct |
38 |
Correct |
3 ms |
760 KB |
Output is correct |
39 |
Correct |
5 ms |
760 KB |
Output is correct |
40 |
Correct |
5 ms |
760 KB |
Output is correct |
41 |
Correct |
5 ms |
760 KB |
Output is correct |
42 |
Correct |
5 ms |
632 KB |
Output is correct |
43 |
Correct |
5 ms |
632 KB |
Output is correct |
44 |
Correct |
5 ms |
632 KB |
Output is correct |
45 |
Correct |
6 ms |
672 KB |
Output is correct |
46 |
Correct |
5 ms |
632 KB |
Output is correct |
47 |
Correct |
6 ms |
760 KB |
Output is correct |
48 |
Correct |
6 ms |
760 KB |
Output is correct |
49 |
Correct |
5 ms |
632 KB |
Output is correct |
50 |
Correct |
5 ms |
760 KB |
Output is correct |
51 |
Correct |
6 ms |
760 KB |
Output is correct |
52 |
Correct |
263 ms |
24708 KB |
Output is correct |
53 |
Correct |
271 ms |
24464 KB |
Output is correct |
54 |
Correct |
269 ms |
24440 KB |
Output is correct |
55 |
Correct |
268 ms |
24572 KB |
Output is correct |
56 |
Correct |
277 ms |
24444 KB |
Output is correct |
57 |
Correct |
267 ms |
24444 KB |
Output is correct |
58 |
Correct |
287 ms |
24524 KB |
Output is correct |
59 |
Correct |
275 ms |
24528 KB |
Output is correct |
60 |
Correct |
278 ms |
24500 KB |
Output is correct |
61 |
Correct |
272 ms |
24464 KB |
Output is correct |
62 |
Correct |
272 ms |
24420 KB |
Output is correct |
63 |
Correct |
282 ms |
24396 KB |
Output is correct |
64 |
Correct |
297 ms |
24432 KB |
Output is correct |
65 |
Correct |
298 ms |
24440 KB |
Output is correct |
66 |
Correct |
289 ms |
24440 KB |
Output is correct |
67 |
Correct |
268 ms |
24440 KB |
Output is correct |
68 |
Correct |
268 ms |
24440 KB |
Output is correct |