답안 #1017540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017540 2024-07-09T08:45:07 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
95 ms 11352 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 = 1e16, 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 44 ms 8280 KB Output is correct
2 Correct 46 ms 8540 KB Output is correct
3 Correct 46 ms 8528 KB Output is correct
4 Correct 48 ms 8532 KB Output is correct
5 Correct 45 ms 8532 KB Output is correct
6 Correct 45 ms 8396 KB Output is correct
7 Correct 45 ms 8280 KB Output is correct
8 Correct 48 ms 8528 KB Output is correct
9 Correct 44 ms 8408 KB Output is correct
10 Correct 45 ms 8508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 8280 KB Output is correct
2 Correct 28 ms 9540 KB Output is correct
3 Correct 27 ms 9564 KB Output is correct
4 Correct 39 ms 9560 KB Output is correct
5 Correct 25 ms 10708 KB Output is correct
6 Correct 27 ms 9296 KB Output is correct
7 Correct 45 ms 9784 KB Output is correct
8 Correct 27 ms 11092 KB Output is correct
9 Correct 27 ms 10576 KB Output is correct
10 Correct 39 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 8532 KB Output is correct
2 Correct 43 ms 10808 KB Output is correct
3 Correct 49 ms 11352 KB Output is correct
4 Correct 44 ms 10832 KB Output is correct
5 Correct 42 ms 11088 KB Output is correct
6 Correct 44 ms 11088 KB Output is correct
7 Correct 45 ms 11088 KB Output is correct
8 Correct 45 ms 11092 KB Output is correct
9 Correct 42 ms 11088 KB Output is correct
10 Correct 48 ms 11092 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 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 452 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 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 452 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 452 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 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 452 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 452 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 348 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 344 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 44 ms 8280 KB Output is correct
2 Correct 46 ms 8540 KB Output is correct
3 Correct 46 ms 8528 KB Output is correct
4 Correct 48 ms 8532 KB Output is correct
5 Correct 45 ms 8532 KB Output is correct
6 Correct 45 ms 8396 KB Output is correct
7 Correct 45 ms 8280 KB Output is correct
8 Correct 48 ms 8528 KB Output is correct
9 Correct 44 ms 8408 KB Output is correct
10 Correct 45 ms 8508 KB Output is correct
11 Correct 29 ms 8280 KB Output is correct
12 Correct 28 ms 9540 KB Output is correct
13 Correct 27 ms 9564 KB Output is correct
14 Correct 39 ms 9560 KB Output is correct
15 Correct 25 ms 10708 KB Output is correct
16 Correct 27 ms 9296 KB Output is correct
17 Correct 45 ms 9784 KB Output is correct
18 Correct 27 ms 11092 KB Output is correct
19 Correct 27 ms 10576 KB Output is correct
20 Correct 39 ms 9564 KB Output is correct
21 Correct 41 ms 8532 KB Output is correct
22 Correct 43 ms 10808 KB Output is correct
23 Correct 49 ms 11352 KB Output is correct
24 Correct 44 ms 10832 KB Output is correct
25 Correct 42 ms 11088 KB Output is correct
26 Correct 44 ms 11088 KB Output is correct
27 Correct 45 ms 11088 KB Output is correct
28 Correct 45 ms 11092 KB Output is correct
29 Correct 42 ms 11088 KB Output is correct
30 Correct 48 ms 11092 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 452 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 456 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 452 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 452 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 348 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 344 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 11092 KB Output is correct
62 Correct 95 ms 11208 KB Output is correct
63 Correct 63 ms 10832 KB Output is correct
64 Correct 82 ms 11092 KB Output is correct
65 Correct 73 ms 11092 KB Output is correct
66 Correct 76 ms 11092 KB Output is correct
67 Correct 71 ms 10844 KB Output is correct
68 Correct 52 ms 11032 KB Output is correct
69 Correct 52 ms 10764 KB Output is correct
70 Correct 40 ms 10700 KB Output is correct