Submission #527610

#TimeUsernameProblemLanguageResultExecution timeMemory
527610_karan_gandhiJob Scheduling (CEOI12_jobs)C++17
70 / 100
1095 ms35640 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 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 timeMemoryGrader output
Fetching results...