Submission #525931

# Submission time Handle Problem Language Result Execution time Memory
525931 2022-02-13T08:41:17 Z pawned Job Scheduling (CEOI12_jobs) C++17
100 / 100
593 ms 20896 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int N, D, M;	// days, max delay, reqs
ii numbers[1000050];
vector<int> answers[100050];
int final = -1;

bool check(int n) {	// checks if n machines is enough
	int needed[2 * N] = {0};
	int latest = 0;
	for (int i = 0; i < M; i++) {	// finds earliest possible time for each
		latest = max(latest, numbers[i].fi);
		while (needed[latest] == n)
			latest++;
		if (latest - numbers[i].fi > D)
			return false;
		needed[latest]++;
		if (n == final)
			answers[latest].pb(numbers[i].se);
	}
	return true;
}

int main() {
	cin>>N>>D>>M;
	for (int i = 0; i < M; i++) {
		cin>>numbers[i].fi;
		numbers[i].se = i + 1;
	}
	sort(numbers, numbers + M);
	int low = 0;
	int high = 1e9;
	int ans = -1;
	while (low <= high) {	// false, false, false, true, true, true
		int mid = (low + high) / 2;
		if (check(mid)) {
			ans = mid;
			high = mid - 1;
		}
		else {
			low = mid + 1;
		}
	}
	cout<<ans<<endl;
	final = ans;
	check(ans);
	for (int i = 1; i <= N; i++) {
		for (int j : answers[i])
			cout<<j<<" ";
		cout<<0<<endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 70 ms 4640 KB Output is correct
2 Correct 57 ms 4636 KB Output is correct
3 Correct 52 ms 4596 KB Output is correct
4 Correct 52 ms 4524 KB Output is correct
5 Correct 56 ms 4632 KB Output is correct
6 Correct 53 ms 4644 KB Output is correct
7 Correct 57 ms 4628 KB Output is correct
8 Correct 53 ms 4624 KB Output is correct
9 Correct 159 ms 5476 KB Output is correct
10 Correct 210 ms 5448 KB Output is correct
11 Correct 56 ms 4432 KB Output is correct
12 Correct 103 ms 6500 KB Output is correct
13 Correct 156 ms 8952 KB Output is correct
14 Correct 247 ms 11204 KB Output is correct
15 Correct 249 ms 11928 KB Output is correct
16 Correct 380 ms 14132 KB Output is correct
17 Correct 403 ms 17988 KB Output is correct
18 Correct 438 ms 18576 KB Output is correct
19 Correct 593 ms 20896 KB Output is correct
20 Correct 419 ms 18036 KB Output is correct