Submission #1116971

#TimeUsernameProblemLanguageResultExecution timeMemory
1116971whoknowK blocks (IZhO14_blocks)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define MAXN 100005 #define ii pair<int,int> #define bit(i,j) ((i>>j)&1) #define sz(i) (int)i.size() #define endl '\n' using namespace std; int n, K; int a[MAXN]; namespace sub1 { ll dp[2][MAXN]; void solve() { int mi = 1e9; for(int i = 1; i <= n; i++) { mi = min(mi, a[i]); dp[0][i] = mi; } for(int j = 2; j <= K; j++) { stack<ii>st; for(int i = 1; i <= n; i++) { while(sz(st) && st.top().S < a[i]) st.pop(); if(sz(st) == 0 || dp[0][i] + a[i] <= st.top().F + st.top().S) st.push({dp[0][i], a[i]}); if(i > j) dp[1][i] = st.top().F + st.top().S; } for(int i = 1; i <= n; i++) dp[0][i] = dp[1][i]; } cout<<dp[0][n]; } } main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> K; for(int i = 1; i <= n; i++) cin >> a[i]; sub1::solve(); }

Compilation message (stderr)

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