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;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 480;
ll n,k;
ll a[N];
void to_thic_cau(){
cin >> n >> k;
vector<ll>v;
for(int i = 1; i <= n;i++){
cin >> a[i];
if(i >= 2) v.pb(a[i] - a[i-1] - 1);
}
ll s = a[n] - a[1] + 1;
sort(all(v));
k--;
while(v.size() > 0 && k > 0){
s -= v.back(); v.pop_back();
k--;
}
cout << s << '\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |