제출 #1144687

#제출 시각아이디문제언어결과실행 시간메모리
1144687crispxxStove (JOI18_stove)C++20
100 / 100
14 ms1480 KiB
/**
 *    author: a.k
 *    created: idk
**/
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define nl '\n'

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, k; cin >> n >> k;
	
	vector<int> t(n);
	
	for(auto &u : t) cin >> u;
	
	vector<int> a;
	
	for(int i = 0; i + 1 < n; i++) {
		a.pb(t[i + 1] - t[i] - 1);
	}
	
	int ans = t[n - 1] - t[0] + 1;
	
	sort(all(a), greater<>());
	
	for(int i = 0; i < k - 1; i++) ans -= a[i];
	
	cout << ans << nl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...