Submission #1033674

#TimeUsernameProblemLanguageResultExecution timeMemory
1033674vjudge1Stove (JOI18_stove)C++17
100 / 100
19 ms2396 KiB
//#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...