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 pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef vector<int> vi;
typedef long long ll;
#define PB push_back
#define MP make_pair
#define FOR(i, x, y) for (int i = x; i < y ; i ++)
int main(){
int n, k; cin >> n >> k;
int prev;
vi gaps;
cin >> prev;
FOR(i, 0, n - 1){
int num; cin >> num;
gaps.PB(num - prev - 1);
prev = num;
}
sort(gaps.begin(), gaps.end());
ll ans = n;
FOR(i, 0, k - 1){
ans += gaps[i];
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |