이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define type(x) __typeof((x).begin())
#define foreach(i, x) for(type(x) i = (x).begin(); i != (x).end(); i++)
typedef long long ll;
typedef pair < int, int > ii;
const int inf = 1e9 + 333;
const ll linf = 1e18 + 333;
const int N = 1e5 + 5;
const int K = 100 + 5;
int n, k, a[N], dp[N][K];
ii p[N];
int main () {
ios :: sync_with_stdio(0);
cin >> n >> k;
int mx = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
dp[i][1] = mx;
}
for(int j = 2; j <= k; j++) {
int sz = 0;
for(int i = 1; i <= n; i++) {
int ans = j <= i ? dp[i - 1][j - 1] : inf;
while(sz and a[i] >= p[sz - 1].first)
ans = min(ans, p[--sz].second);
if(!sz or a[i] + ans < p[sz - 1].first + p[sz - 1].second)
p[sz++] = ii(a[i], ans);
dp[i][j] = p[sz - 1].first + p[sz - 1].second;
}
}
cout << dp[n][k] << endl;
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... |