#include <bits/stdc++.h>
using namespace std;
long long t[100001];
int main(void)
{
long long n,k,ans;
cin>>n>>k;
k--;
priority_queue<long long> q;
for(int i=0;i<n;i++)
{
cin>>t[i];
}
q.push(0);
for(int i=1;i<n;i++)
{
q.push(t[i]-t[i-1]-1);
}
ans=t[n-1]-t[0]+1;
while(k--)
{
ans=ans-q.top();
q.pop();
}
cout<<ans;
return 0;
}
/*
3 3
1
3
6
1 0
3 1
6 2
10 5
1
2
5
6
8
11
13
15
16
20
1 0 1->3
2 0
5 2 5->9
6 0
8 1
11 2 11->14
13 1
15 1 15->17
16 0
20 3 20->21
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
480 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
480 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
35 ms |
3264 KB |
Output is correct |
17 |
Correct |
30 ms |
3272 KB |
Output is correct |
18 |
Correct |
31 ms |
3268 KB |
Output is correct |
19 |
Correct |
31 ms |
3264 KB |
Output is correct |
20 |
Correct |
34 ms |
3272 KB |
Output is correct |
21 |
Correct |
37 ms |
3244 KB |
Output is correct |
22 |
Correct |
37 ms |
3096 KB |
Output is correct |
23 |
Correct |
39 ms |
3272 KB |
Output is correct |
24 |
Correct |
38 ms |
3264 KB |
Output is correct |