# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
481744 | mehdi_farhadian | Job Scheduling (CEOI12_jobs) | C++14 | 339 ms | 13764 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>
#define pb push_back
#define endl '\n'
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O0")
#pragma GCC optimize("O1")
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int n, d, m;
vector<pair<int, int>> vec;
bool check(int x)
{
queue<int> q;
int last = 0;
for (int i = 1; i <= n; i++) {
while (last < vec.size() && vec[last].first == i) {
q.push(i);
last++;
}
int cnt = 0;
while (q.size() && cnt < x) {
cnt++;
int tmp = q.front();
if (i - tmp > d) {
return false;
}
q.pop();
}
}
return q.size() == 0;
}
void print(int x)
{
int ind = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < x && ind < vec.size(); j++) {
cout << vec[ind].second << " ";
ind++;
}
cout << 0 << endl;
}
}
void solve()
{
int l = -1, r = 1e6;
while (l + 1 < r) {
int m = (l + r) / 2;
if (check(m)) {
r = m;
}
else {
l = m;
}
}
cout << r << endl;
print(r);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> d >> m;
vec.resize(m);
for (int i = 0; i < m; i++) {
cin >> vec[i].first;
vec[i].second = i + 1;
}
sort(vec.begin(), vec.end());
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |