Submission #336606

#TimeUsernameProblemLanguageResultExecution timeMemory
336606jovan_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 ll dp[2][100005]; ll a[100005]; ll pre[100005]; const ll INF = 1000000000000000LL; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; ll n, k; cin >> n >> k; for(ll i=1; i<=n; i++) cin >> a[i]; for(ll i=1; i<=n; i++){ dp[0][i] = max(dp[0][i-1], a[i]); pre[i] = pre[i-1] + a[i]; } for(ll g=2; g<=k; g++){ deque <pair <pair <ll, ll>, pair <ll, ll>>> q; for(ll i=0; i<g; i++){ dp[1][i] = INF; } //dp[1][g] = pre[g]; for(ll i=g; i<=n; i++){ ll 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(ll 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...