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 <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long int N,K,horatotal;
int main(){
while(cin>>N>>K){
vector <long long int> horainicio(N);
vector <long long int> rangoespera(N-1);
for(int a=0;a<N;a++){
cin>>horainicio[a];
}
horatotal=horainicio[N-1]-horainicio[0]+1;
for(int a=0;a<N-1;a++){
rangoespera[a]=horainicio[a+1]-horainicio[a]-1;
}
sort(rangoespera.rbegin(),rangoespera.rend());
for(int a=0;a<K-1;a++){
horatotal-=rangoespera[a];
}
cout<<horatotal<<'\n';
}
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... |