# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
896636 |
2024-01-01T19:52:25 Z |
aqxa |
Art Exhibition (JOI18_art) |
C++17 |
|
521 ms |
34132 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct segtree {
vector<ll> tree, lazy;
int n;
segtree(int _n) : n(_n) {
tree = vector<ll>(2 * n, 0);
lazy = vector<ll>(2 * n, 0);
}
void push(int x, int l, int r) {
tree[x] += lazy[x];
if (l != r) {
int mid = (r + l) / 2;
int z = x + 2 * (mid - l + 1);
lazy[x + 1] += lazy[x];
lazy[z] += lazy[x];
}
lazy[x] = 0;
}
void pull(int x, int L, int R) {
int mid = (L + R) / 2;
int z = x + 2 * (mid - L + 1);
tree[x] = max(tree[x + 1], tree[z]);
}
void upd(int l, int r, ll v, int L, int R, int x) {
push(x, L, R);
if (r < L || R < l) return;
if (l <= L && R <= r) {
lazy[x] = v;
push(x, L, R);
return;
}
int mid = (L + R) / 2;
int z = x + 2 * (mid - L + 1);
upd(l, r, v, L, mid, x + 1);
upd(l, r, v, mid + 1, R, z);
pull(x, L, R);
}
void upd(int l, int r, ll v) { upd(l, r, v, 0, n - 1, 0); }
ll get(int l, int r, int L, int R, int x) {
push(x, L, R);
if (r < L || R < l) return -9e18;
if (l <= L && R <= r) return tree[x];
int mid = (L + R) / 2;
int z = x + 2 * (mid - L + 1);
return max(get(l, r, L, mid, x + 1), get(l, r, mid + 1, R, z));
}
ll get(int l, int r) { return get(l, r, 0, n - 1, 0); }
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<ll, ll>> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end());
segtree st(n);
ll S = 0;
for (int i = 0; i < n; ++i) {
S += a[i].second;
st.upd(i, i, S - (a[i].first - a[0].first));
}
ll ans = st.get(0, n - 1);
for (int i = 0; i < n - 1; ++i) {
st.upd(i + 1, n - 1, a[i + 1].first - a[i].first - a[i].second);
ans = max(ans, st.get(i + 1, n - 1));
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
456 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
456 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
724 KB |
Output is correct |
29 |
Correct |
4 ms |
604 KB |
Output is correct |
30 |
Correct |
4 ms |
604 KB |
Output is correct |
31 |
Correct |
4 ms |
648 KB |
Output is correct |
32 |
Correct |
4 ms |
716 KB |
Output is correct |
33 |
Correct |
4 ms |
720 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
4 ms |
604 KB |
Output is correct |
36 |
Correct |
4 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
604 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
664 KB |
Output is correct |
41 |
Correct |
4 ms |
600 KB |
Output is correct |
42 |
Correct |
4 ms |
604 KB |
Output is correct |
43 |
Correct |
4 ms |
640 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
4 ms |
724 KB |
Output is correct |
46 |
Correct |
4 ms |
604 KB |
Output is correct |
47 |
Correct |
4 ms |
604 KB |
Output is correct |
48 |
Correct |
4 ms |
604 KB |
Output is correct |
49 |
Correct |
4 ms |
600 KB |
Output is correct |
50 |
Correct |
4 ms |
604 KB |
Output is correct |
51 |
Correct |
4 ms |
660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
456 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
4 ms |
724 KB |
Output is correct |
29 |
Correct |
4 ms |
604 KB |
Output is correct |
30 |
Correct |
4 ms |
604 KB |
Output is correct |
31 |
Correct |
4 ms |
648 KB |
Output is correct |
32 |
Correct |
4 ms |
716 KB |
Output is correct |
33 |
Correct |
4 ms |
720 KB |
Output is correct |
34 |
Correct |
4 ms |
604 KB |
Output is correct |
35 |
Correct |
4 ms |
604 KB |
Output is correct |
36 |
Correct |
4 ms |
604 KB |
Output is correct |
37 |
Correct |
4 ms |
604 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
664 KB |
Output is correct |
41 |
Correct |
4 ms |
600 KB |
Output is correct |
42 |
Correct |
4 ms |
604 KB |
Output is correct |
43 |
Correct |
4 ms |
640 KB |
Output is correct |
44 |
Correct |
4 ms |
604 KB |
Output is correct |
45 |
Correct |
4 ms |
724 KB |
Output is correct |
46 |
Correct |
4 ms |
604 KB |
Output is correct |
47 |
Correct |
4 ms |
604 KB |
Output is correct |
48 |
Correct |
4 ms |
604 KB |
Output is correct |
49 |
Correct |
4 ms |
600 KB |
Output is correct |
50 |
Correct |
4 ms |
604 KB |
Output is correct |
51 |
Correct |
4 ms |
660 KB |
Output is correct |
52 |
Correct |
472 ms |
33856 KB |
Output is correct |
53 |
Correct |
472 ms |
33920 KB |
Output is correct |
54 |
Correct |
480 ms |
33920 KB |
Output is correct |
55 |
Correct |
521 ms |
33876 KB |
Output is correct |
56 |
Correct |
470 ms |
33872 KB |
Output is correct |
57 |
Correct |
472 ms |
33920 KB |
Output is correct |
58 |
Correct |
467 ms |
33876 KB |
Output is correct |
59 |
Correct |
478 ms |
34076 KB |
Output is correct |
60 |
Correct |
476 ms |
34128 KB |
Output is correct |
61 |
Correct |
504 ms |
33636 KB |
Output is correct |
62 |
Correct |
482 ms |
33956 KB |
Output is correct |
63 |
Correct |
479 ms |
33920 KB |
Output is correct |
64 |
Correct |
478 ms |
33876 KB |
Output is correct |
65 |
Correct |
477 ms |
33964 KB |
Output is correct |
66 |
Correct |
485 ms |
34132 KB |
Output is correct |
67 |
Correct |
493 ms |
33920 KB |
Output is correct |
68 |
Correct |
483 ms |
33924 KB |
Output is correct |