답안 #1017664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017664 2024-07-09T09:24:24 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
115 ms 8588 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n,k; cin >> n >> k;
    int a[n+1];
    for (int i = 1; i <= n; cin >> a[i++]) {}

    long long l = 0, r = 1e14, ans;
    while (r > l) {
        long long lambda = (l+r)/2;
        long long dp[n+1][2];
        int cnt[n+1][2];
        dp[0][0] = 0;
        cnt[0][0] = 0;
        dp[0][1] = -1e18;
        for (int i = 1; i <= n; i++) {
            if (dp[i-1][0] > dp[i-1][1]) {
                dp[i][0] = dp[i-1][0];
                cnt[i][0] = cnt[i-1][0];
            } else {
                dp[i][0]= dp[i-1][1];
                cnt[i][0] = cnt[i-1][1];
            }

            if (dp[i-1][0] - lambda > dp[i-1][1]) {
                dp[i][1] = dp[i-1][0] - lambda + a[i];
                cnt[i][1] = cnt[i-1][0] + 1;
            } else {
                dp[i][1] = dp[i-1][1] + a[i];
                cnt[i][1] = cnt[i-1][1];
            }
        }
        double friends;
        if (dp[n][0] > dp[n][1]) {
            ans = dp[n][0] + lambda*cnt[n][0];
            friends = cnt[n][0];
        } else {
            ans = dp[n][1] + lambda*cnt[n][1];
            friends = cnt[n][1];
        }
        if (friends == k) {
            break;
        }
        if (friends > k) l = lambda+1;
        else r = lambda-1;
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8284 KB Output is correct
2 Correct 47 ms 8536 KB Output is correct
3 Correct 43 ms 8540 KB Output is correct
4 Correct 50 ms 8524 KB Output is correct
5 Correct 42 ms 8520 KB Output is correct
6 Correct 51 ms 8280 KB Output is correct
7 Correct 53 ms 8236 KB Output is correct
8 Correct 48 ms 8536 KB Output is correct
9 Correct 45 ms 8284 KB Output is correct
10 Correct 44 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 8280 KB Output is correct
2 Correct 41 ms 8384 KB Output is correct
3 Correct 40 ms 8248 KB Output is correct
4 Correct 38 ms 8280 KB Output is correct
5 Correct 24 ms 8284 KB Output is correct
6 Correct 24 ms 8448 KB Output is correct
7 Correct 36 ms 8536 KB Output is correct
8 Correct 28 ms 8540 KB Output is correct
9 Correct 22 ms 8244 KB Output is correct
10 Correct 39 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 8540 KB Output is correct
2 Correct 57 ms 8448 KB Output is correct
3 Correct 42 ms 8508 KB Output is correct
4 Correct 38 ms 8204 KB Output is correct
5 Correct 36 ms 8516 KB Output is correct
6 Correct 41 ms 8528 KB Output is correct
7 Correct 45 ms 8508 KB Output is correct
8 Correct 39 ms 8500 KB Output is correct
9 Correct 37 ms 8540 KB Output is correct
10 Correct 39 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 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 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 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 0 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 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8284 KB Output is correct
2 Correct 47 ms 8536 KB Output is correct
3 Correct 43 ms 8540 KB Output is correct
4 Correct 50 ms 8524 KB Output is correct
5 Correct 42 ms 8520 KB Output is correct
6 Correct 51 ms 8280 KB Output is correct
7 Correct 53 ms 8236 KB Output is correct
8 Correct 48 ms 8536 KB Output is correct
9 Correct 45 ms 8284 KB Output is correct
10 Correct 44 ms 8276 KB Output is correct
11 Correct 26 ms 8280 KB Output is correct
12 Correct 41 ms 8384 KB Output is correct
13 Correct 40 ms 8248 KB Output is correct
14 Correct 38 ms 8280 KB Output is correct
15 Correct 24 ms 8284 KB Output is correct
16 Correct 24 ms 8448 KB Output is correct
17 Correct 36 ms 8536 KB Output is correct
18 Correct 28 ms 8540 KB Output is correct
19 Correct 22 ms 8244 KB Output is correct
20 Correct 39 ms 8540 KB Output is correct
21 Correct 33 ms 8540 KB Output is correct
22 Correct 57 ms 8448 KB Output is correct
23 Correct 42 ms 8508 KB Output is correct
24 Correct 38 ms 8204 KB Output is correct
25 Correct 36 ms 8516 KB Output is correct
26 Correct 41 ms 8528 KB Output is correct
27 Correct 45 ms 8508 KB Output is correct
28 Correct 39 ms 8500 KB Output is correct
29 Correct 37 ms 8540 KB Output is correct
30 Correct 39 ms 8532 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 348 KB Output is correct
35 Correct 0 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 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 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 0 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 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 0 ms 348 KB Output is correct
61 Correct 71 ms 8272 KB Output is correct
62 Correct 115 ms 8528 KB Output is correct
63 Correct 55 ms 8272 KB Output is correct
64 Correct 76 ms 8528 KB Output is correct
65 Correct 63 ms 8540 KB Output is correct
66 Correct 71 ms 8552 KB Output is correct
67 Correct 67 ms 8248 KB Output is correct
68 Correct 44 ms 8588 KB Output is correct
69 Correct 42 ms 8240 KB Output is correct
70 Correct 36 ms 8408 KB Output is correct