제출 #765869

#제출 시각아이디문제언어결과실행 시간메모리
765869Owen11Stove (JOI18_stove)C++14
100 / 100
20 ms3160 KiB
#include <bits/stdc++.h>
using namespace std;

# define int long long
# define fir first
# define sec second
# define pb push_back

const int cnst = 2e5+5;
bool mutipletestcase = 0;
//bool debug = false;

void solve() {
    int n, k; cin >> n >> k;

    int num[n+5];
    int ans = n;
    
    priority_queue<int, vector<int>, greater<int>> pq;

    for(int i = 1; i<=n; i++) {
        cin >> num[i];
        if(i != 1) pq.push(num[i]-num[i-1]-1);
    }

    int need = n-k;

    while(need--) {
        ans += pq.top();
        pq.pop();
    }

    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t = 1;
    if(mutipletestcase) cin >> t; 
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...