제출 #397035

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

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

const int N = 1e5;
int n, k;
int t[N+2];

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