#include <bits/stdc++.h>
#define MAXN (int)1e6
#define FOR(n) for(int i = 0; i < n; i++)
using namespace std;
int a[MAXN],b[MAXN];
int main(){
int n,k; cin >> n >> k;
FOR(n) cin >> a[i];
sort(a,a+n);
if(k==1) {cout << a[n-1]-a[0]+1 << "\n"; return 0;}
int m=0;
for(int i = 0; i < n; i++)if(a[i]+1!=a[i+1]) m++;
cout << n+m-k << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |