답안 #1023204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023204 2024-07-14T13:04:44 Z SulA Feast (NOI19_feast) C++17
100 / 100
95 ms 11708 KB
#include <bits/stdc++.h>
using namespace std;
long long dp[300001][2];
int cnt[300001][2];

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 = 5e10, ans;
    while (r > l) {
        long long lambda = (l+r)/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 38 ms 11088 KB Output is correct
2 Correct 38 ms 11204 KB Output is correct
3 Correct 41 ms 11452 KB Output is correct
4 Correct 41 ms 11228 KB Output is correct
5 Correct 47 ms 11196 KB Output is correct
6 Correct 41 ms 11088 KB Output is correct
7 Correct 39 ms 11092 KB Output is correct
8 Correct 39 ms 11344 KB Output is correct
9 Correct 41 ms 11100 KB Output is correct
10 Correct 45 ms 11092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 9716 KB Output is correct
2 Correct 22 ms 9556 KB Output is correct
3 Correct 20 ms 9564 KB Output is correct
4 Correct 31 ms 9564 KB Output is correct
5 Correct 24 ms 11092 KB Output is correct
6 Correct 19 ms 9428 KB Output is correct
7 Correct 32 ms 9564 KB Output is correct
8 Correct 24 ms 11356 KB Output is correct
9 Correct 30 ms 11100 KB Output is correct
10 Correct 33 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 11348 KB Output is correct
2 Correct 32 ms 11352 KB Output is correct
3 Correct 28 ms 11348 KB Output is correct
4 Correct 30 ms 11256 KB Output is correct
5 Correct 26 ms 11356 KB Output is correct
6 Correct 28 ms 11596 KB Output is correct
7 Correct 34 ms 11604 KB Output is correct
8 Correct 32 ms 11320 KB Output is correct
9 Correct 31 ms 11600 KB Output is correct
10 Correct 32 ms 11604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 468 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 468 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 460 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 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 468 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 460 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 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 0 ms 344 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 0 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 11088 KB Output is correct
2 Correct 38 ms 11204 KB Output is correct
3 Correct 41 ms 11452 KB Output is correct
4 Correct 41 ms 11228 KB Output is correct
5 Correct 47 ms 11196 KB Output is correct
6 Correct 41 ms 11088 KB Output is correct
7 Correct 39 ms 11092 KB Output is correct
8 Correct 39 ms 11344 KB Output is correct
9 Correct 41 ms 11100 KB Output is correct
10 Correct 45 ms 11092 KB Output is correct
11 Correct 27 ms 9716 KB Output is correct
12 Correct 22 ms 9556 KB Output is correct
13 Correct 20 ms 9564 KB Output is correct
14 Correct 31 ms 9564 KB Output is correct
15 Correct 24 ms 11092 KB Output is correct
16 Correct 19 ms 9428 KB Output is correct
17 Correct 32 ms 9564 KB Output is correct
18 Correct 24 ms 11356 KB Output is correct
19 Correct 30 ms 11100 KB Output is correct
20 Correct 33 ms 9560 KB Output is correct
21 Correct 28 ms 11348 KB Output is correct
22 Correct 32 ms 11352 KB Output is correct
23 Correct 28 ms 11348 KB Output is correct
24 Correct 30 ms 11256 KB Output is correct
25 Correct 26 ms 11356 KB Output is correct
26 Correct 28 ms 11596 KB Output is correct
27 Correct 34 ms 11604 KB Output is correct
28 Correct 32 ms 11320 KB Output is correct
29 Correct 31 ms 11600 KB Output is correct
30 Correct 32 ms 11604 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 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 468 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 460 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 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 464 KB Output is correct
50 Correct 0 ms 344 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 0 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 64 ms 11348 KB Output is correct
62 Correct 95 ms 11708 KB Output is correct
63 Correct 49 ms 11300 KB Output is correct
64 Correct 69 ms 11620 KB Output is correct
65 Correct 60 ms 11604 KB Output is correct
66 Correct 64 ms 11580 KB Output is correct
67 Correct 63 ms 11344 KB Output is correct
68 Correct 42 ms 11604 KB Output is correct
69 Correct 36 ms 11356 KB Output is correct
70 Correct 31 ms 11344 KB Output is correct