# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
653663 | finn__ | Job Scheduling (CEOI12_jobs) | C++17 | 360 ms | 26824 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
unsigned n, m, d;
cin >> n >> d >> m;
vector<pair<int32_t, unsigned>> jobs(m);
for (unsigned i = 0; i < m; i++)
{
cin >> jobs[i].first;
jobs[i].second = i + 1;
}
sort(jobs.begin(), jobs.end());
vector<int32_t> schedule;
int32_t min_machines = m;
int32_t a = 1, b = m;
while (a < b)
{
int32_t mid = (a + b) / 2;
queue<pair<int32_t, unsigned>> q;
bool possible = 1;
auto it = jobs.begin();
vector<int32_t> local_schedule;
for (int32_t i = 1; i <= n && possible; i++)
{
while (it != jobs.end() && it->first == i)
{
q.push(*it);
it++;
}
for (unsigned j = 0; j < mid && !q.empty(); j++)
{
if (i - q.front().first > d)
{
possible = 0;
break;
}
local_schedule.push_back(q.front().second);
q.pop();
}
local_schedule.push_back(0);
}
if (possible)
{
b = mid;
if (mid < min_machines)
{
min_machines = mid;
swap(local_schedule, schedule);
}
}
else
a = mid + 1;
}
cout << a << '\n';
for (int32_t x : schedule)
{
cout << x;
if (!x)
cout << '\n';
else
cout << ' ';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |