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 pair<int, int> i;
int n, m, k, b[100001], tmp;
bool ck[100005];
vector<i> a;
int main(){
cin >> n >> k;
//cout << n << endl;
tmp = k;
for(int i = 1; i <= n; i++){
cin >> b[i];
//cout << b[i] << endl;
}
for(int i = 1; i < n; i++) a.push_back(make_pair(b[i + 1] - b[i], i));
sort(a.begin(), a.end());
//cout << ans << endl;
int cnt = n;
for(int i = 0; i < n - k; i++){
cnt += a[i].first - 1;
//cout << cnt << endl;
}
cout << 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... |