제출 #1331104

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

#define ll long long

const int nx = 1e5+5;

int n, k;
ll ans = 0;
ll t[nx];
priority_queue<ll, vector<ll>, greater<ll>> pq;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> t[i];
    for (int i = 1; i + 1 <= n; i++) pq.push(t[i+1] - t[i] - 1);
    ans = n;
    while (n > k) {
        ans += pq.top();
        n--;
        pq.pop();
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...