Submission #1115210

#TimeUsernameProblemLanguageResultExecution timeMemory
1115210staszic_ojuzStove (JOI18_stove)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k, a;
    cin >> n >> k;

    vector<int> czasy;

    for (int i=0; i<n; i++){
        cin >> a;
        czasy.push_back(a);
    }

    sort(czasy.begin(), czasy.end());

    vector<int> przerwy;

    int poprzedni=czasy[0];

    for (int i=1; i<(int)czasy.size(); i++){
        //cout << i << " " << czasy[i] << endl;
        przerwy.push_back(czasy[i]-poprzedni-1);
        poprzedni = czasy[i];
    }

    sort(przerwy.begin(), przerwy.end());
    reverse(przerwy.begin(), przerwy.end());

    int wyn=0;

    for (int i=0; i<n-k; i++){
        //cout << i << " prz" << przerwy[i] << endl;
        wyn+=przerwy[i];
    }

    cout << (czasy[n-1]-czasy[0]+1)-wyn << "\n";

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