# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
305254 | 2020-09-22T19:45:48 Z | luciocf | Feast (NOI19_feast) | C++14 | 175 ms | 8824 KB |
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 5e5+10; const ll inf = 6e14+10; int n; int a[maxn]; ll pref[maxn]; ll dp[maxn]; pii range[maxn]; void get(ll c) { ll mx = 0; int mx_l = 0, mx_r = 0; for (int i = 1; i <= n; i++) { ll v = pref[i] + mx - c; dp[i] = dp[i-1], range[i] = range[i-1]; if (v > dp[i]) { dp[i] = v; range[i] = {mx_l+1, mx_r+1}; } else if (v == dp[i]) { range[i].ff = min(range[i].ff, mx_l+1); range[i].ss = max(range[i].ss, mx_r+1); } v = dp[i] - pref[i]; if (v > mx) { mx = v; mx_l = range[i].ff, mx_r = range[i].ss; } else { mx_l = min(mx_l, range[i].ff); mx_r = max(mx_r, range[i].ss); } } } int main(void) { int k; scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); pref[i] = pref[i-1]+1ll*a[i]; } ll ini = 0, fim = inf, best = inf; while (ini <= fim) { ll mid = (ini+fim)/2ll; get(mid); if (range[n].ff > k) ini = mid+1; else best = mid, fim = mid-1; } get(best); int qtd = min(k, range[n].ss); printf("%lld\n", dp[n] + 1ll*qtd*best); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 119 ms | 8316 KB | Output is correct |
2 | Correct | 123 ms | 8568 KB | Output is correct |
3 | Correct | 124 ms | 8696 KB | Output is correct |
4 | Correct | 124 ms | 8668 KB | Output is correct |
5 | Correct | 121 ms | 8568 KB | Output is correct |
6 | Correct | 120 ms | 8440 KB | Output is correct |
7 | Correct | 119 ms | 8364 KB | Output is correct |
8 | Correct | 122 ms | 8652 KB | Output is correct |
9 | Correct | 120 ms | 8440 KB | Output is correct |
10 | Correct | 124 ms | 8592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 8440 KB | Output is correct |
2 | Correct | 90 ms | 8696 KB | Output is correct |
3 | Correct | 92 ms | 8696 KB | Output is correct |
4 | Correct | 93 ms | 8568 KB | Output is correct |
5 | Correct | 121 ms | 8440 KB | Output is correct |
6 | Correct | 94 ms | 8440 KB | Output is correct |
7 | Correct | 99 ms | 8696 KB | Output is correct |
8 | Correct | 124 ms | 8568 KB | Output is correct |
9 | Correct | 120 ms | 8440 KB | Output is correct |
10 | Correct | 98 ms | 8696 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 132 ms | 8568 KB | Output is correct |
2 | Correct | 128 ms | 8568 KB | Output is correct |
3 | Correct | 134 ms | 8696 KB | Output is correct |
4 | Correct | 129 ms | 8568 KB | Output is correct |
5 | Correct | 127 ms | 8568 KB | Output is correct |
6 | Correct | 134 ms | 8700 KB | Output is correct |
7 | Correct | 134 ms | 8696 KB | Output is correct |
8 | Correct | 128 ms | 8568 KB | Output is correct |
9 | Correct | 131 ms | 8696 KB | Output is correct |
10 | Correct | 129 ms | 8696 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 512 KB | Output is correct |
25 | Correct | 1 ms | 384 KB | Output is correct |
26 | Correct | 1 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 119 ms | 8316 KB | Output is correct |
2 | Correct | 123 ms | 8568 KB | Output is correct |
3 | Correct | 124 ms | 8696 KB | Output is correct |
4 | Correct | 124 ms | 8668 KB | Output is correct |
5 | Correct | 121 ms | 8568 KB | Output is correct |
6 | Correct | 120 ms | 8440 KB | Output is correct |
7 | Correct | 119 ms | 8364 KB | Output is correct |
8 | Correct | 122 ms | 8652 KB | Output is correct |
9 | Correct | 120 ms | 8440 KB | Output is correct |
10 | Correct | 124 ms | 8592 KB | Output is correct |
11 | Correct | 85 ms | 8440 KB | Output is correct |
12 | Correct | 90 ms | 8696 KB | Output is correct |
13 | Correct | 92 ms | 8696 KB | Output is correct |
14 | Correct | 93 ms | 8568 KB | Output is correct |
15 | Correct | 121 ms | 8440 KB | Output is correct |
16 | Correct | 94 ms | 8440 KB | Output is correct |
17 | Correct | 99 ms | 8696 KB | Output is correct |
18 | Correct | 124 ms | 8568 KB | Output is correct |
19 | Correct | 120 ms | 8440 KB | Output is correct |
20 | Correct | 98 ms | 8696 KB | Output is correct |
21 | Correct | 132 ms | 8568 KB | Output is correct |
22 | Correct | 128 ms | 8568 KB | Output is correct |
23 | Correct | 134 ms | 8696 KB | Output is correct |
24 | Correct | 129 ms | 8568 KB | Output is correct |
25 | Correct | 127 ms | 8568 KB | Output is correct |
26 | Correct | 134 ms | 8700 KB | Output is correct |
27 | Correct | 134 ms | 8696 KB | Output is correct |
28 | Correct | 128 ms | 8568 KB | Output is correct |
29 | Correct | 131 ms | 8696 KB | Output is correct |
30 | Correct | 129 ms | 8696 KB | Output is correct |
31 | Correct | 1 ms | 384 KB | Output is correct |
32 | Correct | 1 ms | 384 KB | Output is correct |
33 | Correct | 1 ms | 384 KB | Output is correct |
34 | Correct | 1 ms | 384 KB | Output is correct |
35 | Correct | 0 ms | 384 KB | Output is correct |
36 | Correct | 1 ms | 384 KB | Output is correct |
37 | Correct | 1 ms | 384 KB | Output is correct |
38 | Correct | 1 ms | 384 KB | Output is correct |
39 | Correct | 1 ms | 384 KB | Output is correct |
40 | Correct | 1 ms | 384 KB | Output is correct |
41 | Correct | 1 ms | 384 KB | Output is correct |
42 | Correct | 1 ms | 384 KB | Output is correct |
43 | Correct | 1 ms | 384 KB | Output is correct |
44 | Correct | 1 ms | 384 KB | Output is correct |
45 | Correct | 1 ms | 384 KB | Output is correct |
46 | Correct | 1 ms | 384 KB | Output is correct |
47 | Correct | 1 ms | 384 KB | Output is correct |
48 | Correct | 1 ms | 384 KB | Output is correct |
49 | Correct | 1 ms | 384 KB | Output is correct |
50 | Correct | 1 ms | 384 KB | Output is correct |
51 | Correct | 1 ms | 384 KB | Output is correct |
52 | Correct | 2 ms | 384 KB | Output is correct |
53 | Correct | 2 ms | 384 KB | Output is correct |
54 | Correct | 2 ms | 512 KB | Output is correct |
55 | Correct | 1 ms | 384 KB | Output is correct |
56 | Correct | 1 ms | 384 KB | Output is correct |
57 | Correct | 2 ms | 384 KB | Output is correct |
58 | Correct | 2 ms | 384 KB | Output is correct |
59 | Correct | 2 ms | 384 KB | Output is correct |
60 | Correct | 1 ms | 384 KB | Output is correct |
61 | Correct | 165 ms | 8440 KB | Output is correct |
62 | Correct | 164 ms | 8824 KB | Output is correct |
63 | Correct | 143 ms | 8568 KB | Output is correct |
64 | Correct | 169 ms | 8748 KB | Output is correct |
65 | Correct | 175 ms | 8696 KB | Output is correct |
66 | Correct | 167 ms | 8568 KB | Output is correct |
67 | Correct | 169 ms | 8520 KB | Output is correct |
68 | Correct | 132 ms | 8568 KB | Output is correct |
69 | Correct | 128 ms | 8440 KB | Output is correct |
70 | Correct | 129 ms | 8480 KB | Output is correct |