Submission #997176

# Submission time Handle Problem Language Result Execution time Memory
997176 2024-06-11T19:10:06 Z anonymous321 Feast (NOI19_feast) C++17
100 / 100
243 ms 13768 KB
// https://oj.uz/problem/view/NOI19_feast
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a (n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    ll ans = 0;
    ll lo = 0;
    ll hi = 1LL << 55;
    while (lo < hi) {
        ll mid = lo + (hi - lo)/2;
        vector<ll> dp (n+1, 0);
        vector<ll> p (n+1, 0);
        ll best = 0;
        int id = 0;
        vector<int> cnt (n+1, 0);
        for (int i = 0; i < n; i++) {
            p[i+1] = p[i] + a[i];
            dp[i+1] = dp[i];
            cnt[i+1] = cnt[i];
            if (dp[i+1] < best + p[i+1] - mid) {
                dp[i+1] = best + p[i+1] - mid;
                cnt[i+1] = cnt[id] + 1;
            }
            if (best < dp[i+1] - p[i+1]) {
                best = dp[i+1] - p[i+1];
                id = i+1;
            }
        }
        
        if (cnt[n] <= k) {
            hi = mid;
            ans = dp[n];
        } else {
            lo = mid+1;
        }
    }
    cout << ans + k*hi << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 179 ms 8504 KB Output is correct
2 Correct 199 ms 8684 KB Output is correct
3 Correct 190 ms 8820 KB Output is correct
4 Correct 185 ms 10604 KB Output is correct
5 Correct 186 ms 8680 KB Output is correct
6 Correct 160 ms 8496 KB Output is correct
7 Correct 198 ms 8496 KB Output is correct
8 Correct 166 ms 8736 KB Output is correct
9 Correct 167 ms 8580 KB Output is correct
10 Correct 185 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 8556 KB Output is correct
2 Correct 125 ms 9012 KB Output is correct
3 Correct 146 ms 8636 KB Output is correct
4 Correct 150 ms 8624 KB Output is correct
5 Correct 192 ms 8596 KB Output is correct
6 Correct 147 ms 8724 KB Output is correct
7 Correct 162 ms 8756 KB Output is correct
8 Correct 182 ms 8800 KB Output is correct
9 Correct 186 ms 8856 KB Output is correct
10 Correct 152 ms 8648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 8636 KB Output is correct
2 Correct 198 ms 11508 KB Output is correct
3 Correct 206 ms 11664 KB Output is correct
4 Correct 161 ms 11508 KB Output is correct
5 Correct 223 ms 11640 KB Output is correct
6 Correct 206 ms 11764 KB Output is correct
7 Correct 184 ms 11724 KB Output is correct
8 Correct 201 ms 11636 KB Output is correct
9 Correct 207 ms 13768 KB Output is correct
10 Correct 200 ms 11860 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 448 KB Output is correct
5 Correct 1 ms 432 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 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 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 448 KB Output is correct
5 Correct 1 ms 432 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 348 KB Output is correct
9 Correct 0 ms 344 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 436 KB Output is correct
14 Correct 1 ms 344 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 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 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 448 KB Output is correct
5 Correct 1 ms 432 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 348 KB Output is correct
9 Correct 0 ms 344 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 436 KB Output is correct
14 Correct 1 ms 344 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 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 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 444 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 8504 KB Output is correct
2 Correct 199 ms 8684 KB Output is correct
3 Correct 190 ms 8820 KB Output is correct
4 Correct 185 ms 10604 KB Output is correct
5 Correct 186 ms 8680 KB Output is correct
6 Correct 160 ms 8496 KB Output is correct
7 Correct 198 ms 8496 KB Output is correct
8 Correct 166 ms 8736 KB Output is correct
9 Correct 167 ms 8580 KB Output is correct
10 Correct 185 ms 8612 KB Output is correct
11 Correct 144 ms 8556 KB Output is correct
12 Correct 125 ms 9012 KB Output is correct
13 Correct 146 ms 8636 KB Output is correct
14 Correct 150 ms 8624 KB Output is correct
15 Correct 192 ms 8596 KB Output is correct
16 Correct 147 ms 8724 KB Output is correct
17 Correct 162 ms 8756 KB Output is correct
18 Correct 182 ms 8800 KB Output is correct
19 Correct 186 ms 8856 KB Output is correct
20 Correct 152 ms 8648 KB Output is correct
21 Correct 180 ms 8636 KB Output is correct
22 Correct 198 ms 11508 KB Output is correct
23 Correct 206 ms 11664 KB Output is correct
24 Correct 161 ms 11508 KB Output is correct
25 Correct 223 ms 11640 KB Output is correct
26 Correct 206 ms 11764 KB Output is correct
27 Correct 184 ms 11724 KB Output is correct
28 Correct 201 ms 11636 KB Output is correct
29 Correct 207 ms 13768 KB Output is correct
30 Correct 200 ms 11860 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 448 KB Output is correct
35 Correct 1 ms 432 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 436 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 444 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 239 ms 13432 KB Output is correct
62 Correct 243 ms 11828 KB Output is correct
63 Correct 187 ms 11520 KB Output is correct
64 Correct 242 ms 12300 KB Output is correct
65 Correct 237 ms 11672 KB Output is correct
66 Correct 227 ms 11732 KB Output is correct
67 Correct 231 ms 13516 KB Output is correct
68 Correct 198 ms 11724 KB Output is correct
69 Correct 203 ms 11576 KB Output is correct
70 Correct 201 ms 11552 KB Output is correct