This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
ll n, k;
vector<int>t;
vector<int>restas;
void tc(){
cin >> n >> k;
for(int i = 0 ; i < n ; i ++){
int temp;
cin >> temp;
if(i > 0)restas.pb(temp - t.back() - 1);
t.pb(temp);
}
sort(restas.begin(), restas.end());
int total = t.back() + 1 - t[0];
for(int i = 0 ; i < k - 1 ; i ++){
if(!restas.empty()){
total -= restas.back();
restas.pop_back();
}
}
cout << total << "\n";
}
void end_tc(){
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(NULL);
int t = 1;
while(t--){
tc();
end_tc();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |