#include <bits/stdc++.h>
using namespace std;
# define int long long
# define fir first
# define sec second
# define pb push_back
const int cnst = 5e5+5;
bool mutipletestcase = 0;
//bool debug = false;
int arr[cnst];
int posi[cnst*4];
int merge(int a, int b) {
return max(a, b);
}
void build(int a, int b, int id) {
if(a == b) {posi[id] = arr[a]; return;}
int mid = (a+b)/2;
build(a, mid, id*2);
build(mid+1, b, id*2+1);
posi[id] = merge(posi[id*2], posi[id*2+1]);
}
void update(int a, int b, int id, int pos, int val) {
if(a == pos && b == pos) {
posi[id] = val;
return;
}
int mid =(a+b)/2;
if(pos <= mid) update(a, mid, id*2, pos, val);
else update(mid+1, b, id*2+1, pos, val);
posi[id] = merge(posi[id*2], posi[id*2+1]);
}
int get(int a, int b, int id, int from, int to) {
if(to < a || from > b) return LLONG_MIN;
if(from <= a && b <= to) return posi[id];
int mid = (a+b)/2;
return merge(get(a, mid, id*2, from, to), get(mid+1, b, id*2+1, from, to));
}
void solve() {
int n; cin >> n;
pair<int, int> paint[n+5];
for(int i = 1; i<=4*n; i++) posi[i] = LLONG_MIN;
for(int i = 1; i<=n; i++) cin >> paint[i].fir >> paint[i].sec;
int presum[n+5]; presum[0] = 0;
sort(paint+1, paint+n+1);
for(int i = 1; i<=n; i++) {
presum[i] = presum[i-1]+paint[i].sec;
// cerr << presum[i] << " " << paint[i].fir << endl;
update(1, n, 1, i, presum[i]-paint[i].fir);
}
// for(int i = 1; i<=n; i++) cerr << presum[i] << " ";
// cerr << endl;
// for(int i = 1; i<=n; i++) cerr << get(1, n, 1, i, i) << " ";
// cerr << endl;
int ans = 0;
for(int i = 1; i<=n; i++) {
int temp = paint[i].fir-presum[i-1];
// cerr << paint[i].fir << " " << presum[i-1] << " " << get(1, n, 1, i, n) << endl;
temp += get(1, n, 1, i, n);
// cerr << i << " " << temp << endl;
ans = max(ans, temp);
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
int t = 1;
if(mutipletestcase) cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
264 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
264 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 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 |
3 ms |
724 KB |
Output is correct |
28 |
Correct |
4 ms |
684 KB |
Output is correct |
29 |
Correct |
3 ms |
728 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
684 KB |
Output is correct |
32 |
Correct |
3 ms |
720 KB |
Output is correct |
33 |
Correct |
3 ms |
724 KB |
Output is correct |
34 |
Correct |
3 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
720 KB |
Output is correct |
36 |
Correct |
3 ms |
724 KB |
Output is correct |
37 |
Correct |
3 ms |
728 KB |
Output is correct |
38 |
Correct |
3 ms |
724 KB |
Output is correct |
39 |
Correct |
3 ms |
720 KB |
Output is correct |
40 |
Correct |
4 ms |
724 KB |
Output is correct |
41 |
Correct |
3 ms |
724 KB |
Output is correct |
42 |
Correct |
4 ms |
724 KB |
Output is correct |
43 |
Correct |
4 ms |
600 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
3 ms |
724 KB |
Output is correct |
46 |
Correct |
3 ms |
596 KB |
Output is correct |
47 |
Correct |
3 ms |
724 KB |
Output is correct |
48 |
Correct |
3 ms |
724 KB |
Output is correct |
49 |
Correct |
3 ms |
688 KB |
Output is correct |
50 |
Correct |
3 ms |
720 KB |
Output is correct |
51 |
Correct |
3 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
264 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 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 |
3 ms |
724 KB |
Output is correct |
28 |
Correct |
4 ms |
684 KB |
Output is correct |
29 |
Correct |
3 ms |
728 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
684 KB |
Output is correct |
32 |
Correct |
3 ms |
720 KB |
Output is correct |
33 |
Correct |
3 ms |
724 KB |
Output is correct |
34 |
Correct |
3 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
720 KB |
Output is correct |
36 |
Correct |
3 ms |
724 KB |
Output is correct |
37 |
Correct |
3 ms |
728 KB |
Output is correct |
38 |
Correct |
3 ms |
724 KB |
Output is correct |
39 |
Correct |
3 ms |
720 KB |
Output is correct |
40 |
Correct |
4 ms |
724 KB |
Output is correct |
41 |
Correct |
3 ms |
724 KB |
Output is correct |
42 |
Correct |
4 ms |
724 KB |
Output is correct |
43 |
Correct |
4 ms |
600 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
3 ms |
724 KB |
Output is correct |
46 |
Correct |
3 ms |
596 KB |
Output is correct |
47 |
Correct |
3 ms |
724 KB |
Output is correct |
48 |
Correct |
3 ms |
724 KB |
Output is correct |
49 |
Correct |
3 ms |
688 KB |
Output is correct |
50 |
Correct |
3 ms |
720 KB |
Output is correct |
51 |
Correct |
3 ms |
688 KB |
Output is correct |
52 |
Correct |
281 ms |
40292 KB |
Output is correct |
53 |
Correct |
250 ms |
40340 KB |
Output is correct |
54 |
Correct |
248 ms |
40300 KB |
Output is correct |
55 |
Correct |
248 ms |
40344 KB |
Output is correct |
56 |
Correct |
252 ms |
40280 KB |
Output is correct |
57 |
Correct |
253 ms |
40352 KB |
Output is correct |
58 |
Correct |
256 ms |
40288 KB |
Output is correct |
59 |
Correct |
252 ms |
40268 KB |
Output is correct |
60 |
Correct |
245 ms |
40348 KB |
Output is correct |
61 |
Correct |
274 ms |
40128 KB |
Output is correct |
62 |
Correct |
261 ms |
40276 KB |
Output is correct |
63 |
Correct |
262 ms |
40352 KB |
Output is correct |
64 |
Correct |
269 ms |
40268 KB |
Output is correct |
65 |
Correct |
258 ms |
40520 KB |
Output is correct |
66 |
Correct |
262 ms |
40344 KB |
Output is correct |
67 |
Correct |
259 ms |
40352 KB |
Output is correct |
68 |
Correct |
252 ms |
40284 KB |
Output is correct |