#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
52 ms |
2028 KB |
Output is correct |
17 |
Correct |
53 ms |
2028 KB |
Output is correct |
18 |
Correct |
50 ms |
2156 KB |
Output is correct |
19 |
Correct |
50 ms |
2028 KB |
Output is correct |
20 |
Correct |
49 ms |
2048 KB |
Output is correct |
21 |
Correct |
49 ms |
2028 KB |
Output is correct |
22 |
Correct |
50 ms |
2028 KB |
Output is correct |
23 |
Correct |
49 ms |
2028 KB |
Output is correct |
24 |
Correct |
61 ms |
2028 KB |
Output is correct |