Submission #734760

#TimeUsernameProblemLanguageResultExecution timeMemory
734760rahidilbayramliStove (JOI18_stove)C++17
100 / 100
50 ms2632 KiB
#include<bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define sl set<ll>
#define all(v) v.begin(), v.end()
#define pb push_back
#define s second
#define f first
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
int main()
{
    ll n, k, i, s;
    cin >> n >> k;
    vl v(n);
    for(ll&h : v)    cin >> h;
    priority_queue<int>pq;
    for(i = 1; i < n; i++)    pq.push(v[i]-v[i-1]-1);
    s = v[n-1] - v[0] + 1;
    for(i = 0; i < k - 1; i++)
    {
        auto p = pq.top();
        pq.pop();
        s -= p;
    }
    cout << s << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...