# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547310 | krit3379 | K blocks (IZhO14_blocks) | C++17 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int a[N],l[N],dp[105][N];
int main(){
int n,k,i,j;
scanf("%d %d",&n,&k);
a[0]=2e9;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
l[i]=i-1;
while(a[i]>a[l[i]])l[i]=l[l[i]];
}
for(i=0;i<=k;i++)for(j=0;j<=n;j++)dp[i][j]=1e9;
for(i=1;i<=n;i++){
if(l[i]==0)dp[1][i]=a[i];
dp[1][i]=min(dp[1][i],dp[1][l[i]]);
}
for(i=2;i<=k;i++){
for(j=i;j<=n;j++){
dp[i][j]=min({dp[i][j],dp[i][l[j]],dp[i-1][l[j]+1]+a[j],dp[i-1][j-1]+a[j]});
}
}
printf("%d",dp[k][n]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |