제출 #354906

#제출 시각아이디문제언어결과실행 시간메모리
354906SeDunionStove (JOI18_stove)C++17
100 / 100
22 ms2284 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

int a[N], d[N], Ans, n, k;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
		if (i > 1) d[i] = a[i] - a[i - 1] - 1;
	}
	Ans = a[n] - a[1] + 1;
	sort(d + 2, d + 1 + n);
	for (int i = n ; k > 1 ; -- i, -- k) {
		Ans -= max(0, d[i]);
	}
	cout << Ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...