Submission #216925

#TimeUsernameProblemLanguageResultExecution timeMemory
216925someone_aaK blocks (IZhO14_blocks)C++17
0 / 100
5 ms640 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 110;
int n, k;
int dp[maxn][maxn];
int a[maxn];

int main() {
	cin>>n>>k;
	int prefmax = 0;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		prefmax = max(prefmax, a[i]);
		dp[i][1] = prefmax;
	}

	for(int d=2;d<=k;d++) {
		bool check = false;
		for(int i=d;i<=n;i++) {
			dp[i][d] = INT_MAX;
			int prefmax = 0;
			for(int p=i;p>=d;p--) {
				prefmax = max(prefmax, a[p]);
				dp[i][d] = min(dp[i][d], dp[p-1][d-1] + prefmax);
			}

			if(dp[i][d] < dp[i-1][d]) check = true;
		}

		if(check) cout<<(1/0);
	}

	cout<<dp[n][k]<<"\n";
}

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:33:21: warning: division by zero [-Wdiv-by-zero]
   if(check) cout<<(1/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...