Submission #90667

#TimeUsernameProblemLanguageResultExecution timeMemory
90667P1QGK blocks (IZhO14_blocks)C++11
0 / 100
9 ms4728 KiB
#include<bits/stdc++.h> #define maxn 100005 using namespace std; int n, k, a[maxn], F[maxn][105]; int main() { //freopen("BLOCKS.inp","r",stdin); //freopen("BLOCKS.out","w",stdout); scanf("%d%d", &n, &k); for(int i=1;i<=n;i++) { scanf("%d", &a[i]); } for(int i=0;i<=n;i++) { for(int j=0;j<=k;j++) F[i][j] = 1e9+9; } F[0][1] = 0; for(int i=1;i<=n;i++) F[i][1] = max(F[i-1][1], a[i]); for(int i=2;i<=k;i++) { stack< pair<int,int> > P; for(int j=i;j<=n;j++) { int cur = F[j-1][i-1]; while(P.size() && a[P.top().second] <= a[j]) { cur = min(cur, P.top().first); P.pop(); } F[j][i] = min(cur + a[j], (P.size() == 0)?F[0][0]:F[P.top().second][i]); P.push( make_pair(cur, i)); } } printf("%d", F[n][k]); }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...