답안 #420019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420019 2021-06-07T23:17:41 Z CrouchingDragon Feast (NOI19_feast) C++17
100 / 100
131 ms 4568 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 + b * L;
    cout << ans << endl;

    exit(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1356 KB Output is correct
2 Correct 57 ms 1484 KB Output is correct
3 Correct 57 ms 1484 KB Output is correct
4 Correct 57 ms 1484 KB Output is correct
5 Correct 56 ms 1356 KB Output is correct
6 Correct 58 ms 1356 KB Output is correct
7 Correct 55 ms 1440 KB Output is correct
8 Correct 56 ms 1464 KB Output is correct
9 Correct 56 ms 1356 KB Output is correct
10 Correct 58 ms 1460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 1356 KB Output is correct
2 Correct 53 ms 1484 KB Output is correct
3 Correct 48 ms 1356 KB Output is correct
4 Correct 48 ms 1356 KB Output is correct
5 Correct 56 ms 1440 KB Output is correct
6 Correct 48 ms 1356 KB Output is correct
7 Correct 50 ms 1484 KB Output is correct
8 Correct 57 ms 1484 KB Output is correct
9 Correct 57 ms 1356 KB Output is correct
10 Correct 51 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 1484 KB Output is correct
2 Correct 85 ms 4420 KB Output is correct
3 Correct 84 ms 4392 KB Output is correct
4 Correct 87 ms 4380 KB Output is correct
5 Correct 88 ms 4476 KB Output is correct
6 Correct 96 ms 4516 KB Output is correct
7 Correct 85 ms 4404 KB Output is correct
8 Correct 89 ms 4388 KB Output is correct
9 Correct 87 ms 4540 KB Output is correct
10 Correct 86 ms 4408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 204 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 204 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 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1356 KB Output is correct
2 Correct 57 ms 1484 KB Output is correct
3 Correct 57 ms 1484 KB Output is correct
4 Correct 57 ms 1484 KB Output is correct
5 Correct 56 ms 1356 KB Output is correct
6 Correct 58 ms 1356 KB Output is correct
7 Correct 55 ms 1440 KB Output is correct
8 Correct 56 ms 1464 KB Output is correct
9 Correct 56 ms 1356 KB Output is correct
10 Correct 58 ms 1460 KB Output is correct
11 Correct 51 ms 1356 KB Output is correct
12 Correct 53 ms 1484 KB Output is correct
13 Correct 48 ms 1356 KB Output is correct
14 Correct 48 ms 1356 KB Output is correct
15 Correct 56 ms 1440 KB Output is correct
16 Correct 48 ms 1356 KB Output is correct
17 Correct 50 ms 1484 KB Output is correct
18 Correct 57 ms 1484 KB Output is correct
19 Correct 57 ms 1356 KB Output is correct
20 Correct 51 ms 1488 KB Output is correct
21 Correct 85 ms 1484 KB Output is correct
22 Correct 85 ms 4420 KB Output is correct
23 Correct 84 ms 4392 KB Output is correct
24 Correct 87 ms 4380 KB Output is correct
25 Correct 88 ms 4476 KB Output is correct
26 Correct 96 ms 4516 KB Output is correct
27 Correct 85 ms 4404 KB Output is correct
28 Correct 89 ms 4388 KB Output is correct
29 Correct 87 ms 4540 KB Output is correct
30 Correct 86 ms 4408 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 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 204 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 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 123 ms 4396 KB Output is correct
62 Correct 120 ms 4420 KB Output is correct
63 Correct 100 ms 4420 KB Output is correct
64 Correct 126 ms 4408 KB Output is correct
65 Correct 131 ms 4420 KB Output is correct
66 Correct 129 ms 4408 KB Output is correct
67 Correct 128 ms 4404 KB Output is correct
68 Correct 87 ms 4404 KB Output is correct
69 Correct 86 ms 4568 KB Output is correct
70 Correct 84 ms 4372 KB Output is correct