# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471398 | xhuy8248 | K blocks (IZhO14_blocks) | C++14 | 183 ms | 40696 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>
using namespace std;
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ii pair <int, int>
#define ST first
#define ND second
#define TASK "XHUY"
const int N = 1e5 + 5;
int n, k, a[N], dP[105][N];
int main()
{
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> k;
FOR(i, 1, n)
cin >> a[i], dP[1][i] = max(dP[1][i - 1], a[i]);
FOR(i, 2, k)
{
stack <ii> st;
FOR(j, i, n)
{
int M = dP[i - 1][j - 1];
while (!st.empty() && a[st.top().ND] <= a[j])
{
M = min(M, st.top().ST);
st.pop();
}
dP[i][j] = M + a[j];
if (!st.empty())
dP[i][j] = min(dP[i][j], dP[i][st.top().ND]);
st.push({M, j});
}
}
cout << dP[k][n];
return 0;
}
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... |