제출 #1273637

#제출 시각아이디문제언어결과실행 시간메모리
1273637kaiboyStove (JOI18_stove)C++20
100 / 100
14 ms828 KiB
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000;

int aa[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> aa[i];
	int ans = aa[n - 1] + 1 - aa[0];
	for (int i = 0; i + 1 < n; i++)
		aa[i] = aa[i + 1] - (aa[i] + 1);
	sort(aa, aa + n - 1, greater<>());
	for (int i = 0; i < k - 1; i++)
		ans -= aa[i];
	cout << ans << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...