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 pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
int arr[maxn], n, k;
bool light[maxn];
vector<pair<int,int> > diff;
int main() {
cin>>n>>k;
for(int i=1;i<=n;i++) {
cin>>arr[i];
}
for(int i=2;i<=n;i++) {
diff.pb(mp(arr[i]-arr[i-1], i));
}
light[1] = true;
sort(diff.rbegin(), diff.rend());
for(int i=0;i<k-1;i++) {
light[diff[i].second] = true;
}
arr[0] = 0;
int last = 1;
int result = 0;
for(int i=1;i<=n;i++) {
if(light[i]) {
result += arr[i-1] + 1 - last;
last = arr[i];
}
else continue;
}
result += arr[n] + 1 - last;
cout<<result;
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... |