# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1004378 | u_suck_o | Job Scheduling (CEOI12_jobs) | C++17 | 333 ms | 37012 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 <iostream>
#include <vector>
#include <queue>
#define MAXN 100005
using namespace std;
int n, d, m;
vector<int> tasks[MAXN];
int main() {
cin >> n >> d >> m;
for (int i = 1; i <= m; i++) {
int x; cin >> x;
tasks[x].push_back(i);
}
//binary search on answer
int l = 1, r = m;
while (l < r) {
int mid = (l+r)/2;
queue<pair<int, int>> q;
bool valid = true;
for (int i = 1; i <= n; i++) {
for (int j : tasks[i])
q.push({j, i});
for (int j = 1; j <= mid; j++) {
if (!q.empty()) {
auto p = q.front(); q.pop();
if (i - p.second > d) {
valid = false;
break;
}
} else
break;
}
if (!valid)
break;
}
if (!q.empty())
valid = false;
if (valid)
r = mid;
else
l = mid+1;
}
cout << r << "\n";
//make assignments
queue<pair<int, int>> q;
vector<int> v[n];
for (int i = 1; i <= n; i++) {
for (int j : tasks[i])
q.push({j, i});
for (int j = 1; j <= r; j++) {
if (!q.empty()) {
v[i].push_back(q.front().first);
q.pop();
}
else
break;
}
}
for (int i = 1; i <= n; i++) {
for (int j : v[i])
cout << j << " ";
cout << "0\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |