이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main(){
| ^~~~
# | 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... |