#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
using namespace std;
template<typename T> void uin(T &a, T b) {
if (b < a) {
a = b;
}
}
template<typename T> void uax(T &a, T b) {
if (b > a) {
a = b;
}
}
#define int long long
#define left left228
#define right right228
#define prev prev228
#define list list228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second
const int N = 500 * 1000 + 228;
int a[N], b[N];
int X;
vector< pair<int, int> > crd;
struct node
{
int mx, mod;
int l, r;
node() {
mx = mod = l = r = 0;
}
};
vector< node > d;
void build(int l, int r, int v = 1) {
d[v].l = l, d[v].r = r;
if (l == r) {
d[v].mx = crd.back().first - crd[l - 1].first;
} else {
int m = (l + r) >> 1;
build(l, m, v << 1); build(m + 1, r, v << 1 | 1);
d[v].mx = max(d[v << 1].mx, d[v << 1 | 1].mx);
}
}
int gets(int v) {
return d[v].mx + d[v].mod;
}
void push(int v) {
d[v << 1].mod += d[v].mod;
d[v << 1 | 1].mod += d[v].mod;
d[v].mod = 0;
d[v].mx = max(gets(v << 1), gets(v << 1 | 1));
}
void update(int l, int r, int x, int v = 1) {
if (l > r || d[v].l > r || d[v].r < l) return;
if (l <= d[v].l && d[v].r <= r) {
d[v].mod += x;
} else {
push(v);
update(l, r, x, v << 1); update(l, r, x, v << 1 | 1);
d[v].mx = max(gets(v << 1), gets(v << 1 | 1));
}
}
int get(int l, int r, int v = 1) {
if (l > r || d[v].l > r || d[v].r < l) return 0;
if (l <= d[v].l && d[v].r <= r) return gets(v);
push(v);
return max(get(l, r, v << 1), get(l, r, v << 1 | 1));
}
void init(int n) {
int ss = 1;
while (ss < n) ss <<= 1;
ss <<= 1;
d.resize(ss + 3, node());
build(1, n);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
crd.push_back({a[i], b[i]});
}
sort(crd.begin(), crd.end());
init(n);
int res = 0;
int pv = crd.back().first;
int delta = 0;
for (int i = n; i; --i) {
delta += crd[i - 1].first - pv;
pv = crd[i - 1].first;
update(i, n, crd[i - 1].second);
uax(res, delta + get(i, n));
}
cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
8 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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
8 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 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 |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
8 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 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 |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
7 ms |
1272 KB |
Output is correct |
28 |
Correct |
7 ms |
1148 KB |
Output is correct |
29 |
Correct |
7 ms |
1144 KB |
Output is correct |
30 |
Correct |
7 ms |
1144 KB |
Output is correct |
31 |
Correct |
7 ms |
1144 KB |
Output is correct |
32 |
Correct |
9 ms |
1144 KB |
Output is correct |
33 |
Correct |
7 ms |
1144 KB |
Output is correct |
34 |
Correct |
7 ms |
1144 KB |
Output is correct |
35 |
Correct |
9 ms |
1144 KB |
Output is correct |
36 |
Correct |
7 ms |
1144 KB |
Output is correct |
37 |
Correct |
7 ms |
1144 KB |
Output is correct |
38 |
Correct |
7 ms |
1144 KB |
Output is correct |
39 |
Correct |
7 ms |
1144 KB |
Output is correct |
40 |
Correct |
8 ms |
1144 KB |
Output is correct |
41 |
Correct |
7 ms |
1144 KB |
Output is correct |
42 |
Correct |
7 ms |
1148 KB |
Output is correct |
43 |
Correct |
7 ms |
1144 KB |
Output is correct |
44 |
Correct |
7 ms |
1144 KB |
Output is correct |
45 |
Correct |
7 ms |
1144 KB |
Output is correct |
46 |
Correct |
7 ms |
1116 KB |
Output is correct |
47 |
Correct |
7 ms |
1144 KB |
Output is correct |
48 |
Correct |
9 ms |
1144 KB |
Output is correct |
49 |
Correct |
7 ms |
1144 KB |
Output is correct |
50 |
Correct |
7 ms |
1144 KB |
Output is correct |
51 |
Correct |
7 ms |
1144 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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
8 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 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 |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
7 ms |
1272 KB |
Output is correct |
28 |
Correct |
7 ms |
1148 KB |
Output is correct |
29 |
Correct |
7 ms |
1144 KB |
Output is correct |
30 |
Correct |
7 ms |
1144 KB |
Output is correct |
31 |
Correct |
7 ms |
1144 KB |
Output is correct |
32 |
Correct |
9 ms |
1144 KB |
Output is correct |
33 |
Correct |
7 ms |
1144 KB |
Output is correct |
34 |
Correct |
7 ms |
1144 KB |
Output is correct |
35 |
Correct |
9 ms |
1144 KB |
Output is correct |
36 |
Correct |
7 ms |
1144 KB |
Output is correct |
37 |
Correct |
7 ms |
1144 KB |
Output is correct |
38 |
Correct |
7 ms |
1144 KB |
Output is correct |
39 |
Correct |
7 ms |
1144 KB |
Output is correct |
40 |
Correct |
8 ms |
1144 KB |
Output is correct |
41 |
Correct |
7 ms |
1144 KB |
Output is correct |
42 |
Correct |
7 ms |
1148 KB |
Output is correct |
43 |
Correct |
7 ms |
1144 KB |
Output is correct |
44 |
Correct |
7 ms |
1144 KB |
Output is correct |
45 |
Correct |
7 ms |
1144 KB |
Output is correct |
46 |
Correct |
7 ms |
1116 KB |
Output is correct |
47 |
Correct |
7 ms |
1144 KB |
Output is correct |
48 |
Correct |
9 ms |
1144 KB |
Output is correct |
49 |
Correct |
7 ms |
1144 KB |
Output is correct |
50 |
Correct |
7 ms |
1144 KB |
Output is correct |
51 |
Correct |
7 ms |
1144 KB |
Output is correct |
52 |
Correct |
608 ms |
49076 KB |
Output is correct |
53 |
Correct |
606 ms |
48956 KB |
Output is correct |
54 |
Correct |
616 ms |
61780 KB |
Output is correct |
55 |
Correct |
623 ms |
61652 KB |
Output is correct |
56 |
Correct |
607 ms |
61652 KB |
Output is correct |
57 |
Correct |
653 ms |
61664 KB |
Output is correct |
58 |
Correct |
602 ms |
61784 KB |
Output is correct |
59 |
Correct |
815 ms |
61780 KB |
Output is correct |
60 |
Correct |
655 ms |
61896 KB |
Output is correct |
61 |
Correct |
739 ms |
61552 KB |
Output is correct |
62 |
Correct |
600 ms |
61784 KB |
Output is correct |
63 |
Correct |
612 ms |
61792 KB |
Output is correct |
64 |
Correct |
596 ms |
61780 KB |
Output is correct |
65 |
Correct |
595 ms |
61780 KB |
Output is correct |
66 |
Correct |
595 ms |
61652 KB |
Output is correct |
67 |
Correct |
594 ms |
61772 KB |
Output is correct |
68 |
Correct |
605 ms |
61752 KB |
Output is correct |