제출 #14804

#제출 시각아이디문제언어결과실행 시간메모리
14804erdemkirazK blocks (IZhO14_blocks)C++98
100 / 100
195 ms43904 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...