# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958836 | 2024-04-07T00:39:53 Z | vjudge1 | Art Exhibition (JOI18_art) | C++17 | 172 ms | 86616 KB |
#include <bits/stdc++.h> #define range(it, a, b) for (ll it = a; it < b; it++) #define all(x) begin(x), end(x) #define ll long long #define ull unsigned long long #define INF64 ((ll) 1 << 62) #define INF32 (1 << 30) #define mset multiset #define uset unordered_set #define umap unordered_map #define pqueue priority_queue #define ptr(A) shared_ptr<A> using namespace std; void setio (string name) { ios_base::sync_with_stdio(0); cin.tie(0); if (name.size()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } struct TPos { ll val, sz; }; struct SegTree { struct Node { Node* left; Node* right; ll l, r, m; ll ans; ll sum; ll pre; ll suf; }; Node* root; vector<TPos>& arr; SegTree (vector<TPos>& a) : arr(a) { root = new Node; root->l = 0; root->r = a.size() - 1; root->m = (a.size()-1)/2; build(root); } void build(Node* node) { if (node->l == node->r) { node->ans = arr[node->l].val; node->sum = node->ans; node->suf = node->sum + arr[node->l].sz; node->pre = node->sum - arr[node->l].sz; return; } node->left = new Node; node->left->l = node->l; node->left->r = node->m; node->left->m = (node->l + node->m)/2; build(node->left); node->right = new Node; node->right->l = node->m+1; node->right->r = node->r; node->right->m = (node->r + node->m+1)/2; build (node->right); node->ans = max({node->left->ans, node->right->ans, node->left->suf + node->right->pre}); node->sum = node->left->sum + node->right->sum; node->pre = max(node->left->pre, node->left->sum + node->right->pre); node->suf = max(node->right->suf, node->right->sum + node->left->suf); } }; ll n; vector<TPos> arr; void solve() { cin >> n; arr.resize(n); range(i, 0, n) cin >> arr[i].sz >> arr[i].val; sort(all(arr), [](const TPos& a, const TPos& b) { return a.sz < b.sz; }); SegTree st(arr); cout << st.root->ans; } int main () { setio(""); ll t = 1; // cin >> t; while (t--) solve(); } // IT'S TOUGH, I KNOW // BUT YOU'D RATHER DIE FIGHTING THAN LIVE ON YOUR KNEES // THOUG H YOU WON'T DO NEITHER OF THOSE // IMPOSSIBLE, AS IT'S AGAINST YOUR NATURE // AS YOU ALREADY WON // I SEE YOUR MEDAL HANGING FROM YOUR NECK // SHINING AS NOTHING YOU'VE EVER HAD // THOUSANDS AND THOUSANDS OF LINES // YOU AREADY MADE IT THIS FAR // AND WHO COULD TELL HOW FAR YOU WILL GET... // BUT YOU? // THEN COME ON, YOU BASTARD! // GO CLEAR YOUR MIND AND STAND // AS EACH OF THOSE LINES IS A STEP CLOSER // CLOSER TO THE GREATNESS YOU PURSUE // CLOSER TO THE GREATNESS YOU ALREADY HAVE
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 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 | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 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 | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 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 | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 348 KB | Output is correct |
23 | Correct | 0 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 | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 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 | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 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 | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 348 KB | Output is correct |
23 | Correct | 0 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 | 0 ms | 348 KB | Output is correct |
27 | Correct | 2 ms | 1112 KB | Output is correct |
28 | Correct | 3 ms | 1116 KB | Output is correct |
29 | Correct | 2 ms | 1116 KB | Output is correct |
30 | Correct | 2 ms | 1116 KB | Output is correct |
31 | Correct | 2 ms | 1116 KB | Output is correct |
32 | Correct | 2 ms | 1116 KB | Output is correct |
33 | Correct | 2 ms | 1116 KB | Output is correct |
34 | Correct | 2 ms | 1116 KB | Output is correct |
35 | Correct | 2 ms | 1116 KB | Output is correct |
36 | Correct | 2 ms | 1116 KB | Output is correct |
37 | Correct | 2 ms | 1116 KB | Output is correct |
38 | Correct | 2 ms | 1116 KB | Output is correct |
39 | Correct | 2 ms | 1116 KB | Output is correct |
40 | Correct | 2 ms | 1116 KB | Output is correct |
41 | Correct | 2 ms | 1116 KB | Output is correct |
42 | Correct | 2 ms | 1116 KB | Output is correct |
43 | Correct | 3 ms | 1116 KB | Output is correct |
44 | Correct | 3 ms | 1116 KB | Output is correct |
45 | Correct | 3 ms | 1116 KB | Output is correct |
46 | Correct | 2 ms | 1116 KB | Output is correct |
47 | Correct | 2 ms | 1116 KB | Output is correct |
48 | Correct | 2 ms | 1112 KB | Output is correct |
49 | Correct | 2 ms | 1116 KB | Output is correct |
50 | Correct | 2 ms | 1116 KB | Output is correct |
51 | Correct | 2 ms | 1316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 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 | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 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 | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 348 KB | Output is correct |
23 | Correct | 0 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 | 0 ms | 348 KB | Output is correct |
27 | Correct | 2 ms | 1112 KB | Output is correct |
28 | Correct | 3 ms | 1116 KB | Output is correct |
29 | Correct | 2 ms | 1116 KB | Output is correct |
30 | Correct | 2 ms | 1116 KB | Output is correct |
31 | Correct | 2 ms | 1116 KB | Output is correct |
32 | Correct | 2 ms | 1116 KB | Output is correct |
33 | Correct | 2 ms | 1116 KB | Output is correct |
34 | Correct | 2 ms | 1116 KB | Output is correct |
35 | Correct | 2 ms | 1116 KB | Output is correct |
36 | Correct | 2 ms | 1116 KB | Output is correct |
37 | Correct | 2 ms | 1116 KB | Output is correct |
38 | Correct | 2 ms | 1116 KB | Output is correct |
39 | Correct | 2 ms | 1116 KB | Output is correct |
40 | Correct | 2 ms | 1116 KB | Output is correct |
41 | Correct | 2 ms | 1116 KB | Output is correct |
42 | Correct | 2 ms | 1116 KB | Output is correct |
43 | Correct | 3 ms | 1116 KB | Output is correct |
44 | Correct | 3 ms | 1116 KB | Output is correct |
45 | Correct | 3 ms | 1116 KB | Output is correct |
46 | Correct | 2 ms | 1116 KB | Output is correct |
47 | Correct | 2 ms | 1116 KB | Output is correct |
48 | Correct | 2 ms | 1112 KB | Output is correct |
49 | Correct | 2 ms | 1116 KB | Output is correct |
50 | Correct | 2 ms | 1116 KB | Output is correct |
51 | Correct | 2 ms | 1316 KB | Output is correct |
52 | Correct | 164 ms | 86348 KB | Output is correct |
53 | Correct | 169 ms | 86376 KB | Output is correct |
54 | Correct | 163 ms | 86352 KB | Output is correct |
55 | Correct | 164 ms | 86356 KB | Output is correct |
56 | Correct | 163 ms | 86372 KB | Output is correct |
57 | Correct | 163 ms | 86400 KB | Output is correct |
58 | Correct | 163 ms | 86356 KB | Output is correct |
59 | Correct | 162 ms | 86376 KB | Output is correct |
60 | Correct | 163 ms | 86352 KB | Output is correct |
61 | Correct | 172 ms | 86356 KB | Output is correct |
62 | Correct | 164 ms | 86352 KB | Output is correct |
63 | Correct | 162 ms | 86352 KB | Output is correct |
64 | Correct | 164 ms | 86380 KB | Output is correct |
65 | Correct | 164 ms | 86356 KB | Output is correct |
66 | Correct | 167 ms | 86616 KB | Output is correct |
67 | Correct | 167 ms | 86352 KB | Output is correct |
68 | Correct | 168 ms | 86352 KB | Output is correct |