제출 #1332794

#제출 시각아이디문제언어결과실행 시간메모리
1332794Zone_zoneeStove (JOI18_stove)C++20
100 / 100
21 ms1224 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;

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