Submission #1175938

#TimeUsernameProblemLanguageResultExecution timeMemory
1175938tawwieStove (JOI18_stove)C++20
100 / 100
12 ms968 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    cin.tie(NULL)->ios_base::sync_with_stdio(false);
    int n, k, prev = -1, now, total;
    cin >> n >> k;
    vector<int> interval;
    for(int i=0; i<n; i++){
        if(prev == -1){
            cin >> prev;
            total = prev;
        }else{
            cin >> now;
            interval.push_back(now-prev-1);
            prev = now;
        }
        if(i == n - 1){
            total = prev - total + 1;
        }
    }
    sort(interval.begin(), interval.end(), greater<int>());
    for(int i=0; i<k-1; i++){
        total -= interval[i];
    }
    cout << total;
    
    return 0;
}
/*
10 5
1 2 5 6 8 11 13 15 16 20
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...