#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, k;
const int maxn = 2e5;
ll t[maxn + 3];
priority_queue<ll>pq;
ll sum;
ll mx;
int main()
{
// freopen("STOVEN.INP", "r", stdin);
//freopen("STOVEN.OUT", "w", stdout);
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
cin >> t[i];
}
sort(t + 1, t + n + 1);
ll res = t[n] + 1 - t[1];
for(int i = 2; i <= n; i++)
{
pq.push(t[i] - t[i - 1] - 1);
}
k = k - 1;
while(k > 0 && pq.size())
{
res -= pq.top();
//cout << pq.top() << ' ' ;
pq.pop();
k--;
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
26 ms |
3280 KB |
Output is correct |
17 |
Correct |
26 ms |
3272 KB |
Output is correct |
18 |
Correct |
26 ms |
3272 KB |
Output is correct |
19 |
Correct |
29 ms |
3324 KB |
Output is correct |
20 |
Correct |
33 ms |
3404 KB |
Output is correct |
21 |
Correct |
35 ms |
3284 KB |
Output is correct |
22 |
Correct |
37 ms |
3144 KB |
Output is correct |
23 |
Correct |
35 ms |
3316 KB |
Output is correct |
24 |
Correct |
35 ms |
3276 KB |
Output is correct |