This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
#include<bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define pll pair<long long, long long>
#define pii pair<int , int>
#define fi first
#define se second
#define bit(i,j) ((j >> i) & 1)
using namespace std;
const long long inf = 1e18+1;
const int mod = 1e9+7;
const int MAXN = 1e6+100;
#define int long long
int32_t main(){
//freopen("PAINT.INP", "r", stdin);
//freopen("PAINT.OUT", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
int n , k; cin >> n >> k;
vector<int> a(n+1) , v;
for(int i = 1 ; i <= n ; i++){
cin >> a[i];
if(i != 1) v.push_back(a[i] - a[i-1] - 1);
}
int sum = a[n] - a[1] + 1;
k--;
sort(all(v) , greater<int>());
for(int i = 0 ; i < k ; i++){
sum -= v[i];
}
cout << sum << "\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... |