Submission #1236347

#TimeUsernameProblemLanguageResultExecution timeMemory
1236347nasjesStove (JOI18_stove)C++20
100 / 100
31 ms2240 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 5*1e6+7;
//const ll mod = 1e9 + 7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>

ll n, m;
ll a[dim];
int main() {
    ll k;
    cin>>n>>k;
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    ll dx=n-k;
    sort(a+1, a+1+n);
    vll dist;
    for(int i=2; i<=n; i++){
        dist.pb({a[i]-a[i-1]-1});
    }
    sort(dist.begin(), dist.end());
    ll ans=n;
    for(auto x: dist){
        if(dx==0)break;
        ans+=x;
        dx--;
    }
    cout<<ans<<endl;




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