Submission #499262

#TimeUsernameProblemLanguageResultExecution timeMemory
499262AktanK blocks (IZhO14_blocks)C++17
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ft first #define sc second using namespace std; const long long mod=1e9+7,INF=1e17; int a[1000005],dp[105][1000005]; main(){ int n,k,mx=0; cin >> n >> k; for(int i=1;i<=n;i++){ cin >> a[i]; } for(int i=1;i<=n;i++){ mx=max(mx,a[i]); dp[1][i]=mx; } for(int i=2;i<=k;i++){ vector<pair<int,int>> v; for(int j=i;j<=n;j++){ int tmp=dp[i-1][j-1]; while(!v.empty() && v.back().ft<a[j]){ tmp=max(tmp,v.back().sc); v.pop_back(); } if(v.empty()|| v.back().ft+v.back().sc>(tmp+a[j])){ v.push_back({a[i],tmp}); } dp[i][j]=v.back().ft+v.back().sc; } } cout << dp[k][n]; }

Compilation message (stderr)

blocks.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | 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...