답안 #1092683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092683 2024-09-24T18:15:56 Z muhammad Feast (NOI19_feast) C++17
0 / 100
1000 ms 4532 KB
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> A(N + 1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }

    // Initialize the dp array with negative infinity
    vector<long long> dp(K + 1, LLONG_MIN);
    dp[0] = 0;  // Base case: no plates and 0 people = 0 satisfaction

    // Iterate through all plates
    for (int i = 1; i <= N; ++i) {
        // Start a temporary array for the next iteration
        vector<long long> next_dp = dp;

        // Maintain a variable to track the best value if starting a segment for person `j`
        long long max_so_far = LLONG_MIN;

        // Iterate over possible people in reverse to avoid overwriting our current dp values
        for (int j = 1; j <= K; ++j) {
            max_so_far = max(max_so_far, dp[j - 1]);  // Find the best ending segment for `j-1`
            next_dp[j] = max(next_dp[j], max_so_far + A[i]);  // Update the current segment with the best value + current plate
        }

        dp = next_dp;  // Update dp with our next_dp
    }

    // The final result is the maximum value for `K` people using up to N plates
    cout << dp[K] << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 4532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 111 ms 1584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 4532 KB Time limit exceeded
2 Halted 0 ms 0 KB -