| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 500824 | keta_tsimakuridze | K blocks (IZhO14_blocks) | C++14 | 296 ms | 84644 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, K = 105, inf = 1e18; // !
int t, n, k, dp[N][K], a[N];
stack<pii> st;
main(){
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i], dp[i][0] = max(a[i], dp[i - 1][0]);
st.push({dp[n][0], 0});
for(int i = 1; i < k; i++) {
while(st.size()) st.pop();
for(int j = i + 1; j <= n; j++) {
int last = inf;
while(st.size() && st.top().f <= a[j]) {
last = min(last, st.top().s);
// x1 < x2
// x1 + y1 < x2 + y2
st.pop();
}
last = min(last, dp[j - 1][i - 1]);
if(!st.size() || st.top().f + st.top().s > last + a[j]) st.push({a[j], last});
dp[j][i] = st.top().f + st.top().s;
}
}
cout << st.top().f + st.top().s;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
