Submission #527738

#TimeUsernameProblemLanguageResultExecution timeMemory
527738_karan_gandhiJob Scheduling (CEOI12_jobs)C++17
95 / 100
357 ms34588 KiB
#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 int cnt = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < x; j++) { if (arr[cnt].first > i) { break; } if (arr[cnt].first + d >= i) { cnt++; } else { return false; } if (cnt == m) return true; } } return false; }; // cout << pl(possible(2)) << 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 timeMemoryGrader output
Fetching results...