#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
typedef long long llong;
const int MAXN = 100000 + 10;
const int MAXLOG = 17;
const int INF = 2e9;
int a[MAXN], n, k;
void solve()
{
int max = a[1];
std::sort(a+1, a+1+n);
for (int i = n ; i >= 2 ; --i)
{
max = std::max(max, a[i]);
a[i] -= a[i-1];
a[i]--;
}
int sum = 0;
std::sort(a+2, a+1+n); --k;
for (int i = n ; i >= n - k + 1 ; --i)
{
sum += a[i];
}
std::cout << max - sum << '\n';
}
void read()
{
std::cin >> n >> k;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |