제출 #1083582

#제출 시각아이디문제언어결과실행 시간메모리
1083582f0rizenK blocks (IZhO14_blocks)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll infll = 1e18; template<typename T> istream &operator>>(istream &is, vector<T> &a) { for (auto &i : a) { is >> i; } return is; } int32_t main() { #ifdef LOCAL freopen("/tmp/input.txt", "r", stdin); #else ios::sync_with_stdio(false); cin.tie(nullptr); #endif int n, k; cin >> n >> k; vector<int> a(n); cin >> a; vector<vector<ll>> dp(k + 1, vector<ll>(n + 1, infll)); dp[0][0] = 0; for (int j = 1; j <= k; ++j) { vector<pair<int, ll>> st; vector<ll> pref; pref.push_back(infll); for (int i = 1; i <= n; ++i) { ll mn = dp[j - 1][i - 1]; while (!st.empty() && a[st.back().first] <= a[i - 1]) { mn = min(mn, st.back().second); st.pop_back(); } st.push_back({i - 1, mn}); pref.push_back(min(pref.back(), mn + a[i - 1])); dp[j][i] = pref.back(); } } cout << dp[k][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...