제출 #1331102

#제출 시각아이디문제언어결과실행 시간메모리
1331102sabishiiStove (JOI18_stove)C++20
100 / 100
13 ms1272 KiB
#include <bits/stdc++.h>

using namespace std;

int n, k, arr[100010], ans;

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    vector<int> inte;
    for(int i=1; i<=n; i++) {
        cin >> arr[i];
    }
    for(int i=1; i<n; i++) inte.push_back(arr[i+1]-arr[i]-1);
    ans = arr[n]-arr[1]+1;
    sort(inte.begin(), inte.end(), greater<int>());
    for(int i=0; i<min(k-1, (int)inte.size()); i++) {
        ans -= inte[i];
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...