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;
int main() {
int n,m,ans = 0;
cin>>n>>m;
m--;
int a[n];
vector <pair<int,int>> b(n-1);
int bs[n-1];
cin>>a[0];
for(int k=1;k<n;k++){
cin>>a[k];
b[k-1].first = a[k] - a[k-1];
bs[k-1] = b[k-1].first;
}
sort(bs,bs+n-1);
int cnt = 0;
for(int k=0;k<n-1;k++){
if(b[k].first>=bs[n-m-1] and n-m-1<=n-2) {
cnt++;
b[k].second = 1;
} else b[k].second = 0;
}
if(cnt>m){
for(int k=0;k<n-1;k++){
if(b[k].first==bs[n-m-1] and cnt>m){
b[k].second = 0;
cnt--;
}
}
}
for(int k=0;k<n-1;k++){
int j = k;
if(b[k].second==1) ans++; else {
while(b[j].second!=1 and j<n-1){
ans = ans + b[j].first;
j++;
}
ans++;
k = j;
}
}
if(b[n-2].second==1) ans++;
cout<<ans;
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... |