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;
typedef long long ll;
#define FOR(i, l, r) for(ll i = l; i <= r; i++)
ll a[100005], val[100005];
pair<ll, ll> p[100005];
bool tmp(pair<ll, ll> A, pair<ll, ll> B){
if(A.first != B.first) return A.first < B.first;
else return A.second <= B.second;
}
int main(){
ll n, k;
cin >> n >> k;
FOR(i, 0, n - 1){
cin >> a[i];
}
FOR(i, 0, n - 2){
val[i] = a[i + 1] - a[i];
p[i].first = val[i];
p[i].second = i;
}
sort(p, p + n - 1, tmp);
ll ans = 0;
FOR(i, 0, n - k - 1){
ans += p[i].first;
}
cout << ans + k;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |