제출 #311128

#제출 시각아이디문제언어결과실행 시간메모리
311128TemmieStove (JOI18_stove)C++17
100 / 100
23 ms2652 KiB
#include <bits/stdc++.h>

typedef long long ll;

int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	
	int n, k; std::cin >> n >> k;
	std::vector <int> a(n);
	for (int& x : a) std::cin >> x;
	std::sort(a.begin(), a.end());
	ll ans = a.back() - a.front();
	std::vector <ll> in(n - 1);
	for (int i = 0; i < n - 1; i++) in[i] = a[i + 1] - a[i] - 1;
	std::sort(in.begin(), in.end());
	while (--k) ans -= in.back(), in.pop_back();
	std::cout << ans + 1 << "\n";
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...