# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101502 | 2024-10-16T09:14:39 Z | MThanCCVA | K blocks (IZhO14_blocks) | C++14 | 2 ms | 4492 KB |
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; const int MAXN = 1e4 + 5; int n, k; int dp[MAXN][105], a[MAXN]; int main() { freopen("blocks.inp", "r", stdin); freopen("blocks.out", "w", stdout); cin >> n >> k; memset(dp, 0x3f, sizeof(dp)); int mx = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); dp[i][1] = mx; } for (int j = 2; j <= k; j++) { stack<pii> s; for (int i = 1; i <= n; i++) { int tmp = dp[i - 1][j - 1]; while (!s.empty() && s.top().first < a[i]) { tmp = min(tmp, s.top().second); s.pop(); } if (s.empty() || a[i] + tmp < s.top().first + s.top().second) s.push({a[i], tmp}); if (i >= j) dp[i][j] = s.top().first + s.top().second; } } cout << dp[n][k]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4432 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |