Submission #1019339

#TimeUsernameProblemLanguageResultExecution timeMemory
1019339NicolaikrobFeast (NOI19_feast)C++17
59 / 100
135 ms262144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; ll A[n+1], DP[n+1][k+1], PS[n+1], B[k+1]; A[0] = PS[0] = 0; for(int i = 1; i <= n; i++) cin >> A[i], PS[i] = PS[i-1]+A[i]; for(int i = 0; i < k+1; i++) B[i] = PS[n]; for(int i = 0; i < n+1; i++) DP[i][0] = 0; for(int i = 0; i < k+1; i++) DP[0][i] = 0; for(int i = 1; i <= n; i++) { B[0] = max(B[0], PS[n]-PS[i]); for(int j = 1; j <= k; j++) { DP[i][j] = max(DP[i-1][j], B[j-1]-(PS[n]-PS[i])); B[j] = max(B[j], DP[i][j]+(PS[n]-PS[i])); } } cout << DP[n][k]; }
#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...