제출 #1291171

#제출 시각아이디문제언어결과실행 시간메모리
1291171Miquella_Stove (JOI18_stove)C++20
50 / 100
148 ms82544 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pi pair<int, int>
#define FOR(i,a,b) for(int i = a; i <= b; i ++)
#define REP(i,a,b) for(int i = a; i >= b; i --)
#define el "\n"
#define bit(mask,i) ((mask >> i) & 1)
#define all(x) (x).begin(),(x).end()
#define int long long
#define NAME ""
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 5e3 + 5;

void maximize (int &x, int y) {
    x = max (x, y);
}

void minimize (int &x, int y) {
    x = min (x, y);
}

//-------------------

int n, k, a[MAXN], dp[MAXN][MAXN];

void solve () {
    cin >> n >> k;
    FOR (i, 1, n) cin >> a[i];

    sort (a + 1, a + 1 + n);

    FOR (i, 1, n) FOR (j, 0, k) dp[i][j] = INF;

    a[0] = a[1] - 1;
    FOR (i, 1, n) {
        FOR (j, 1, k) {
            dp[i][j] = dp[i - 1][j] + a[i] - a[i - 1];
            minimize (dp[i][j], dp[i - 1][j - 1] + 1);

//            cout << i << " " << j << " " << dp[i][j] << el;
        }
    }


    cout << dp[n][k];
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie (0);
//    freopen (NAME".INP", "r", stdin);
//    freopen (NAME".OUT", "w", stdout);

    solve ();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...