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 <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <climits>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
const ll mod = 1e9 + 7;
const ll inf = 1e18;
// #define int long long
void solve(){
int n, k;
cin >> n >> k;
vector <int> a(n), arr;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 1; i < n; i++){
arr.pb(a[i] - a[i - 1] - 1);
}
sort(arr.begin(), arr.end());
int m = n - k, ans = n, l = 0;
while(m--){
ans += arr[l];
l++;
}
cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T = 1;
// cin >> T;
while(T--){
solve();
cout << '\n';
}
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... |