This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool compare (const unsigned &a, const unsigned &b)
{
    return a>b;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    size_t n{}, k{};
    cin >> n >> k;
    size_t availabeMatches {k-1};
    vector<unsigned> guestsTimes(n);
    for(size_t i{}; i<n; i++)
        cin >> guestsTimes[i];
    
    vector<unsigned> timeDifferences;
    unsigned timeDifference;
    for (size_t i{}; i<n-1; i++)
    {
        timeDifference = guestsTimes[i+1]-guestsTimes[i];
        if (timeDifference!=1)
            timeDifferences.push_back(timeDifference-1);
    }
    sort(timeDifferences.begin(), timeDifferences.end(), compare);
    size_t burnedTime{n};
    for(size_t i{availabeMatches}; i<timeDifferences.size(); i++)
        burnedTime+=timeDifferences[i];
    cout << burnedTime << '\n';
    
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |