Submission #1312754

#TimeUsernameProblemLanguageResultExecution timeMemory
1312754yeulerStove (JOI18_stove)C++20
100 / 100
22 ms2360 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define banyak int tc = 1; cin >> tc; while(tc--){solve();}
#define vector2d(x) vector<vector<x>>
#define pii pair<int, int>
#define pl pair<ll, ll>
#define kagamine_len ios_base::sync_with_stdio(0); cin.tie(0);
#define file_in freopen("input.txt", "r", stdin);
#define file_out freopen("output.txt", "w", stdout);
#define all(x) x.begin(), x.end()

using namespace std;

int main(){
    kagamine_len

    ll n, k; cin >> n >> k;
    vector<ll> ar(n+2, 0);
    priority_queue<ll> pq;
    for (ll i = 1; i <= n; i++) cin >> ar[i];
    ar[n+1] = 1e9+69;
    sort(all(ar));
    ll tot = ar[n] - ar[1] + 1, ans = tot;
    for (ll i = 2; i <= n; i++){
        pq.push(ar[i]-ar[i-1]);
    }
    k--;
    while(!pq.empty() && k--){
        ll cur = pq.top();
        pq.pop();
        // cout << cur << "\n";
        tot = tot - cur + 1;
        ans = min(ans, tot);
    }

    cout << ans << "\n";

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