Submission #49142

# Submission time Handle Problem Language Result Execution time Memory
49142 2018-05-22T19:04:15 Z WLZ Art Exhibition (JOI18_art) C++17
100 / 100
437 ms 235212 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

int n;

vector<pair<ll, int>> v;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll a; int b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    vector<ll> pre(n);
    vector<ll> precomp(n);
    for (int i = 0; i < n; i++) {
        pre[i] = v[i].second;
        if (i) pre[i] += pre[i - 1];
        precomp[i] = v[i].first;
        if (i) {
            precomp[i] -= pre[i - 1];
            precomp[i] = max(precomp[i], precomp[i - 1]);
        }
    }
    ll ans = -INF;
    for (int i = 0; i < n; i++) {
        ans = max(ans, pre[i] - v[i].first + precomp[i]);
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 3 ms 688 KB Output is correct
14 Correct 3 ms 776 KB Output is correct
15 Correct 3 ms 776 KB Output is correct
16 Correct 2 ms 776 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 2 ms 824 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 932 KB Output is correct
24 Correct 2 ms 940 KB Output is correct
25 Correct 2 ms 948 KB Output is correct
26 Correct 2 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 3 ms 688 KB Output is correct
14 Correct 3 ms 776 KB Output is correct
15 Correct 3 ms 776 KB Output is correct
16 Correct 2 ms 776 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 2 ms 824 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 932 KB Output is correct
24 Correct 2 ms 940 KB Output is correct
25 Correct 2 ms 948 KB Output is correct
26 Correct 2 ms 956 KB Output is correct
27 Correct 7 ms 1220 KB Output is correct
28 Correct 7 ms 1348 KB Output is correct
29 Correct 5 ms 1476 KB Output is correct
30 Correct 5 ms 1604 KB Output is correct
31 Correct 8 ms 1768 KB Output is correct
32 Correct 5 ms 1860 KB Output is correct
33 Correct 6 ms 1988 KB Output is correct
34 Correct 5 ms 2116 KB Output is correct
35 Correct 5 ms 2244 KB Output is correct
36 Correct 4 ms 2408 KB Output is correct
37 Correct 5 ms 2564 KB Output is correct
38 Correct 6 ms 2628 KB Output is correct
39 Correct 4 ms 2756 KB Output is correct
40 Correct 5 ms 2884 KB Output is correct
41 Correct 5 ms 3016 KB Output is correct
42 Correct 5 ms 3136 KB Output is correct
43 Correct 5 ms 3264 KB Output is correct
44 Correct 4 ms 3416 KB Output is correct
45 Correct 4 ms 3700 KB Output is correct
46 Correct 5 ms 3808 KB Output is correct
47 Correct 5 ms 3812 KB Output is correct
48 Correct 5 ms 3940 KB Output is correct
49 Correct 4 ms 4100 KB Output is correct
50 Correct 5 ms 4256 KB Output is correct
51 Correct 5 ms 4424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 688 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 3 ms 688 KB Output is correct
14 Correct 3 ms 776 KB Output is correct
15 Correct 3 ms 776 KB Output is correct
16 Correct 2 ms 776 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 2 ms 824 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 2 ms 932 KB Output is correct
24 Correct 2 ms 940 KB Output is correct
25 Correct 2 ms 948 KB Output is correct
26 Correct 2 ms 956 KB Output is correct
27 Correct 7 ms 1220 KB Output is correct
28 Correct 7 ms 1348 KB Output is correct
29 Correct 5 ms 1476 KB Output is correct
30 Correct 5 ms 1604 KB Output is correct
31 Correct 8 ms 1768 KB Output is correct
32 Correct 5 ms 1860 KB Output is correct
33 Correct 6 ms 1988 KB Output is correct
34 Correct 5 ms 2116 KB Output is correct
35 Correct 5 ms 2244 KB Output is correct
36 Correct 4 ms 2408 KB Output is correct
37 Correct 5 ms 2564 KB Output is correct
38 Correct 6 ms 2628 KB Output is correct
39 Correct 4 ms 2756 KB Output is correct
40 Correct 5 ms 2884 KB Output is correct
41 Correct 5 ms 3016 KB Output is correct
42 Correct 5 ms 3136 KB Output is correct
43 Correct 5 ms 3264 KB Output is correct
44 Correct 4 ms 3416 KB Output is correct
45 Correct 4 ms 3700 KB Output is correct
46 Correct 5 ms 3808 KB Output is correct
47 Correct 5 ms 3812 KB Output is correct
48 Correct 5 ms 3940 KB Output is correct
49 Correct 4 ms 4100 KB Output is correct
50 Correct 5 ms 4256 KB Output is correct
51 Correct 5 ms 4424 KB Output is correct
52 Correct 267 ms 32448 KB Output is correct
53 Correct 437 ms 45076 KB Output is correct
54 Correct 239 ms 57728 KB Output is correct
55 Correct 272 ms 70532 KB Output is correct
56 Correct 313 ms 83184 KB Output is correct
57 Correct 289 ms 95920 KB Output is correct
58 Correct 287 ms 108472 KB Output is correct
59 Correct 318 ms 121092 KB Output is correct
60 Correct 286 ms 133880 KB Output is correct
61 Correct 269 ms 146404 KB Output is correct
62 Correct 411 ms 159004 KB Output is correct
63 Correct 243 ms 171972 KB Output is correct
64 Correct 308 ms 184368 KB Output is correct
65 Correct 297 ms 197108 KB Output is correct
66 Correct 276 ms 209776 KB Output is correct
67 Correct 290 ms 222392 KB Output is correct
68 Correct 263 ms 235212 KB Output is correct