제출 #1100482

#제출 시각아이디문제언어결과실행 시간메모리
1100482crispxxStove (JOI18_stove)C++14
100 / 100
18 ms3280 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector
#define nl " \n"
#define pb emplace_back
#define all(x) x.begin(), x.end()

template <class _F, class _S> 
void chmin(_F &a, _S b) { 
	if(a > b) a = b;
}

template <class _F, class _S> 
void chmax(_F &a, _S b) { 
	if(a < b) a = b;
}

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