This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int N, K, A[100010], ans;
vector<int> blank;
signed main() {
fast;
cin >> N >> K;
for (int i = 1; i <= N; ++i) {
cin >> A[i];
}
sort(A + 1, A + 1 + N);
for (int i = 1; i <= N - 1; ++i) {
blank.pb(A[i + 1] - A[i] - 1);
}
ans = A[N] + 1 - A[1];
sort(blank.begin(), blank.end(), greater<int>());
for (int i = 0; i < K - 1; ++i) {
ans -= blank[i];
}
cout << ans;
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... |