답안 #938084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938084 2024-03-04T19:25:28 Z TAhmed33 Job Scheduling (CEOI12_jobs) C++
100 / 100
214 ms 4084 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 25;
int n, d, m;
int a[MAXN];
bool check (int x) {
	bool flag = 1;
	int ptr = 1;
	for (int day = 1; day <= n; day++) {
		int cnt = 0;
		while (ptr <= m && a[ptr] <= day && cnt + 1 <= x) {
			flag &= day <= a[ptr] + d;
			ptr++; cnt++;
		} 
	}
	flag &= ptr == m + 1;
	return flag;
}
void cringe () {
	for (int i = 1; i <= n; i++) cout << 0 << endl;
}
int main () {
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("rand", "r", stdin);
	cin >> n >> d >> m;
	for (int i = 1; i <= m; i++) cin >> a[i];
	sort(a + 1, a + m + 1);
	int l = 1, r = m - 1, ans = m;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (check(mid)) {
			r = mid - 1; ans = mid;
		} else {
			l = mid + 1;
		}
	}
	cout << ans << '\n';
	cringe();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2652 KB Output is correct
2 Correct 18 ms 2648 KB Output is correct
3 Correct 18 ms 2652 KB Output is correct
4 Correct 18 ms 2648 KB Output is correct
5 Correct 21 ms 2648 KB Output is correct
6 Correct 18 ms 2696 KB Output is correct
7 Correct 18 ms 2652 KB Output is correct
8 Correct 18 ms 2708 KB Output is correct
9 Correct 125 ms 3244 KB Output is correct
10 Correct 118 ms 2704 KB Output is correct
11 Correct 12 ms 2652 KB Output is correct
12 Correct 23 ms 2700 KB Output is correct
13 Correct 33 ms 2652 KB Output is correct
14 Correct 60 ms 2648 KB Output is correct
15 Correct 56 ms 2668 KB Output is correct
16 Correct 85 ms 2648 KB Output is correct
17 Correct 100 ms 3180 KB Output is correct
18 Correct 104 ms 3576 KB Output is correct
19 Correct 214 ms 4084 KB Output is correct
20 Correct 98 ms 3172 KB Output is correct