제출 #497051

#제출 시각아이디문제언어결과실행 시간메모리
497051shmadK개의 묶음 (IZhO14_blocks)C++17
53 / 100
2 ms1232 KiB
#include <bits/stdc++.h>
 
#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;
 
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 20);
const double eps = 1e-6;
 
int n, k, dp[200][200];

void solve () {
	cin >> n >> k;
	vt<int> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i], fill(dp[i], dp[i] + 200, inf);
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int block = 1; block <= k; block++) {
			int mx = 0;
			for (int j = i; j >= 1 && j >= block; j--) {
				mx = max(mx, a[j]);
				dp[i][block] = min(dp[i][block], dp[j - 1][block - 1] + mx);
			}
		}
	}
	cout << dp[n][k];
	cout << '\n';
}
 
bool testcases = 0;
 
signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int test = 1;
    if (testcases) cin >> test;
    for (int cs = 1; cs <= test; cs++) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...