# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
727557 | buffering | Job Scheduling (CEOI12_jobs) | C++17 | 550 ms | 31312 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;
void IO(string s = "")
{
if (s == "")
{
freopen("input.txt", "r", stdin);
freopen("output 2.txt", "w", stdout);
}
if (s != "")
{
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
}
bool check(vector<pair<long long, long long>>& req, int machines, long long d, long long n, bool print) {
if (machines < 1) return false;
if (n * machines < req.size()) return false;
vector<vector<long long>> days;
for (int i = 0; i < n; i++) {
days.push_back({});
}
long long delay = 0;
long long day = 1;
long long i = 0;
while (i < req.size() && day < n) {
if (days[day - 1].size() == machines || req[i].first > day) {
day++;
if (day == n) break;
}
days[day - 1].push_back(req[i].second);
delay = max(delay, abs(req[i].first - day));
i++;
}
if (delay > d) return false;
if (print) {
for (auto v: days) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << 0 << endl;
}
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
//IO();
long long n; long long d; long long m;
cin >> n >> d >> m;
vector<pair<long long, long long>> req(m);
for (int i = 0; i < m; i++) {
cin >> req[i].first;
req[i].second = i + 1;
}
sort(req.begin(), req.end());
long long lo = 1; long long hi = 1e5;
bool w = false;
while (lo <= hi) {
long long mid = (lo + hi)/2;
if (check(req, mid, d, n, 0)) {
if (!check(req, mid - 1, d, n, 0)) {
cout << mid << endl;
check(req, mid, d, n, 1);
w = true;
break;
}
else hi = mid - 1;
}
else lo = mid + 1;
}
assert(w);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |