Submission #751055

# Submission time Handle Problem Language Result Execution time Memory
751055 2023-05-31T02:48:14 Z KN200711 Stove (JOI18_stove) C++14
100 / 100
26 ms 2296 KB
# include <bits/stdc++.h>
using namespace std;

int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	vector<int> arr(N);
	for(int i=0;i<N;i++) scanf("%d", &arr[i]);
	sort(arr.begin(), arr.end());
	int ans = arr.back() + 1 - arr[0];
	vector<int> sel;
	sel.clear();
	
	for(int i=0;i + 1<N;i++) {
		if(arr[i + 1] > arr[i]) sel.push_back(arr[i + 1] - arr[i] - 1);
	}
	sort(sel.begin(), sel.end());
	for(int c=sel.size() - 1, d = K - 1;c>=0 && d > 0;c--, d--) {
		ans -= sel[c];
	}
	printf("%d\n", ans);
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:6:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |  scanf("%d %d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:8:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  for(int i=0;i<N;i++) scanf("%d", &arr[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 20 ms 2216 KB Output is correct
17 Correct 20 ms 2284 KB Output is correct
18 Correct 20 ms 2232 KB Output is correct
19 Correct 20 ms 2208 KB Output is correct
20 Correct 26 ms 2296 KB Output is correct
21 Correct 20 ms 2196 KB Output is correct
22 Correct 19 ms 2296 KB Output is correct
23 Correct 19 ms 2292 KB Output is correct
24 Correct 19 ms 2212 KB Output is correct