제출 #818816

#제출 시각아이디문제언어결과실행 시간메모리
818816vjudge1Stove (JOI18_stove)C++17
100 / 100
38 ms1616 KiB
#include <bits/stdc++.h>
#define ll long long 
#define pll pair<int, int>
#define pb push_back
#define fi first
#define se second
using namespace std;
ll n, k, total, t[100010];

int main(){
	cin >> n >> k; total=n;
	vector<int>v;
	for(int i=0; i<n; i++){
		cin >> t[i];
		if(i==0) continue;
		int jeda=t[i]-t[i-1]-1;
		if(jeda>0) v.pb(jeda); 
	}
	int sz=v.size();
	if(k<sz+1){
		int kurang=sz+1-k;
		sort(v.begin(), v.end());
		for(int i=0; i<kurang; i++){
			total+=v[i];
		}
	}
	cout << total << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...