제출 #1115223

#제출 시각아이디문제언어결과실행 시간메모리
1115223staszic_ojuzStove (JOI18_stove)C++17
100 / 100
36 ms1144 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n,k,pop,akt;
    cin >> n >> k;
    vector<int> odl;
    cin >> pop >> akt;
    odl.push_back(akt-pop-1);
    for (int i=0; i<n-2; i++){
        pop=akt;
        cin >> akt;
        odl.push_back(akt-pop-1);
    }
    sort(odl.begin(),odl.end());
    reverse(odl.begin(),odl.end());
    //for (int i:odl) cout << i << ' ';
    k=n-k;
    int wyn=n;
    while (k-- or (odl.size() and odl[odl.size()]<0)){
        wyn+=odl[odl.size()-1];
        odl.pop_back();
    }
    cout << wyn;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...