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 pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define elif else if
#define x first
#define y second
ll n, k, t[100001], dist[100001], ans;
int main(){
cin >> n >> k;
for(int i=1; i<=n; i++){
cin >> t[i];
}
for(int i=2; i<=n; i++){
dist[i]=t[i]-t[i-1];
}
sort(dist+2, dist+n+1, greater<ll>());
ans=t[n]-t[1]+1;
for(int i=2; i<=n && k>1; i++, k--){
ans-=dist[i]-1;
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |