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>
#define int long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define kill(x) cout << x << endl, exit(0);
#define endl "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
int n, m, t, q, tmp, tmp2, tmp3, tmp4, ans, k, u, v, w, flag;
int arr[MAXN];
vector<int> vec;
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i=1; i<=n; i++) cin >> arr[i];
sort(arr+1, arr+n+1);
ans = arr[n]-arr[1]+1;
for (int i=2; i<=n; i++) vec.pb(arr[i]-arr[i-1]);
sort(all(vec), greater<int>());
for (int i=1; i<k; i++) ans -= vec[i-1]-1;
cout << ans << endl;
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... |