Submission #420044

# Submission time Handle Problem Language Result Execution time Memory
420044 2021-06-08T02:00:09 Z CrouchingDragon Feast (NOI19_feast) C++17
100 / 100
129 ms 2756 KB
#include "bits/stdc++.h"

using namespace std;

#define endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(x) begin(x), end(x)

using ll = long long;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

template<typename T>
bool chmin(T& x, T y) { return y < x ? (x = y, true) : false; }
template<typename T>
bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; }
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    for (auto& x : A) cin >> x;

    auto f = [&](ll z) {
        ll dpmax = 0, prefsum = 0, prefmax = 0;
        int cnt_dpmax = 0, cnt_prefmax = 0;
        for (auto x : A) {
            prefsum += x;
            ll dp = prefsum + prefmax - z;
            if (chmax(dpmax, dp)) cnt_dpmax = 1 + cnt_prefmax;
            if (chmax(prefmax, dpmax - prefsum)) cnt_prefmax = cnt_dpmax;
        }
        return pair(dpmax, cnt_dpmax);
    };

    const ll inf = 1e13;
    ll L = 0, R = inf;
    while (L < R) {
        ll M = L + (R - L) / 2;
        f(M).second <= K ? R = M : L = M + 1;
    }

    auto [a, b] = f(L);
    ll ans = a + K * L;
    cout << ans << endl;

    exit(0);
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 2112 KB Output is correct
2 Correct 57 ms 2236 KB Output is correct
3 Correct 61 ms 2128 KB Output is correct
4 Correct 59 ms 2156 KB Output is correct
5 Correct 59 ms 2116 KB Output is correct
6 Correct 62 ms 2336 KB Output is correct
7 Correct 57 ms 2204 KB Output is correct
8 Correct 57 ms 2232 KB Output is correct
9 Correct 76 ms 2108 KB Output is correct
10 Correct 62 ms 2196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 2120 KB Output is correct
2 Correct 58 ms 2244 KB Output is correct
3 Correct 51 ms 2220 KB Output is correct
4 Correct 50 ms 2152 KB Output is correct
5 Correct 61 ms 2212 KB Output is correct
6 Correct 50 ms 2220 KB Output is correct
7 Correct 61 ms 2248 KB Output is correct
8 Correct 61 ms 2168 KB Output is correct
9 Correct 59 ms 2228 KB Output is correct
10 Correct 51 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 2236 KB Output is correct
2 Correct 88 ms 2756 KB Output is correct
3 Correct 87 ms 2680 KB Output is correct
4 Correct 91 ms 2656 KB Output is correct
5 Correct 84 ms 2604 KB Output is correct
6 Correct 104 ms 2692 KB Output is correct
7 Correct 87 ms 2628 KB Output is correct
8 Correct 85 ms 2568 KB Output is correct
9 Correct 87 ms 2700 KB Output is correct
10 Correct 85 ms 2628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 2112 KB Output is correct
2 Correct 57 ms 2236 KB Output is correct
3 Correct 61 ms 2128 KB Output is correct
4 Correct 59 ms 2156 KB Output is correct
5 Correct 59 ms 2116 KB Output is correct
6 Correct 62 ms 2336 KB Output is correct
7 Correct 57 ms 2204 KB Output is correct
8 Correct 57 ms 2232 KB Output is correct
9 Correct 76 ms 2108 KB Output is correct
10 Correct 62 ms 2196 KB Output is correct
11 Correct 52 ms 2120 KB Output is correct
12 Correct 58 ms 2244 KB Output is correct
13 Correct 51 ms 2220 KB Output is correct
14 Correct 50 ms 2152 KB Output is correct
15 Correct 61 ms 2212 KB Output is correct
16 Correct 50 ms 2220 KB Output is correct
17 Correct 61 ms 2248 KB Output is correct
18 Correct 61 ms 2168 KB Output is correct
19 Correct 59 ms 2228 KB Output is correct
20 Correct 51 ms 2132 KB Output is correct
21 Correct 87 ms 2236 KB Output is correct
22 Correct 88 ms 2756 KB Output is correct
23 Correct 87 ms 2680 KB Output is correct
24 Correct 91 ms 2656 KB Output is correct
25 Correct 84 ms 2604 KB Output is correct
26 Correct 104 ms 2692 KB Output is correct
27 Correct 87 ms 2628 KB Output is correct
28 Correct 85 ms 2568 KB Output is correct
29 Correct 87 ms 2700 KB Output is correct
30 Correct 85 ms 2628 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 312 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 324 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 121 ms 2668 KB Output is correct
62 Correct 120 ms 2656 KB Output is correct
63 Correct 99 ms 2680 KB Output is correct
64 Correct 122 ms 2584 KB Output is correct
65 Correct 129 ms 2744 KB Output is correct
66 Correct 126 ms 2688 KB Output is correct
67 Correct 127 ms 2648 KB Output is correct
68 Correct 89 ms 2692 KB Output is correct
69 Correct 88 ms 2664 KB Output is correct
70 Correct 83 ms 2596 KB Output is correct