제출 #930594

#제출 시각아이디문제언어결과실행 시간메모리
930594ArgoCahayaStove (JOI18_stove)C++14
100 / 100
52 ms1888 KiB
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define pll pair<long long, long long>
#define loop(i,n) for(int i=1;i<=n;i++)
#define loop0(i,n) for(int i=0;i<n;i++)
using namespace std;
 
//pbds template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
 
//template <class T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
void solve(){
	int n,k;
	cin >> n >> k;
	priority_queue<int> pq;
	int prev = -1;
	int first = -1;
	for(int i=1;i<=n;i++){
		int a;
		cin >> a;
		if(prev!=-1) pq.push((a-prev));
		if(first == -1) first = a;
		prev = a;
	}
//	cout << "DEBUG" << endl;
	int ans = prev-first+1;
	int turn = k-1;
	while(turn>0){
		ans -= pq.top()-1;
		pq.pop();
		turn--;
	}
	cout << ans << endl;
}
 
int main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);
//	cout.tie(0);
	int tc = 1;
//	cin >> tc;
	while(tc--){
	   solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...