This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ID: NAMIN
TASK:
LANG: C++
*/
#include <iostream>
#include <numeric>
#include <math.h>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <fstream>
#include <map>
#include <unordered_map>
#include <iomanip>
#define gcd __gcd
#define endl "\n"
#define ll long long
using namespace std;
void solve(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin >> n >> k;
vector<int> visit(n);
for(int i=0;i<n;i++)
cin >> visit[i];
sort(visit.begin(),visit.end());
int T = visit[n-1]-visit[0]+1;
priority_queue<int> q;
for(int i=0;i<n-1;i++){
q.push(visit[i+1]-visit[i]-1);
}
for(int i=0;i<k-1;i++){
T -= q.top();
q.pop();
}
cout << T << endl;
}
int main(){
int t = 1;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |