이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1e5 + 15;
int n, k, dp[N], mn[N];
int a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
auto solve = [&] () {
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i];
dp[i] = max(dp[i - 1], a[i]);
}
for(int j = 2; j <= k; j++) {
stack<int> s;
for(int i = j; i <= n; i++) {
mn[i] = dp[i - 1];
}
for(int i = j; i <= n; i++) {
while(!s.empty() && a[s.top()] <= a[i]) {
mn[i] = min(mn[i], mn[s.top()]);
s.pop();
}
dp[i] = a[i] + mn[i];
if(!s.empty()) {
dp[i] = min(dp[i], dp[s.top()]);
}
s.push(i);
}
}
cout << dp[n];
};
int t = 1;
//cin >> t;
while(t--) {
solve();
}
return 0;
}
# | 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... |