# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104813 | daili | Job Scheduling (CEOI12_jobs) | C++14 | 303 ms | 20052 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;
bool check(vector<pair<int,int>> &allJobs, int currNr, int delay, int days)
{
vector<int> busy(days+1);
for (int i = 0; i < allJobs.size(); i++)
{
int day = allJobs[i].first;
while(busy[day] >= currNr)
{
day++;
}
if (allJobs[i].second + delay < day)
{
return false;
}
else
{
busy[day]++;
}
}
return true;
}
void print(vector<pair<int,int>> &allJobs, int days, int nr)
{
vector<vector<int>> busy(days+1);
for (int i = 0; i < allJobs.size(); i++)
{
int day = allJobs[i].first;
while(busy[day].size() >= nr)
{
day++;
}
busy[day].push_back(allJobs[i].second);
}
for (int i = 1; i <= days; i++)
{
for (auto j: busy[i])
{
cout << j << " ";
}
cout << 0 << "\n";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, d, m;
cin >> n >> d >> m;
vector<pair<int,int>> allJobs;
for (int i = 0; i < m; i++)
{
int x;
cin >> x;
allJobs.push_back({x, i+1});
}
sort(allJobs.begin(), allJobs.end());
int left = 1;
int right = m;
while(left <= right)
{
int mid = (left + right) >> 1;
if (check(allJobs, mid, d, n))
{
right = mid - 1;
}
else
{
left = mid + 1;
}
}
if (check(allJobs, (left+right) >> 1, d, n))
{
cout << ((left+right) >> 1) << "\n";
print(allJobs, n, (left+right) >> 1);
}
else
{
cout << ((left + right) >> 1) + 1 << "\n";
print(allJobs, n, ((left+right) >> 1) + 1);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |