Submission #393353

# Submission time Handle Problem Language Result Execution time Memory
393353 2021-04-23T09:46:44 Z vanic K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 332 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

const int maxk=105, maxn=1e5+5;
const int inf=1e9;

vector < pair < int, int > > v[maxk]; 
int dp[maxn][maxk];
int a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	int sum=0;
	for(int i=0; i<k; i++){
		v[i].push_back({sum, a[i]});
		sum+=a[i];
		dp[i][i]=sum;
	}
	int mindp;
	int val;
	for(int i=0; i<n; i++){
		for(int j=0; j<min(k, i); j++){
			mindp=dp[i-1][j-1];
			val=a[i];
			while(v[j].back().second<=val){
				mindp=min(mindp, v[j].back().first);
				v[j].pop_back();
			}
			dp[i][j]=val+mindp;
			v[j].push_back({mindp, val});
		}
	}
	cout << dp[n-1][k-1] << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -