제출 #1147747

#제출 시각아이디문제언어결과실행 시간메모리
1147747arjunphanseStove (JOI18_stove)C++17
100 / 100
29 ms788 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define dbg(x) cerr << #x << ": " << (x) << endl;

int diff[100000];

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    int last = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans++;
        if(i == 0) {
            last = x;
            continue;
        }
        diff[i-1] = x - last;
        last = x;
    }
    sort(diff, diff+n-1);
    for (int i = 0; i < n - k; i++) {
        ans += diff[i] - 1;
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...