Submission #336605

#TimeUsernameProblemLanguageResultExecution timeMemory
336605jovan_bK blocks (IZhO14_blocks)C++17
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back int dp[2][100005]; int a[100005]; int pre[100005]; const int INF = 1000000000; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, k; cin >> n >> k; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=n; i++){ dp[0][i] = max(dp[0][i-1], a[i]); pre[i] = pre[i-1] + a[i]; } for(int g=2; g<=k; g++){ deque <pair <pair <int, int>, pair <int, int>>> q; for(int i=0; i<g; i++){ dp[1][i] = INF; } //dp[1][g] = pre[g]; for(int i=g; i<=n; i++){ int mnl = i-1; while(!q.empty() && q.back().second.first <= a[i]){ mnl = min(mnl, q.back().first.first); q.pop_back(); } //cout << i << " " << mnl << endl; dp[1][i] = dp[0][mnl] + a[i]; if(!q.empty()) dp[1][i] = min(dp[1][i], q.back().second.second); q.push_back({{mnl, i-1}, {a[i], dp[1][i]}}); } for(int i=0; i<=n; i++) dp[0][i] = min(INF, dp[1][i]); } cout << dp[0][n] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...