답안 #863301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863301 2023-10-20T02:13:21 Z maks007 Stove (JOI18_stove) C++14
0 / 100
0 ms 348 KB
#include "bits/stdc++.h"

using namespace std;

//#define int long long 

signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	function <int(int, int)> good=[&](int sz, int opt) {
		int prev = a[0], ans = 1, cnt = 1;
		for(int i = 1; i < n; i ++) {
			if((a[i] + 1) - (prev + 1) <= sz) {
				ans += ((a[i] + 1) - (prev + 1));
				prev = a[i];
			}else {
				ans += 1;
				prev = a[i];
				cnt ++;
			}
		}
		if(opt == 0) {
			if(cnt <= k) return 1;
			return 0;
		}
		return ans;
	};
	for(int i = 0; i < n; i ++) cin >> a[i];
	sort(a.begin(), a.end());
	int l = 1, r = (int)1e9;
	while(l < r) {
		int mid = (l + r) / 2;
		if(good(mid, 0)) r = mid;
		else l = mid + 1;
	}
	cout << good(r, 1);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -