# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1077149 | duyhoanho | K blocks (IZhO14_blocks) | C++14 | 1089 ms | 80340 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>
#define task ""
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1e5+10;
int n,a[N],dp[N][102],k;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen ("blocks.in", "r"))
{
freopen ("blocks.in", "r", stdin);
freopen ("blocks.out", "w", stdout);
}
cin>>n>>k;
memset(dp,99,sizeof dp);
int mx=0;
forinc(i,1,n)
{
cin>>a[i];
mx=max(mx,a[i]);
dp[i][1] = mx;
dp[i][0]=0;
}
dp[0][0]=0;
for(int i=2;i<=n;i++)
{
for(int j=2;j<=k;j++)
{
int mx=a[i];
for(int tt=i-1;tt>=1;tt--)
{
dp[i][j] = min(dp[i][j],dp[tt][j-1] + mx);
mx=max(mx,a[tt]);
}
}
}
// forinc(i,1,n)
// {
// forinc(j,1,k) cout<<dp[i][j]<<" ";
// cout<<"\n";
// }
cout<<dp[n][k];
}
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... |