#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
constexpr int base = 1<<19;
constexpr int debug = 0;
constexpr ll mini = -1e18-7;
ll tree[2*base+7];
ll tree2[2*base+7];
int p, k;
void push(int v){
tree[2*v] += tree2[v];
tree[2*v+1] += tree2[v];
tree2[2*v] += tree2[v];
tree2[2*v+1] += tree2[v];
tree2[v] = 0;
}
void add(int v, int a, int b, ll val){
if((p > b) || (k < a)){
return;
}
else if((p <= a) && (k >= b)){
tree[v] += val;
tree2[v] += val;
}
else{
int mid = (a+b)/2;
push(v);
add(2*v, a, mid, val); add(2*v+1, mid+1, b, val);
tree[v] = max(tree[2*v], tree[2*v+1]);
}
}
ll query(int v, int a, int b){
ll maksi = mini;
if((p > b) || (k < a)){
return mini;
}
else if((p <= a) && (k >= b)){
return tree[v];
}
else{
int mid = (a+b)/2;
push(v);
maksi = max(query(2*v, a, mid), query(2*v+1, mid+1, b));
tree[v] = max(tree[2*v], tree[2*v+1]);
}
return maksi;
}
vector<pair<ll,ll>> art;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 0; i < n; i++){
pair<ll,ll> a1; cin >> a1.F >> a1.S;
art.pb(a1);
}
sort(art.begin(), art.end());
//fill(tree, tree+2*base+7, mini);
ll best = mini;
for(int i = 0; i < n; i++){
p = 0; k = i;
add(1, 0, base-1, art[i].S);
p = i;
add(1, 0, base-1, art[i].F);
p = 0;
best = max(best, query(1, 0, base-1) - art[i].F);
if(debug){
for(int j = 0; j < n; j++){
p = k = j;
cout << query(1, 0, base-1) << ' ';
}
cout << '\n';
cout << best << '\n';
}
}
cout << best;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6640 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6640 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
6632 KB |
Output is correct |
18 |
Correct |
1 ms |
6684 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6640 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
6632 KB |
Output is correct |
18 |
Correct |
1 ms |
6684 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
5 ms |
9052 KB |
Output is correct |
28 |
Correct |
5 ms |
9076 KB |
Output is correct |
29 |
Correct |
4 ms |
7004 KB |
Output is correct |
30 |
Correct |
5 ms |
9052 KB |
Output is correct |
31 |
Correct |
4 ms |
7008 KB |
Output is correct |
32 |
Correct |
4 ms |
9052 KB |
Output is correct |
33 |
Correct |
5 ms |
7004 KB |
Output is correct |
34 |
Correct |
5 ms |
7004 KB |
Output is correct |
35 |
Correct |
4 ms |
7004 KB |
Output is correct |
36 |
Correct |
5 ms |
9052 KB |
Output is correct |
37 |
Correct |
5 ms |
7004 KB |
Output is correct |
38 |
Correct |
5 ms |
9052 KB |
Output is correct |
39 |
Correct |
5 ms |
7004 KB |
Output is correct |
40 |
Correct |
5 ms |
7000 KB |
Output is correct |
41 |
Correct |
5 ms |
7004 KB |
Output is correct |
42 |
Correct |
5 ms |
7004 KB |
Output is correct |
43 |
Correct |
5 ms |
7004 KB |
Output is correct |
44 |
Correct |
4 ms |
7004 KB |
Output is correct |
45 |
Correct |
5 ms |
9048 KB |
Output is correct |
46 |
Correct |
4 ms |
6952 KB |
Output is correct |
47 |
Correct |
5 ms |
9052 KB |
Output is correct |
48 |
Correct |
5 ms |
9048 KB |
Output is correct |
49 |
Correct |
5 ms |
9052 KB |
Output is correct |
50 |
Correct |
4 ms |
9052 KB |
Output is correct |
51 |
Correct |
4 ms |
6872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6640 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
6632 KB |
Output is correct |
18 |
Correct |
1 ms |
6684 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
5 ms |
9052 KB |
Output is correct |
28 |
Correct |
5 ms |
9076 KB |
Output is correct |
29 |
Correct |
4 ms |
7004 KB |
Output is correct |
30 |
Correct |
5 ms |
9052 KB |
Output is correct |
31 |
Correct |
4 ms |
7008 KB |
Output is correct |
32 |
Correct |
4 ms |
9052 KB |
Output is correct |
33 |
Correct |
5 ms |
7004 KB |
Output is correct |
34 |
Correct |
5 ms |
7004 KB |
Output is correct |
35 |
Correct |
4 ms |
7004 KB |
Output is correct |
36 |
Correct |
5 ms |
9052 KB |
Output is correct |
37 |
Correct |
5 ms |
7004 KB |
Output is correct |
38 |
Correct |
5 ms |
9052 KB |
Output is correct |
39 |
Correct |
5 ms |
7004 KB |
Output is correct |
40 |
Correct |
5 ms |
7000 KB |
Output is correct |
41 |
Correct |
5 ms |
7004 KB |
Output is correct |
42 |
Correct |
5 ms |
7004 KB |
Output is correct |
43 |
Correct |
5 ms |
7004 KB |
Output is correct |
44 |
Correct |
4 ms |
7004 KB |
Output is correct |
45 |
Correct |
5 ms |
9048 KB |
Output is correct |
46 |
Correct |
4 ms |
6952 KB |
Output is correct |
47 |
Correct |
5 ms |
9052 KB |
Output is correct |
48 |
Correct |
5 ms |
9048 KB |
Output is correct |
49 |
Correct |
5 ms |
9052 KB |
Output is correct |
50 |
Correct |
4 ms |
9052 KB |
Output is correct |
51 |
Correct |
4 ms |
6872 KB |
Output is correct |
52 |
Correct |
420 ms |
36468 KB |
Output is correct |
53 |
Correct |
352 ms |
36664 KB |
Output is correct |
54 |
Correct |
371 ms |
36580 KB |
Output is correct |
55 |
Correct |
353 ms |
36524 KB |
Output is correct |
56 |
Correct |
368 ms |
36548 KB |
Output is correct |
57 |
Correct |
356 ms |
36816 KB |
Output is correct |
58 |
Correct |
357 ms |
36528 KB |
Output is correct |
59 |
Correct |
364 ms |
36532 KB |
Output is correct |
60 |
Correct |
364 ms |
36536 KB |
Output is correct |
61 |
Correct |
361 ms |
36444 KB |
Output is correct |
62 |
Correct |
373 ms |
36652 KB |
Output is correct |
63 |
Correct |
365 ms |
36536 KB |
Output is correct |
64 |
Correct |
353 ms |
36536 KB |
Output is correct |
65 |
Correct |
405 ms |
36532 KB |
Output is correct |
66 |
Correct |
355 ms |
36824 KB |
Output is correct |
67 |
Correct |
421 ms |
36804 KB |
Output is correct |
68 |
Correct |
355 ms |
36792 KB |
Output is correct |