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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solucion(int K, vector<int> & momentos) {
int N = (int) momentos.size();
vector<int> huecos(N-1);
for (int i = 0; i < N-1; i++)
huecos[i] = momentos[i+1]-momentos[i]-1;
sort(huecos.begin(), huecos.end(), greater<int>());
int respuesta = momentos[N-1]+1 - momentos[0];
for (int i = 0; i < K-1; i++) {
respuesta -= huecos[i];
}
return respuesta;
}
int main() {
int N, K;
vector<int> momentos;
cin >> N >> K;
momentos = vector<int>(N);
for (int i = 0; i < N; i++)
cin >> momentos[i];
cout << solucion(K, momentos) << '\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... |