This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
@AUTHOR: BY_KUTBILIM
FILE CREATED: 17.11.2021 14:43:09 (GMT+6)
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using pii = pair<int, int>;
void solve(){
int n, k;
cin >> n >> k;
long long a[n];
for(auto &e : a){
cin >> e;
}
long long b[n-1];
for(int i = 0; i < n-1; i++){
b[i] = a[i+1] - a[i]-1;
}
sort(b, b + n - 1);
long long ans = n;
for(int i = 0; i <n-k; i++)ans += b[i];
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
solve();
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... |