Submission #540450

#TimeUsernameProblemLanguageResultExecution timeMemory
540450BhavayGoyalJob Scheduling (CEOI12_jobs)C++14
80 / 100
431 ms45448 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define vii vector<vector<int>> #define vi vector<int> #define v vector #define pii pair<int, int> #define mii map<int, int> #define umii unordered_map<int, int> #define si set<int> #define usi unordered_set<int> #define all(x) x.begin(), x.end() #define f first #define s second #define endl "\n" #define pb push_back #define MOD 1000000007 int inf = 1e9; int n, d, m; v<pii> arr(m); pair<bool, vii> isFiss(int mid) { int idx = 0; vii answer(n); for (int i = 1; i <= n; i++) { for (int j = 0; j < mid; j++) { if (arr[idx].f > i) break; if (i <= arr[idx].f + d) answer[i-1].pb(arr[idx++].s); else return {false, answer}; if (idx == m) return {true, answer}; } } return {false, answer}; } void sol() { cin >> n >> d >> m; arr = v<pii>(m); for (int i = 0; i < m; i++) { cin >> arr[i].f; arr[i].s = i+1; } sort (all(arr)); int i = 1, j = m; int ans = m; vii actualans; while (i <= j) { int mid = (i+j)/2; auto f = isFiss(mid); if (f.f) { actualans = f.s; ans = mid; j = mid-1; } else i = mid+1; } cout << ans << endl; for (int i = 0; i < n; i++) { for (auto j : actualans[i]) cout << j << " "; cout << 0 << endl; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; // cin >> t; for (int i = 1; i <= t; i++) sol(); }
#Verdict Execution timeMemoryGrader output
Fetching results...