#include <bits/stdc++.h>
#define FOR(i, u, v) for (int i = u; i <= v; i++)
#define FORD(i, v, u) for (int i = v; i >= u; i--)
#define N 1000005
using namespace std;
int n, k, a[N], b[N], res;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
cin >> n >> k;
FOR(i, 1, n) cin >> a[i];
sort(a+1, a+n+1);
FOR(i, 1, n-1) b[i] = a[i+1] - a[i];
sort(b+1, b+n);
reverse(b+1, b+n);
k--;
res = a[n] - a[1] + 1;
FOR(i, 1, k)
res -= (b[i]-1);
cout <<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
452 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
536 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
536 KB |
Output is correct |
7 |
Correct |
2 ms |
660 KB |
Output is correct |
8 |
Correct |
2 ms |
660 KB |
Output is correct |
9 |
Correct |
2 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
452 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
536 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
536 KB |
Output is correct |
7 |
Correct |
2 ms |
660 KB |
Output is correct |
8 |
Correct |
2 ms |
660 KB |
Output is correct |
9 |
Correct |
2 ms |
660 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
3 ms |
868 KB |
Output is correct |
15 |
Correct |
3 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
452 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
536 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
536 KB |
Output is correct |
7 |
Correct |
2 ms |
660 KB |
Output is correct |
8 |
Correct |
2 ms |
660 KB |
Output is correct |
9 |
Correct |
2 ms |
660 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
3 ms |
868 KB |
Output is correct |
15 |
Correct |
3 ms |
900 KB |
Output is correct |
16 |
Correct |
26 ms |
2668 KB |
Output is correct |
17 |
Correct |
26 ms |
3560 KB |
Output is correct |
18 |
Correct |
26 ms |
4536 KB |
Output is correct |
19 |
Correct |
26 ms |
5616 KB |
Output is correct |
20 |
Correct |
26 ms |
6468 KB |
Output is correct |
21 |
Correct |
26 ms |
7608 KB |
Output is correct |
22 |
Correct |
26 ms |
8396 KB |
Output is correct |
23 |
Correct |
26 ms |
9496 KB |
Output is correct |
24 |
Correct |
25 ms |
10376 KB |
Output is correct |