This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Sopaconk 6/04/23
*/
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define deb(x) cout<<#x<<": "<<(x)<<endl
using lli=long long int;
//using pii=pair<int,int>;
using ld=long double;
lli MOD=1e9+7;
using namespace std;
#define endl '\n'
void solve(){
lli n,k;
cin>>n>>k;
vector<lli> v (n);
for(lli i=0; i<n; ++i){
cin>>v[i];
}
lli aux=n;
priority_queue<lli, vector<lli>, greater<lli>> pq;
for(lli i=1; i<n; ++i){
pq.push(v[i]-v[i-1]-1);
}
lli ans=n;
while(aux>k){
ans+=pq.top();
pq.pop();
aux--;
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |