제출 #312442

#제출 시각아이디문제언어결과실행 시간메모리
312442ryannguyen0303K개의 묶음 (IZhO14_blocks)C++14
53 / 100
4 ms4352 KiB
#include <bits/stdc++.h> using namespace std; #define file "test" #define ll long long #define X first #define Y second typedef pair <int, int> ii; const int oo = 1e9 + 7; const int mod = 1e6; const int N = 1005; int n, k; int a[N]; int f[N][N]; void enter() { cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; } void solve() { memset(f, oo, sizeof f); f[1][0] = 0; for(int i = 1; i <= n; i++) f[1][i] = max(f[1][i - 1], a[i]); for(int i = 2; i <= k; i++) { stack <ii> s; for(int j = i; j <= n; j++) { int Min = f[i - 1][j - 1]; while(!s.empty() && a[s.top().Y] <= a[j]) { Min = min(Min, s.top().X); s.pop(); } f[i][j] = min(f[i][s.empty() ? 0 : s.top().Y], Min + a[j]); s.push({Min, j}); } } cout << f[k][n]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen(file".INP", "r", stdin); // freopen(file".OUT", "w", stdout); enter(); solve(); 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...