Submission #13514

#TimeUsernameProblemLanguageResultExecution timeMemory
13514tncks0121K blocks (IZhO14_blocks)C++14
0 / 100
0 ms42824 KiB
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <string> #include <functional> #include <vector> #include <deque> #include <utility> #include <bitset> #include <limits.h> #include <time.h> using namespace std; typedef long long ll; typedef unsigned long long llu; typedef double lf; typedef unsigned int uint; typedef long double llf; typedef pair<int, int> pii; const int N_ = 100500; const int K_ = 105; int N, K, A[N_]; int tb[K_][N_]; vector<pii> stk; int main() { scanf("%d%d", &N, &K); for (int i = 1; i <= N; i++) scanf("%d", A + i); for (int i = 1; i <= N; i++) tb[0][i] = (int)2e8; for (int k = 1; k <= K; k++) { stk.clear(); tb[k][k] = tb[k - 1][k - 1] + A[k]; stk.push_back(pii(A[k], tb[k - 1][k - 1])); for (int i = k+1; i <= N; i++) { int c = tb[k - 1][i - 1]; while (!stk.empty() && stk.rbegin()->first <= A[i]) { c = min(c, stk.rbegin()->second); stk.pop_back(); } stk.push_back(pii(A[i], c)); tb[k][i] = stk.rbegin()->first + stk.rbegin()->second; } } printf("%d\n", tb[K][N]); 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...