Submission #975931

# Submission time Handle Problem Language Result Execution time Memory
975931 2024-05-06T03:36:02 Z vjudge1 Feast (NOI19_feast) C++17
0 / 100
1000 ms 6956 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    vector<int> prefixSum(N + 1, 0);

    // Read satisfaction points and compute prefix sums
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        prefixSum[i + 1] = prefixSum[i] + A[i];
    }

    // Define a dynamic programming array
    vector<int> dp(N + 1);

    // Iterate over the number of people
    for (int j = 1; j <= K; ++j) {
        // Initialize binary search parameters
        int left = 0, right = N;

        // Binary search to find the optimal partition for each person
        while (left < right) {
            int mid = (left + right + 1) / 2;

            // Calculate the maximum satisfaction points achievable for the current segment
            int maxSum = prefixSum[mid];
            for (int i = 1; i <= mid; ++i) {
                maxSum = max(maxSum, prefixSum[mid] - prefixSum[i]);
            }

            // Check if the current segment satisfies the condition
            if (maxSum > dp[mid]) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }

        // Update dynamic programming table
        for (int i = 0; i <= N; ++i) {
            dp[i] = max(dp[i], prefixSum[left] - prefixSum[i]);
        }
    }

    cout << dp[N] << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1051 ms 6484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 6956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1051 ms 6484 KB Time limit exceeded
2 Halted 0 ms 0 KB -