This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |