# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395420 | 2021-04-28T10:39:56 Z | __algebra__ | K blocks (IZhO14_blocks) | C++14 | 1 ms | 208 KB |
#include<bits/stdc++.h> using namespace std; int dp[100001][101],arr[100001]; int main(){ int n,k; scanf("%d%d",&n,&k); for(int i=0;i<=k;++i)for(int j=0;j<=n;++j)dp[j][i]=1e9; dp[0][1]=0; for(int i=1;i<=n;i++)scanf("%d",&arr[i]),dp[i][1]=max(dp[i-1][1],arr[i]); for(int j=2;j<=k;++j){ stack<pair<int,int>>stk; for(int i=j;i<=n;++i){ int dpi=dp[i-1][j-1] , ai = arr[i]; while(!stk.empty() && stk.top().second <= ai)dpi=min(dpi,stk.top().first),stk.pop(); if(stk.empty() || stk.top().first+stk.top().second > ai+dpi) stk.push({dpi,ai}); dp[i][k]=stk.top().first+stk.top().second; } } printf("%d\n",dp[n][k]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 208 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Incorrect | 1 ms | 204 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Incorrect | 1 ms | 204 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 208 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Incorrect | 1 ms | 204 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 208 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Incorrect | 1 ms | 204 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |