Submission #648185

#TimeUsernameProblemLanguageResultExecution timeMemory
648185anteteStove (JOI18_stove)C++14
100 / 100
62 ms1312 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define wii(x) cout << #x << " = " << x << endl;

typedef long long ll;
using namespace std;

priority_queue<int> q;

int main()
{
    int n, k;
    cin >> n >> k;
    int t[n];
    for(int i = 0; i < n; i++)
    {
        cin >> t[i];
    }
    sort(t, t + n);
    int c = t[n - 1] - t[0] + 1;
    for(int i = 0; i < n - 1; i++)
    {
        q.push(t[i + 1] - t[i] - 1);
    }
    for(int i = 0; i < k - 1; i++)
    {
        c -= q.top();
        q.pop();
    }
    cout << c;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...