Submission #1033662

#TimeUsernameProblemLanguageResultExecution timeMemory
1033662vjudge1Stove (JOI18_stove)C++17
100 / 100
22 ms1504 KiB
#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define ins insert
#define pf push_front
#define bit(n,k) ((n>>k)&1) 
#define pi acos(-1.0)
const ll N=2e5+5, inf = 1e9, mod=1e9+7;
using namespace std;
bool cmp(ii a, ii b){
    return a>b;
}
int main(){
    // freopen("TRAVEL.INP", "r", stdin);
    // freopen("TRAVEL.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);  
    ii n,k; cin >> n >> k;
    ii a[n+1];
    vector<ii>v;
    for(ii i=1;i<=n;i++) cin >> a[i];
    for(ii i=2;i<=n;i++) v.pb(a[i]-a[i-1]-1);
    sort(v.begin(),v.end(),cmp);
    ii ans=a[n]-a[1]+1;
    for(ii i=0;i<k-1;i++) ans-=v[i];
    cout << ans << endl; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...