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 IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define F first
#define S second
using namespace std;
void solve () {
int n, match; cin >> n >> match;
match--;
pq<int> q;
vector<int> v;
for (int i = 0; i < n; i++) {
int a1; cin >> a1;
if (i) q.push(a1 - v.back() - 1);
v.pb(a1);
}
int ans = v.back() - v[0] + 1;
while ((match > 0) && (!q.empty())) {
ans -= q.top();
q.pop();
match--;
}
cout << ans;
}
signed main() {IOS solve(); 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... |