Submission #1331137

#TimeUsernameProblemLanguageResultExecution timeMemory
1331137_apknxnStove (JOI18_stove)C++20
100 / 100
64 ms1544 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> t;
priority_queue<ll> b;
int main()
{
    ll n, k, tt = 0, st = 0, ed = 0, f, a;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (ed == 0)
        {
            ed = a;
            f = a;
        }
        if (a != ed)
            b.push(a - ed - 1);
        ed = a;
    }
    st = ed - f + 1;

    for (int i = 1; i < k; i++)
    {
        st -= b.top();
        b.pop();
    }

    cout << st << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...