제출 #443168

#제출 시각아이디문제언어결과실행 시간메모리
443168flashhhStove (JOI18_stove)C++14
100 / 100
32 ms2276 KiB
#include <bits/stdc++.h>
#define nmax 100010
#define ll long long 

using namespace std;

int n,k,a[nmax];
ll res;
priority_queue<int,vector<int>,greater<int> > pq;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin>>n>>k;
    for (int i=1;i<=n;++i)
    {
        cin>>a[i];
        if (i>1) pq.push(a[i]-a[i-1]-1);
    }

    res=n; k=n-k;
    while (k>0)
    {
        res+=pq.top(); pq.pop();
        --k;
    }
    
    cout<<res;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...