#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bip(i) __builtin_popcount(i)
#define gb(i,j) ((i>>j)&1)
#define fi first
#define se second
using namespace std;
const int N=1e5+5;
int k , n , a[N];
ll res;
int gap[N];
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> k;
for( int i=1 ; i<=n ; i++ ){
cin >> a[i];
if(i>1)
gap[i] = a[i]-a[i-1]-1; // gap cua i va cai trc
// gap[i].se.fi = a[i-1]+1;
// gap[i].se.se = a[i];
res+=1;
}
sort(gap+2 , gap+1+n);
// for( int i=1 ; i<=n ; i++ )cout << i << " " << gap[i].fi << endl;
if(k<n){
k=n-k;
for( int i=1 ; i<=k ; i++ ){
res+=gap[i+1];
}
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
480 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
480 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
13 ms |
2140 KB |
Output is correct |
17 |
Correct |
14 ms |
2004 KB |
Output is correct |
18 |
Correct |
14 ms |
2084 KB |
Output is correct |
19 |
Correct |
15 ms |
2140 KB |
Output is correct |
20 |
Correct |
14 ms |
2208 KB |
Output is correct |
21 |
Correct |
14 ms |
2128 KB |
Output is correct |
22 |
Correct |
13 ms |
2140 KB |
Output is correct |
23 |
Correct |
14 ms |
2140 KB |
Output is correct |
24 |
Correct |
13 ms |
2140 KB |
Output is correct |