Submission #218287

# Submission time Handle Problem Language Result Execution time Memory
218287 2020-04-01T19:56:22 Z dolphingarlic Feast (NOI19_feast) C++14
100 / 100
170 ms 9336 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

ll a[300001], dp[300001];
int cnt[300001];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    FOR(i, 1, n + 1) cin >> a[i];

    ll l = 0, r = 3e14, ans = 0;
    while (l != r) {
        ll mid = (l + r) / 2;

        ll local_max = 0, local_max_cnt = 0;
        FOR(i, 1, n + 1) {
            local_max += a[i];
            if (dp[i - 1] >= local_max - mid) {
                dp[i] = dp[i - 1];
                cnt[i] = cnt[i - 1];
            } else {
                dp[i] = local_max - mid;
                cnt[i] = local_max_cnt + 1;
            }

            if (local_max < dp[i - 1]) {
                local_max = dp[i - 1];
                local_max_cnt = cnt[i - 1];
            }
        }

        if (cnt[n] <= k) {
            r = mid;
            ans = max(ans, dp[n] + mid * cnt[n]);
        } else
            l = mid + 1;
    }

    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 8824 KB Output is correct
2 Correct 85 ms 8952 KB Output is correct
3 Correct 70 ms 9080 KB Output is correct
4 Correct 67 ms 8952 KB Output is correct
5 Correct 67 ms 8952 KB Output is correct
6 Correct 74 ms 8952 KB Output is correct
7 Correct 92 ms 8824 KB Output is correct
8 Correct 65 ms 9080 KB Output is correct
9 Correct 69 ms 8824 KB Output is correct
10 Correct 66 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 7168 KB Output is correct
2 Correct 62 ms 7288 KB Output is correct
3 Correct 56 ms 7168 KB Output is correct
4 Correct 58 ms 7296 KB Output is correct
5 Correct 85 ms 8824 KB Output is correct
6 Correct 55 ms 7168 KB Output is correct
7 Correct 59 ms 7288 KB Output is correct
8 Correct 67 ms 9084 KB Output is correct
9 Correct 67 ms 8824 KB Output is correct
10 Correct 57 ms 7296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 9208 KB Output is correct
2 Correct 105 ms 9080 KB Output is correct
3 Correct 108 ms 9180 KB Output is correct
4 Correct 105 ms 9080 KB Output is correct
5 Correct 106 ms 9084 KB Output is correct
6 Correct 107 ms 9336 KB Output is correct
7 Correct 106 ms 9208 KB Output is correct
8 Correct 117 ms 9080 KB Output is correct
9 Correct 109 ms 9208 KB Output is correct
10 Correct 107 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 308 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 308 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 308 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 8824 KB Output is correct
2 Correct 85 ms 8952 KB Output is correct
3 Correct 70 ms 9080 KB Output is correct
4 Correct 67 ms 8952 KB Output is correct
5 Correct 67 ms 8952 KB Output is correct
6 Correct 74 ms 8952 KB Output is correct
7 Correct 92 ms 8824 KB Output is correct
8 Correct 65 ms 9080 KB Output is correct
9 Correct 69 ms 8824 KB Output is correct
10 Correct 66 ms 8952 KB Output is correct
11 Correct 65 ms 7168 KB Output is correct
12 Correct 62 ms 7288 KB Output is correct
13 Correct 56 ms 7168 KB Output is correct
14 Correct 58 ms 7296 KB Output is correct
15 Correct 85 ms 8824 KB Output is correct
16 Correct 55 ms 7168 KB Output is correct
17 Correct 59 ms 7288 KB Output is correct
18 Correct 67 ms 9084 KB Output is correct
19 Correct 67 ms 8824 KB Output is correct
20 Correct 57 ms 7296 KB Output is correct
21 Correct 116 ms 9208 KB Output is correct
22 Correct 105 ms 9080 KB Output is correct
23 Correct 108 ms 9180 KB Output is correct
24 Correct 105 ms 9080 KB Output is correct
25 Correct 106 ms 9084 KB Output is correct
26 Correct 107 ms 9336 KB Output is correct
27 Correct 106 ms 9208 KB Output is correct
28 Correct 117 ms 9080 KB Output is correct
29 Correct 109 ms 9208 KB Output is correct
30 Correct 107 ms 9208 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 308 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 5 ms 640 KB Output is correct
51 Correct 7 ms 384 KB Output is correct
52 Correct 6 ms 384 KB Output is correct
53 Correct 6 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 6 ms 384 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 6 ms 384 KB Output is correct
61 Correct 153 ms 9080 KB Output is correct
62 Correct 165 ms 9208 KB Output is correct
63 Correct 123 ms 8952 KB Output is correct
64 Correct 148 ms 9184 KB Output is correct
65 Correct 159 ms 9208 KB Output is correct
66 Correct 170 ms 9228 KB Output is correct
67 Correct 154 ms 9080 KB Output is correct
68 Correct 112 ms 9148 KB Output is correct
69 Correct 108 ms 9208 KB Output is correct
70 Correct 105 ms 8952 KB Output is correct