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 fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vp vector<pi>
#define vpl vector<pl>
#define ll long long
#define MAX 2147000000
#define MOD 1000000007
using namespace std;
int main(){
fastio;
int n, k;
cin >> n >> k;
vi vec(n);
for(int i{0}; i < n; ++i){
cin >> vec[i];
}
vi A;
for(int i{0}; i < n - 1; ++i){
A.push_back(vec[i + 1] - vec[i] - 1);
}
sort(A.begin(), A.end());
if(k >= n) cout << n;
else{
int ans{n};
for(int i{0}; i < n - k; ++i){
ans += A[i];
}
cout << ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |