Submission #13514

# Submission time Handle Problem Language Result Execution time Memory
13514 2015-02-22T14:01:21 Z tncks0121 K blocks (IZhO14_blocks) C++14
0 / 100
0 ms 42824 KB
#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 time Memory Grader output
1 Correct 0 ms 42824 KB Output is correct
2 Incorrect 0 ms 42824 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -