Submission #1092683

#TimeUsernameProblemLanguageResultExecution timeMemory
1092683muhammadFeast (NOI19_feast)C++17
0 / 100
1063 ms4532 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...