제출 #1033948

#제출 시각아이디문제언어결과실행 시간메모리
1033948vjudge1Stove (JOI18_stove)C++17
100 / 100
15 ms2988 KiB
#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int MAXN = 1e5 + 5;

ll n,k,res;
ll a[MAXN],pre[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>k;
    for(int i = 1;i<=n;i++) cin>>a[i];
    for(int i = 2;i<=n;i++){
        pre[i] = a[i] - a[i-1];
    }
    sort(pre+2,pre+n+1);
    if(k == n){
        res = n;
    }
    else{
        for(int i = 1;i<=n-k;i++){
            res += pre[i+1];
        }
        res += k;
    }
    cout<<res;

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