Submission #1269164

#TimeUsernameProblemLanguageResultExecution timeMemory
1269164picradStove (JOI18_stove)C++20
100 / 100
14 ms1992 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef double dbl;
typedef pair<ll,ll> pii;

const int maxn = 1e5+5;
ll N,K,T[maxn],ans;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> N >> K;
    vector<ll> pq;
    for(int i =1; i <= N; i++){
        cin >> T[i];
        if(i > 1)pq.pb(T[i]-T[i-1]-1);
    }
    ans = T[N] - T[1] + 1;
    //cout << ans << '\n';
    sort(pq.begin(),pq.end());
    K--;
    while(K-- && !pq.empty()){
        ll cur = pq.back();
        pq.pop_back();
        ans -= cur;
    }
    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...