# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527606 | _karan_gandhi | Job Scheduling (CEOI12_jobs) | C++17 | 1101 ms | 31852 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;
#define ll long long
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
void solve() {
int n, d, m; cin >> n >> d >> m;
vector<pair<int, int>> arr(m); for (int i = 0; i < m; i++) cin >> arr[i].first;
for (int i = 0; i < m; i++) arr[i].second = i + 1;
sort(all(arr));
// for (auto a : arr) {
// cout << a.first << ' ';
// }
// cout << endl;
auto possible = [&](int x) {
// check if it is possible to complete the jobs with x machines
multiset<int> s;
for (int i = 0; i < x; i++) {
s.insert(arr[i].first);
}
for (int i = x; i < m; i++) {
int last = *s.begin();
s.erase(s.find(last));
if (last + 1 - arr[i].first > d) return false;
s.insert(max(last + 1, arr[i].first));
}
return true;
};
// cout << pl(possible(1)) << endl;
int hi = m, lo = 1;
int ans = 0;
while (hi >= lo) {
int mid = (hi + lo) / 2;
if (possible(mid)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << endl;
// find a way to get answer
vector<vector<int>> days(n + 1);
multiset<int> s;
for (int i = 0; i < ans; i++) {
// cout << pl(arr[i].second) << endl;
s.insert(arr[i].first);
days[arr[i].first - 1].push_back(arr[i].second);
}
for (int i = ans; i < m; i++) {
// cout << pl(arr[i].second) << endl;
int last = *s.begin();
s.erase(s.find(last));
s.insert(max(last + 1, arr[i].first));
days[max(last + 1, arr[i].first) - 1].push_back(arr[i].second);
}
for (int i = 0; i < n; i++) {
for (auto a : days[i]) cout << a << ' ';
cout << 0 << endl;
}
}
int main() {
// freopen("socdist.in", "r", stdin);
// freopen("socdist.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
// int t; cin >> t;
// while (t--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |