제출 #1134092

#제출 시각아이디문제언어결과실행 시간메모리
1134092tuongllK개의 묶음 (IZhO14_blocks)C++20
53 / 100
1093 ms8516 KiB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <ctime>
#include <cassert>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <bitset>
#include <array>
using ll = long long;
#define debug(x) cout << #x << " = " << x << '\n'
#define separator "===============================================\n"
#define all(a) a.begin(), a.end()
#define SZ(a) (int)(a).size()
using namespace std;
const int mxn = 1e5 + 3;
const ll  mod = 1e9 + 7;
const int inf32 = 2e9;
const ll  inf64 = 3e18;
int n, k, a[mxn];
ll dp[mxn][103];
void solve(){
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 0; i <= n; ++i) for (int j = 0; j <= k; ++j)
        dp[i][j] = inf64;
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= min(i, k); ++j){
            int mx = 0;
            for (int u = i; u >= 1; --u){
                mx = max(mx, a[u]);
                if (dp[u - 1][j - 1] != inf64)
                    dp[i][j] = min(dp[i][j], mx + dp[u - 1][j - 1]);
            }
        }
    }
    cout << dp[n][k];
}
int main(){
	auto start = chrono::steady_clock::now();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    chrono::duration<double> elapsed {chrono::steady_clock::now() - start};
    cerr << "\n>> Runtime: " << elapsed.count() << "s\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...