# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527610 | _karan_gandhi | Job Scheduling (CEOI12_jobs) | C++17 | 1095 ms | 35640 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() {
ll int n, d, m; cin >> n >> d >> m;
vector<pair<ll int, ll int>> arr(m); for (ll int i = 0; i < m; i++) cin >> arr[i].first;
for (ll int i = 0; i < m; i++) arr[i].second = i + 1;
sort(all(arr));
auto possible = [&](ll int x) {
// check if it is possible to complete the jobs with x machines
multiset<ll int> s;
for (ll int i = 0; i < x; i++) {
s.insert(arr[i].first);
}
for (ll int i = x; i < m; i++) {
ll 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;
ll int hi = m, lo = 1;
ll int ans = 0;
while (hi >= lo) {
ll 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<ll int>> days(n + 1);
multiset<ll int> s;
for (ll 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 (ll int i = ans; i < m; i++) {
ll 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 (ll int i = 0; i < n; i++) {
for (ll int 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);
// ll int t; cin >> t;
// while (t--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |