답안 #1026006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026006 2024-07-17T12:29:12 Z Zicrus Feast (NOI19_feast) C++17
100 / 100
106 ms 5724 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n, k;
vector<ll> a;

pair<ll, ll> solve(ll p) {
    ll dp = 0;
    ll dpSeg = a[0] - p;
    ll ps = 0;
    ll psSeg = 1;
    for (int i = 1; i < n; i++) {
        ll tdp = dp, tdpSeg = dpSeg, tps = ps, tpsSeg = psSeg;
        if (tdpSeg > tdp) {
            dp = tdpSeg;
            ps = tpsSeg;
        }
        if (tdp - p > tdpSeg) {
            dpSeg = tdp - p;
            psSeg = tps + 1;
        }
        dpSeg += a[i];
    }
    if (dpSeg > dp) {
        dp = dpSeg;
        ps = psSeg;
    }
    return {dp, ps};
}

int main() {
    ios::sync_with_stdio(0);

    cin >> n >> k;
    a = vector<ll>(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll l = 0, r = 1ll << 50;
    ll bestK = 1ll << 50;
    ll bestAns = 0;
    ll pen = 0;
    while (l <= r) {
        ll mid = pen = (l + r) / 2;
        auto best = solve(mid);
        bestK = best.second;
        bestAns = best.first;

        if (bestK > k) {
            l = mid + 1;
        }
        else {
            if (l == r) break;
            r = mid;
        }
    }
    ll val = bestAns + k * pen;
    cout << val;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 5200 KB Output is correct
2 Correct 36 ms 5212 KB Output is correct
3 Correct 54 ms 5212 KB Output is correct
4 Correct 38 ms 5208 KB Output is correct
5 Correct 52 ms 4444 KB Output is correct
6 Correct 41 ms 4272 KB Output is correct
7 Correct 36 ms 4188 KB Output is correct
8 Correct 39 ms 4440 KB Output is correct
9 Correct 45 ms 4188 KB Output is correct
10 Correct 46 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 3416 KB Output is correct
2 Correct 60 ms 3424 KB Output is correct
3 Correct 30 ms 3416 KB Output is correct
4 Correct 36 ms 3540 KB Output is correct
5 Correct 35 ms 4184 KB Output is correct
6 Correct 58 ms 3380 KB Output is correct
7 Correct 29 ms 3420 KB Output is correct
8 Correct 65 ms 2652 KB Output is correct
9 Correct 35 ms 2652 KB Output is correct
10 Correct 60 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 2652 KB Output is correct
2 Correct 53 ms 2648 KB Output is correct
3 Correct 54 ms 2652 KB Output is correct
4 Correct 59 ms 2648 KB Output is correct
5 Correct 89 ms 2652 KB Output is correct
6 Correct 53 ms 2648 KB Output is correct
7 Correct 55 ms 2648 KB Output is correct
8 Correct 61 ms 2652 KB Output is correct
9 Correct 87 ms 2652 KB Output is correct
10 Correct 54 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 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 0 ms 460 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 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 0 ms 460 KB Output is correct
19 Correct 1 ms 600 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 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 5200 KB Output is correct
2 Correct 36 ms 5212 KB Output is correct
3 Correct 54 ms 5212 KB Output is correct
4 Correct 38 ms 5208 KB Output is correct
5 Correct 52 ms 4444 KB Output is correct
6 Correct 41 ms 4272 KB Output is correct
7 Correct 36 ms 4188 KB Output is correct
8 Correct 39 ms 4440 KB Output is correct
9 Correct 45 ms 4188 KB Output is correct
10 Correct 46 ms 4700 KB Output is correct
11 Correct 33 ms 3416 KB Output is correct
12 Correct 60 ms 3424 KB Output is correct
13 Correct 30 ms 3416 KB Output is correct
14 Correct 36 ms 3540 KB Output is correct
15 Correct 35 ms 4184 KB Output is correct
16 Correct 58 ms 3380 KB Output is correct
17 Correct 29 ms 3420 KB Output is correct
18 Correct 65 ms 2652 KB Output is correct
19 Correct 35 ms 2652 KB Output is correct
20 Correct 60 ms 2652 KB Output is correct
21 Correct 58 ms 2652 KB Output is correct
22 Correct 53 ms 2648 KB Output is correct
23 Correct 54 ms 2652 KB Output is correct
24 Correct 59 ms 2648 KB Output is correct
25 Correct 89 ms 2652 KB Output is correct
26 Correct 53 ms 2648 KB Output is correct
27 Correct 55 ms 2648 KB Output is correct
28 Correct 61 ms 2652 KB Output is correct
29 Correct 87 ms 2652 KB Output is correct
30 Correct 54 ms 2652 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 452 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 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 0 ms 460 KB Output is correct
49 Correct 1 ms 600 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 344 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 77 ms 5556 KB Output is correct
62 Correct 77 ms 5724 KB Output is correct
63 Correct 66 ms 5680 KB Output is correct
64 Correct 106 ms 5720 KB Output is correct
65 Correct 84 ms 5724 KB Output is correct
66 Correct 81 ms 5588 KB Output is correct
67 Correct 102 ms 5720 KB Output is correct
68 Correct 57 ms 5716 KB Output is correct
69 Correct 56 ms 5460 KB Output is correct
70 Correct 55 ms 5468 KB Output is correct