답안 #718467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718467 2023-04-04T07:22:39 Z shoryu386 Stove (JOI18_stove) C++17
100 / 100
56 ms 2800 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

main(){
	int n, k; cin >> n >> k; int arr[n];
	for (int x= 0; x < n; x++) cin >> arr[x];
	
	sort(arr, arr+n);
	int ans = arr[n-1] - arr[0] + 1;
	vector<int> diffs;
	for (int x = 1; x < n; x++){
		diffs.push_back(arr[x] - arr[x-1] - 1);
	}
	
	sort(diffs.begin(), diffs.end());
	int cnt = 1;
	for (int x = diffs.size()-1; x > -1; x--){
		if (cnt == k) break;
		cnt++;
		ans -= diffs[x];
		if (cnt == k) break;
	}
	
	cout << ans;
}

Compilation message

stove.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 324 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 324 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 308 KB Output is correct
16 Correct 50 ms 2732 KB Output is correct
17 Correct 56 ms 2772 KB Output is correct
18 Correct 50 ms 2688 KB Output is correct
19 Correct 49 ms 2756 KB Output is correct
20 Correct 49 ms 2784 KB Output is correct
21 Correct 47 ms 2688 KB Output is correct
22 Correct 50 ms 2800 KB Output is correct
23 Correct 55 ms 2684 KB Output is correct
24 Correct 49 ms 2736 KB Output is correct