Submission #1093790

# Submission time Handle Problem Language Result Execution time Memory
1093790 2024-09-27T13:03:25 Z julian Stove (JOI18_stove) C++
100 / 100
42 ms 2956 KB
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	long N, K;
	std::cin >> N >> K;

	std::vector<long> T(N);
	for (long i = 0; i < N; i++) {
		std::cin >> T[i];
	}

	std::sort(T.begin(), T.end());

	

	std::vector<long> diffs(N - 1);

	for (long i = 0; i < N - 1; i++) {
		diffs[i] = T[i + 1] - T[i] - 1;
	}

	std::sort(diffs.begin(), diffs.end(), std::greater<>());

	long cost = T[N - 1] - T[0] + 1;

	for (long k = 0; k < K - 1; k++) {
		if (diffs[k] > 0)
			cost -= diffs[k];
	}

	std::cout << cost << std::endl;


}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 3 ms 696 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 3 ms 696 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 31 ms 2908 KB Output is correct
17 Correct 31 ms 2956 KB Output is correct
18 Correct 33 ms 2864 KB Output is correct
19 Correct 32 ms 2896 KB Output is correct
20 Correct 33 ms 2896 KB Output is correct
21 Correct 31 ms 2904 KB Output is correct
22 Correct 41 ms 2900 KB Output is correct
23 Correct 32 ms 2896 KB Output is correct
24 Correct 42 ms 2952 KB Output is correct