Submission #1004387

#TimeUsernameProblemLanguageResultExecution timeMemory
1004387u_suck_oJob Scheduling (CEOI12_jobs)C++17
0 / 100
145 ms11092 KiB
#include <iostream> #include <vector> #include <queue> #define MAXN 100005 using namespace std; int n, d, m; vector<int> tasks[MAXN]; int main() { cin >> n >> d >> m; for (int i = 1; i <= m; i++) { int x; cin >> x; tasks[x].push_back(i); } //binary search on answer int l = 1, r = m; while (l < r) { int mid = (l+r)/2; queue<pair<int, int>> q; bool valid = true; for (int i = 1; i <= n; i++) { for (int j : tasks[i]) q.push({j, i}); for (int j = 1; j <= mid; j++) { if (!q.empty()) { auto p = q.front(); q.pop(); if (i - p.second > d) { valid = false; break; } } else break; } if (!valid) break; } if (!q.empty()) valid = false; if (valid) r = mid; else l = mid+1; } cout << r << "\n"; /*//make assignments queue<pair<int, int>> q; vector<int> v[n]; for (int i = 1; i <= n; i++) { for (int j : tasks[i]) q.push({j, i}); for (int j = 1; j <= r; j++) { if (!q.empty()) { v[i].push_back(q.front().first); q.pop(); } else break; } } for (int i = 1; i <= n; i++) { for (int j : v[i]) cout << j << " "; cout << "0\n"; }*/ }
#Verdict Execution timeMemoryGrader output
Fetching results...