Submission #386351

# Submission time Handle Problem Language Result Execution time Memory
386351 2021-04-06T12:28:51 Z Aryan_Raina Feast (NOI19_feast) C++14
100 / 100
177 ms 12780 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define ar array

const int INF = 1e15;
const int MOD = 1e9+7;

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, k; cin>>n>>k;
    vector<int> a(n);
    for (int &i : a) cin>>i;
    vector<int> pf(n+1);
    pf[0] = 0; for (int i = 1; i <= n; i++) pf[i] = pf[i-1] + a[i-1];
    int dp[n+1], cnt[n+1];
    auto compute = [&](int lambda) {
        dp[0] = cnt[0] = 0;
        int besti = 0;
        for (int i = 1; i <= n; i++) {
            dp[i] = dp[i-1], cnt[i] = cnt[i-1];
            if (dp[i] < dp[besti] + pf[i] - pf[besti] - lambda) {
                dp[i] = dp[besti] + pf[i] - pf[besti] - lambda;
                cnt[i] = cnt[besti] + 1;
            }
            if (dp[besti] - pf[besti] < dp[i] - pf[i]) besti = i;
        }
    };
    int lo = 0, hi = 1e18, mid;
    while (lo + 1 < hi) {
        mid = (lo + hi) >> 1;
        compute(mid);
        if (cnt[n] <= k) {
            hi = mid;
        } else lo = mid+1;
    }
    compute(hi);
    cout<<dp[n] + cnt[n]*hi<<"\n";
}  
# Verdict Execution time Memory Grader output
1 Correct 136 ms 12524 KB Output is correct
2 Correct 146 ms 12524 KB Output is correct
3 Correct 137 ms 12652 KB Output is correct
4 Correct 139 ms 12652 KB Output is correct
5 Correct 139 ms 12396 KB Output is correct
6 Correct 134 ms 12268 KB Output is correct
7 Correct 136 ms 12268 KB Output is correct
8 Correct 141 ms 12524 KB Output is correct
9 Correct 134 ms 12268 KB Output is correct
10 Correct 136 ms 12396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 10604 KB Output is correct
2 Correct 122 ms 10860 KB Output is correct
3 Correct 117 ms 10604 KB Output is correct
4 Correct 123 ms 10732 KB Output is correct
5 Correct 135 ms 12268 KB Output is correct
6 Correct 117 ms 10604 KB Output is correct
7 Correct 123 ms 10860 KB Output is correct
8 Correct 140 ms 12652 KB Output is correct
9 Correct 135 ms 12268 KB Output is correct
10 Correct 120 ms 10732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 12652 KB Output is correct
2 Correct 126 ms 12524 KB Output is correct
3 Correct 129 ms 12652 KB Output is correct
4 Correct 128 ms 12512 KB Output is correct
5 Correct 130 ms 12692 KB Output is correct
6 Correct 133 ms 12652 KB Output is correct
7 Correct 129 ms 12780 KB Output is correct
8 Correct 130 ms 12780 KB Output is correct
9 Correct 132 ms 12780 KB Output is correct
10 Correct 130 ms 12780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 12524 KB Output is correct
2 Correct 146 ms 12524 KB Output is correct
3 Correct 137 ms 12652 KB Output is correct
4 Correct 139 ms 12652 KB Output is correct
5 Correct 139 ms 12396 KB Output is correct
6 Correct 134 ms 12268 KB Output is correct
7 Correct 136 ms 12268 KB Output is correct
8 Correct 141 ms 12524 KB Output is correct
9 Correct 134 ms 12268 KB Output is correct
10 Correct 136 ms 12396 KB Output is correct
11 Correct 113 ms 10604 KB Output is correct
12 Correct 122 ms 10860 KB Output is correct
13 Correct 117 ms 10604 KB Output is correct
14 Correct 123 ms 10732 KB Output is correct
15 Correct 135 ms 12268 KB Output is correct
16 Correct 117 ms 10604 KB Output is correct
17 Correct 123 ms 10860 KB Output is correct
18 Correct 140 ms 12652 KB Output is correct
19 Correct 135 ms 12268 KB Output is correct
20 Correct 120 ms 10732 KB Output is correct
21 Correct 133 ms 12652 KB Output is correct
22 Correct 126 ms 12524 KB Output is correct
23 Correct 129 ms 12652 KB Output is correct
24 Correct 128 ms 12512 KB Output is correct
25 Correct 130 ms 12692 KB Output is correct
26 Correct 133 ms 12652 KB Output is correct
27 Correct 129 ms 12780 KB Output is correct
28 Correct 130 ms 12780 KB Output is correct
29 Correct 132 ms 12780 KB Output is correct
30 Correct 130 ms 12780 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 2 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 364 KB Output is correct
53 Correct 2 ms 364 KB Output is correct
54 Correct 2 ms 364 KB Output is correct
55 Correct 2 ms 364 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 2 ms 364 KB Output is correct
58 Correct 2 ms 364 KB Output is correct
59 Correct 2 ms 364 KB Output is correct
60 Correct 2 ms 364 KB Output is correct
61 Correct 166 ms 12536 KB Output is correct
62 Correct 177 ms 12780 KB Output is correct
63 Correct 138 ms 12396 KB Output is correct
64 Correct 166 ms 12652 KB Output is correct
65 Correct 155 ms 12652 KB Output is correct
66 Correct 153 ms 12652 KB Output is correct
67 Correct 152 ms 12524 KB Output is correct
68 Correct 131 ms 12652 KB Output is correct
69 Correct 128 ms 12396 KB Output is correct
70 Correct 127 ms 12396 KB Output is correct