Submission #499329

#TimeUsernameProblemLanguageResultExecution timeMemory
499329beksultan04K blocks (IZhO14_blocks)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define int long long #define pii pair<int,int> #define ret return #define fr first #define sc second #define OK puts("OK"); #define NO puts("NO"); #define YES puts("YES"); #define all(s) s.begin(),s.end() #define allr(s) s.rbegin(),s.rend() #define nosol puts("-1"); #define pb push_back #define endi puts(""); #define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> const int N = 2e5+12,INF = 1e18+7; int q[N],dp[101][N]; main(){ int n,k,i,j; cin>>n>>k; for (i=1;i<=n;++i){ cin>>q[i]; dp[1][i] = max(q[i],dp[1][i-1]); } for (j=2;j<=k;++j){ vector <pii> v; for (i=j;i<=n;++i){ int tmp = dp[i-1][j-1]; while (!v.empty() && v.back().fr < q[i]){ tmp = max(tmp,v.back().sc); v.pop_back(); } if (v.empty() || v.back().fr + v.back().sc < tmp+q[i]){ v.pb({q[i],tmp}); } dp[j][i] = v.back().fr+v.back().sc; } } cout <<dp[k][n]; }

Compilation message (stderr)

blocks.cpp:23:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   23 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...