# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40519 | Pajaraja | K blocks (IZhO14_blocks) | C++14 | 231 ms | 13980 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;
int a[100007],dp[100007],dpl[100007],minn[100007];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
a[0]=1000001;
for(int i=1;i<=n;i++) dpl[i]=1000000000;
stack<int> st;
for(int z=1;z<=k;z++)
{
while(!st.empty()) st.pop();
st.push(0);
dp[0]=1000000000;
for(int i=1;i<=n;i++)
{
minn[i]=1000000000;
while(a[st.top()]<=a[i])
{
minn[i]=min(min(minn[i],dpl[st.top()]),minn[st.top()]);
st.pop();
}
minn[i]=fmin(minn[i],dpl[st.top()]);
dp[i]=min(dp[st.top()],minn[i]+a[i]);
st.push(i);
}
for(int i=0;i<=n;i++) dpl[i]=dp[i];
}
printf("%d",dp[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... |