Submission #754150

#TimeUsernameProblemLanguageResultExecution timeMemory
754150OlympiaK blocks (IZhO14_blocks)C++17
53 / 100
1078 ms468 KiB
#include <vector> #include <iostream> #include <cassert> #include <cmath> #include <map> #include <set> using namespace std; int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, K; cin >> N >> K; int64_t arr[N]; for (int i = 0; i < N; i++) { cin >> arr[i]; } int64_t INF = 1e17; vector<int64_t> prev(N + 1), cur(N + 1); prev.assign(N + 1, INF), cur.assign(N + 1, INF); for (int j = 1; j <= N; j++) { prev[j] = ((j == 1) ? arr[0] : max(prev[j - 1], arr[j - 1])); } for (int i = 2; i <= K; i++) { for (int j = 1; j <= N; j++) { if (j == 1) { cur[1] = prev[0] + arr[0]; } else { cur[j] = INF; int64_t myMax = 0; for (int l = j - 1; l >= 0; l--) { myMax = max(myMax, arr[l]); if (myMax == arr[j - 1]) { cur[j] = min(cur[j], prev[l] + myMax); } else { cur[j] = min(cur[j], prev[l] + myMax); } } } } swap(cur, prev); } cout << prev[N]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...