제출 #875639

#제출 시각아이디문제언어결과실행 시간메모리
875639Beerus13Stove (JOI18_stove)C++14
100 / 100
16 ms1304 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int ar = 1e5 + 5;

int n, k, a[ar];
vector<int> res;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        if(i > 1) res.push_back(a[i] - a[i - 1]);
    }
    sort(res.begin(), res.end());
    int ans = n;
    for(int i = 0; i < n - k; ++i) ans += res[i] - 1;
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...