이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
const int mod=998244353, maxn=1e5+5;
int n, k, a[maxn], mindp, val, dp[105][maxn];
stack<pii> s;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> k;
for(int i=1; i<=n; i++) cin >> a[i];
for(int kel=1; kel<=k; kel++) {
for(int i=kel; i<=n; i++) {
mindp=dp[kel-1][i-1];
while(!s.empty()&&a[s.top().fi]<=a[i]) {
mindp=min(mindp, s.top().se);
s.pop();
}
val=1e9;
if(!s.empty()) val=dp[kel][s.top().fi];
dp[kel][i]=min(val, mindp+a[i]);
s.push({i, mindp});
}
while(!s.empty()) s.pop();
}
cout << dp[k][n] << '\n';
}
| # | 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... |