#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i <= (b); --i)
#define each(i, a) for (auto i : a)
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
template<typename T> inline bool ckmax(T&x, T y) { if (x >= y) return false; x = y; return true; }
template<typename T> inline bool ckmin(T&x, T y) { if (x <= y) return false; x = y; return true; }
const int MOD = int(1e9) + 7, naxm = 100000;
int N, K, T[naxm + 5];
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
cin >> N >> K;
rep(i, 1, N) cin >> T[i];
int ans = T[N];
priority_queue<int> que;
rep(i, 1, N - 1) que.push(T[i + 1] - T[i] - 1);
--K;
while (que.size()) {
if (!K) break;
--K;
ans -= que.top();
que.pop();
}
cout << ans << "\n";
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 |
- |