Submission #1092681

#TimeUsernameProblemLanguageResultExecution timeMemory
1092681muhammadFeast (NOI19_feast)C++17
0 / 100
1047 ms262144 KiB
#include <iostream> #include <vector> #include <algorithm> #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]; } // DP array initialized with a very small value (negative infinity) vector<vector<long long>> dp(N + 1, vector<long long>(K + 1, LLONG_MIN)); dp[0][0] = 0; // Base case // Iterate over each possible plate for (int i = 1; i <= N; ++i) { for (int j = 0; j <= K; ++j) { // If not taking the i-th plate for the j-th person dp[i][j] = max(dp[i][j], dp[i - 1][j]); } // Iterate over the number of people (from 1 to K) for (int j = 1; j <= K; ++j) { // Keep track of the sum for the current segment ending at `i` long long current_sum = 0; // Iterate back from `i` to track the best sum ending at `i` for person `j` for (int x = i; x > 0; --x) { current_sum += A[x]; dp[i][j] = max(dp[i][j], dp[x - 1][j - 1] + current_sum); } } } cout << dp[N][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...