# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
696424 | cfjason | Job Scheduling (CEOI12_jobs) | C++17 | 1082 ms | 30412 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(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, d, m;
cin >> n >> d >> m;
vector<vector<int>> requestsByDay(n);
vector<string> validResults;
for (int i = 0; i < m; i++)
{
int day;
cin >> day;
requestsByDay[day-1].push_back(i+1);
}
int lower = 0, upper = m+1;
while (lower + 1 < upper)
{
int mid = (lower + upper) / 2;
int reqIndex = 0;
priority_queue<array<int, 2>, vector<array<int, 2>>, greater<>> line;
bool valid = true;
vector<string> results(n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < requestsByDay[i].size(); j++)
line.push(array<int, 2>{i, requestsByDay[i][j]});
for (int j = 0; j < mid; j++)
{
if (line.size())
{
if (i - line.top()[0] > d)
{
valid = false;
break;
}
results[i] += to_string(line.top()[1]) + " ";
line.pop();
}
else
{
break;
}
}
results[i] += "0";
if (!valid)
break;
}
if (line.size())
valid = false;
if(valid){
validResults = results;
upper = mid;
}
else{
lower = mid;
}
}
cout << upper << endl;
for (int i = 0; i < n; i++)
{
cout << validResults[i] << endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |