제출 #1236003

#제출 시각아이디문제언어결과실행 시간메모리
1236003lanaskaricaK개의 묶음 (IZhO14_blocks)C++20
53 / 100
1093 ms1860 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair <int, int> #define fi first #define se second const int MAXN = 1e5 + 5, MAXK = 110, MAX = 1e9; int arr[MAXN], dp[MAXK][MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; for (int i = 0; i <= k; i++) { for (int j = 0; j <= n; j++) dp[i][j] = MAX; } dp[0][0] = 0; for (int i = 1; i <= n; i++) { cin >> arr[i]; dp[0][i] = max(dp[0][i - 1], arr[i]); } for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { int mx = arr[j]; for (int z = j - 1; z >= 1; z--) { dp[i][j] = min(dp[i][j], dp[i - 1][z] + mx); mx = max(mx, arr[z]); } } } //for (int i = 0; i <= k; i++) { //for (int j = 0; j <= n; j++) cout << dp[i][j] << " "; //cout << "\n"; //} cout << dp[k - 1][n] << "\n"; 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...