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 ll long long
#define pll pair<int, int>
#define pb push_back
#define fi first
#define se second
using namespace std;
ll n, k, total, t[100010];
int main(){
cin >> n >> k; total=n;
vector<int>v;
for(int i=0; i<n; i++){
cin >> t[i];
if(i==0) continue;
int jeda=t[i]-t[i-1]-1;
if(jeda>0) v.pb(jeda);
}
int sz=v.size();
if(k<sz+1){
int kurang=sz+1-k;
sort(v.begin(), v.end());
for(int i=0; i<kurang; i++){
total+=v[i];
}
}
cout << total << 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... |