# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47045 | wzy | K blocks (IZhO14_blocks) | C++11 | 455 ms | 122864 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 n , k , dp[100005][105] , v[100005] , opt[100005][105] , pointer[105];
stack< pair<int,int> > s[105];
int main(){
scanf("%d%d" , &n , &k);
for(int i = 1 ; i<=n ;i ++) scanf("%d" , &v[i]);
for(int i = 0 ; i <= n; i ++)
for(int j = 0 ; j <= k ; j++) opt[i][j] = 1000000009 , pointer[j] = 0 , dp[i][j] = 0;
for(int j = 1 ; j <= k ; j++)
for(int i = j ; i <= n; i++){
if(j == 1){
dp[i][j] = max(dp[i-1][j] , v[i]);
}
else{
int currminimal = dp[i-1][j-1];
while(s[j].size() && s[j].top().second <= v[i]){
currminimal = min(currminimal , s[j].top().first);
s[j].pop();
pointer[j]--;
}
dp[i][j] = min(currminimal + v[i] , opt[pointer[j]][j]);
s[j].push(pair<int,int>(currminimal, v[i]));
opt[pointer[j] + 1][j] = min(opt[pointer[j]][j] , currminimal + v[i]);
pointer[j]++;
}
}
printf("%d\n" , 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... |