Submission #1033892

#TimeUsernameProblemLanguageResultExecution timeMemory
1033892vjudge1Stove (JOI18_stove)C++17
100 / 100
15 ms2208 KiB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bip(i) __builtin_popcount(i)
#define gb(i,j) ((i>>j)&1)
#define fi first
#define se second

using namespace std;

const int N=1e5+5;
int k , n , a[N];
ll res;
int gap[N];

int main()
{
    cin.tie(0) -> sync_with_stdio(false);
    cin >> n >> k;
    for( int i=1 ; i<=n ; i++ ){
        cin >> a[i];
        if(i>1)
        gap[i] = a[i]-a[i-1]-1; // gap cua i va cai trc
//        gap[i].se.fi = a[i-1]+1;
//        gap[i].se.se = a[i];
        res+=1;
    }
    sort(gap+2 , gap+1+n);
//    for( int i=1 ; i<=n ; i++ )cout << i << " " << gap[i].fi << endl;
    if(k<n){
        k=n-k;
        for( int i=1 ; i<=k ; i++ ){
            res+=gap[i+1];
        }
    }
    cout << res;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...