Submission #254446

#TimeUsernameProblemLanguageResultExecution timeMemory
254446shrek12357Job Scheduling (CEOI12_jobs)C++14
100 / 100
701 ms14548 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;

int main() {
	int n, d, m;
	cin >> n >> d >> m;
	vector<int> nums(n);
	vector<pair<int, int>> cows;
	for (int i = 0; i < m; i++) {
		int temp;
		cin >> temp;
		temp--;
		nums[temp]++;
		cows.push_back(make_pair(temp, i + 1));
	}
	sort(cows.begin(), cows.end());
	int lo = 0;
	int hi = 1000005;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		vector<int> temp = nums;
		int idx = 0;
		bool bad = false;
		for (int i = 0; i < n; i++) {
			if (idx + d < i && idx != n - d) {
				bad = true;
				break;
			}
			int tCounter = mid;
			while (idx <= i && tCounter > 0) {
				if (idx == n - d) {
					break;
				}
				if (temp[idx] > tCounter) {
					temp[idx] -= tCounter;
					break;
				}
				else {
					tCounter -= temp[idx];
					temp[idx] = 0;
					idx++;
				}
			}
		}
		if (!bad) {
			hi = mid;
		}
		else {
			lo = mid + 1;
		}
	}
	cout << hi << endl;
	int counter = 0;
	int countDays = 0;
	for (int i = 0; i < cows.size(); i++) {
		cout << cows[i].second << " ";
		counter++;
		if (counter == hi) {
			cout << 0 << endl;
			countDays++;
			counter = 0;
		}
	}
	for (int i = 0; i < n - countDays; i++) {
		cout << 0 << endl;
	}
}

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:64:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < cows.size(); i++) {
                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...