Submission #687680

#TimeUsernameProblemLanguageResultExecution timeMemory
687680NK_Stove (JOI18_stove)C++17
100 / 100
12 ms984 KiB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

int d[123];
long long read() {
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		ch = getchar();
	}
	long long v = 0;
	while ('0' <= ch && ch <= '9') {
		v = v * 10 + (int) (ch - '0');
		ch = getchar();
	}
	return v;
}
 
void write(int x) {
	int len = 0;
	while (x > 0) {
		d[len++] = x % 10;
		x /= 10;
	}
	for (int i = len - 1; i >= 0; i--) {
		putchar('0' + d[i]);
	}
	if (len == 0) {
		putchar('0');
	}
	putchar('\n');
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N = read(), K = read();

	vector<int> gaps;
	int t = read();
	int ans = -t;
	for(int i = 1; i < N; i++) {
		int x = read();
		gaps.push_back(x-t-1);
		t = x;
	}

	// for(auto x : gaps) cout << x << " ";

	sort(rbegin(gaps), rend(gaps));

	ans += t+1;
	for(int i = 0; i < min(K-1, int(size(gaps))); i++) ans -= gaps[i];

	write(ans);

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...