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 fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;
const int N=1e5+5, mod = 1e9+7, inf = 1e18;
int n, k;
int a[N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i=1; i<=n; i++) cin >> a[i];
vector<int> b;
for (int i=2; i<=n; i++) {
b.pb(a[i]-a[i-1]-1);
}
sort(all(b), greater<int>());
int cnt = 0;
for (int i=0; i<k-1; i++) cnt += b[i];
cout << a[n]-cnt;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |