제출 #1162252

#제출 시각아이디문제언어결과실행 시간메모리
1162252arkanefuryK개의 묶음 (IZhO14_blocks)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define lb lower_bound
#define F first
#define S second
#define sz size()
#define int long long
#define all(v) v.begin(),v.end()
#define FOR1(x, n) for(int j = x; j <= n; j ++)
#define FOR(x, n, m, d) for(int x = n; x <= m; x += d)
#define FORR(x, n, m, d) for(int x = n; x >= m; x -= d)
#define nikita ios_base::sync_with_stdio(0), cin.tie(0);
const int N =  5e5+5;
int a[N], b[N], pref[N], d[N], c[N], ans, e[N], dp[N][105];
int n,m,sum=0,x,y, r, cnt, l, mod = 998244353, inf = -1e18, k;
string s, str;
void solve(){
    cin >> n >> m;
    FOR(i,1,n,1)cin>>a[i];
    FOR(i, 1, n, 1){
        FOR(j, 1, m, 1)dp[i][j]=1e18;
    }
    x = *max_element(a+1, a+n+1);
    FOR(i, 0, n, 1)dp[i][1] = x;
    FOR(i,2,m,1){
        FOR(j, 1, n, 1){
            x = a[j];
            FORR(ok, j-1, i-2, 1){
                dp[j][i] = min(dp[j][i], dp[ok][i-1] + x);
                x = max(x, a[ok]);
            }
        }
    }
    ans = 1e18;
    FOR(i, 1, n, 1)ans = min(ans, dp[i][m]);
    cout<<ans;
}
signed main(){
    nikita
    int tt = 1;
    if(!tt)cin >> tt;
    FOR(i, 1, tt, 1){
        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...