제출 #1310740

#제출 시각아이디문제언어결과실행 시간메모리
1310740somefolkStove (JOI18_stove)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vector<int> diff;
    for(int i = 1; i < n; i++){
        diff.push_back(a[i] - a[i-1] + 1);
    }
    sort(diff.begin(), diff.end());

    int sol = 0;
    for(int i = 0; i < k-1; i++){
        sol += diff[i];
    }

    cout << sol+1 << endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...