# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
479215 | cheeseman | Job Scheduling (CEOI12_jobs) | C++14 | 1064 ms | 22396 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;
long long n, m, d;
bool works(long long machines, vector<vector<int>> &reqs)
{
priority_queue<long long, vector<long long>, greater<long long>> pq;
for (int i = 0; i < n; i++)
{
for (int j : reqs[i])
{
pq.push(i + d);
}
for (int j = 0; j < machines; j++)
{
if (pq.empty())
{
break;
}
if (pq.top() < i)
{
return false;
}
pq.pop();
}
}
return true;
}
int main()
{
cin >> n >> d >> m;
vector<vector<int>> reqs(n);
int day;
for (int i = 0; i < m; i++)
{
cin >> day;
reqs[day - 1].push_back(i);
}
long long l = 1, r = m;
long long best = INT_MAX;
while (l <= r)
{
long long mid = (l + r) / 2;
if (works(mid, reqs))
{
r = mid - 1;
best = mid;
}
else
{
l = mid + 1;
}
}
cout << best << endl;
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
greater<pair<long long, int>>>
pq;
vector<vector<int>> sol(n);
for (int i = 0; i < n; i++)
{
for (int j : reqs[i])
{
pq.push(make_pair(i + d, j));
}
for (int j = 0; j < best; j++)
{
if (pq.empty())
{
break;
}
sol[i].push_back(pq.top().second + 1);
pq.pop();
}
}
for (auto day : sol)
{
for (int req : day)
{
cout << req << ' ';
}
cout << 0 << endl;
}
return true;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |