#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
const int nmax=100005;
long long v[nmax],dp[2][nmax],mn[nmax];
int st[nmax];
int n,k,i,j,use,u;
int main()
{
//freopen("data.in","r",stdin);
ios_base::sync_with_stdio(false);
cin>>n>>k;
for(i=1;i<=n;i++)
{
cin>>v[i];
}
for(i=0;i<=n;i++)
dp[0][i]=1LL*1e15,dp[1][i]=1LL*1e15;
mn[0]=1LL*1e15;dp[0][0]=0;
for(int cnt=1;cnt<=k;cnt++)
{
use=1-use;u=0;
for(i=1;i<=n;i++)
{
while(u>0&&v[i]>=v[st[u]])
u--;
st[++u]=v[i];
mn[u]=min(mn[u-1],dp[1-use][st[u-1]]+v[i]);
if(i>=cnt&&u==1)
mn[u]=min(dp[1-use][cnt-1]+v[i],mn[u]);
dp[use][i]=mn[u];
}
for(i=0;i<=n;i++)
dp[1-use][i]=1LL*1e15;
}
cout<<dp[use][n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Runtime error |
3 ms |
768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Runtime error |
3 ms |
800 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
824 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |