답안 #1017539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017539 2024-07-09T08:44:36 Z vjudge1 Feast (NOI19_feast) C++17
4 / 100
1000 ms 11136 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 46 ms 10576 KB Output is correct
2 Correct 49 ms 10908 KB Output is correct
3 Correct 47 ms 11080 KB Output is correct
4 Correct 47 ms 11136 KB Output is correct
5 Correct 58 ms 10896 KB Output is correct
6 Correct 47 ms 10580 KB Output is correct
7 Correct 46 ms 10580 KB Output is correct
8 Correct 47 ms 10992 KB Output is correct
9 Correct 47 ms 10720 KB Output is correct
10 Correct 47 ms 10832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1010 ms 9512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1061 ms 11092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1099 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1099 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1099 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 10576 KB Output is correct
2 Correct 49 ms 10908 KB Output is correct
3 Correct 47 ms 11080 KB Output is correct
4 Correct 47 ms 11136 KB Output is correct
5 Correct 58 ms 10896 KB Output is correct
6 Correct 47 ms 10580 KB Output is correct
7 Correct 46 ms 10580 KB Output is correct
8 Correct 47 ms 10992 KB Output is correct
9 Correct 47 ms 10720 KB Output is correct
10 Correct 47 ms 10832 KB Output is correct
11 Execution timed out 1010 ms 9512 KB Time limit exceeded
12 Halted 0 ms 0 KB -