Submission #1331097

#TimeUsernameProblemLanguageResultExecution timeMemory
1331097yumemysteryStove (JOI18_stove)C++17
100 / 100
41 ms1436 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,k;
    cin >> n >> k;

    vector<int>guest(n);
    
    for (auto &a : guest) {
        cin >> a;
    }

    priority_queue<int,vector<int>,greater<int>>pq;

    for (int i=1; i<n; i++) {
        pq.push(guest[i]-guest[i-1]-1);
    }

    int ans = n;
    while (!pq.empty() && pq.size() > k-1) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...