# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62224 | kingpig9 | Stove (JOI18_stove) | C++11 | 57 ms | 10620 KiB |
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;
typedef pair<int, int> pii;
const int MAXN = 1e5 + 10;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
int N, K;
int A[MAXN];
int main() {
scanf("%d %d", &N, &K);
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
sort(A, A + N);
int ans = A[N - 1] - A[0] + 1;
priority_queue<int> pq;
for (int i = 0; i < N; i++) {
pq.push(A[i + 1] - A[i] - 1);
}
//K - 1 times at most
for (int i = 1; i < K; i++) {
if (pq.empty()) {
break;
}
ans -= pq.top();
pq.pop();
}
printf("%d\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |