Submission #1017397

#TimeUsernameProblemLanguageResultExecution timeMemory
1017397vjudge1Feast (NOI19_feast)C++17
0 / 100
1085 ms262144 KiB
#include <iostream> #include <vector> #include <algorithm> #include <climits> using namespace std; int main() { //not uy tins int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } vector<vector<int>> dp(K + 1, vector<int>(N + 1, 0)); vector<int> prefixSum(N + 1, 0); for (int i = 1; i <= N; ++i) { prefixSum[i] = prefixSum[i - 1] + A[i - 1]; } for (int k = 1; k <= K; ++k) { for (int n = 1; n <= N; ++n) { dp[k][n] = dp[k][n - 1]; for (int i = 0; i < n; ++i) { dp[k][n] = max(dp[k][n], dp[k - 1][i] + prefixSum[n] - prefixSum[i]); } } } cout << dp[K][N] << 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...