# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
581265 | yutabi | K blocks (IZhO14_blocks) | C++14 | 1 ms | 468 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;
typedef long long ll;
int n;
int k;
ll nums[100007];
ll ans[11][100007];
int main()
{
scanf("%d %d",&n,&k);
for(int i=0;i<n;i++)
{
scanf(" %d",&nums[i]);
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<=k;j++)
{
ans[j][i]=-1;
}
}
ans[0][0]=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<k;j++)
{
ll mini=-1;
ll maxi=0;
for(int l=i;l>=0;l--)
{
maxi=max(maxi,nums[l]);
if(ans[j][l]!=-1 && (mini==-1 || ans[j][l]+maxi<mini))
{
mini=ans[j][l]+maxi;
}
}
ans[j+1][i+1]=mini;
}
}
/*for(int i=0;i<=k;i++)
{
for(int j=0;j<=n;j++)
{
printf("%lld ",ans[i][j]);
}
printf("\n");
}*/
printf("%lld\n",ans[k][n]);
}
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... |