제출 #1144127

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    int a, total =1;

    vector<int> v;

    for(int i=1; i<=n;i++){
        int b;
        cin >> b;
        if(i>1){
            v.push_back(b-a-1);
            total += b-a;
        }
        a=b;
    }
    sort(v.rbegin(),v.rend());
    for(int i=0;i<k-1;i++){
        total -= v[i];
    }
    cout << total << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...