# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1277587 | vlqd0 | Job Scheduling (CEOI12_jobs) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
void setIO(string name = "") {
if (name.length()) {
(void)!freopen((name + ".in").c_str(), "r", stdin);
(void)!freopen((name + ".out").c_str(), "w", stdout);
}
}
int n, d, m;
vector<vector<int>> days;
bool check(int original){
queue<pair<int, int>> q;
int remaining, machines;
for (int i = 1; i <= n; i++){
machines = original;
while(!q.empty() and machines > 0){
if (i - d > q.front().first) return false;
if (q.front().second <= machines){
machines -= q.front().second;
q.pop();
} else {
q.front().second -= machines;
machines = 0;
}
}
remaining = days[i].size();
if (machines > 0) remaining = max(0, remaining - machines);
if (remaining > 0) q.push({i, remaining});
}
if (!q.empty()) return false;
return true;
}
void solve(){
cin >> n >> d >> m;
days.resize(n + 1);
int c;
for (int i = 1; i <= m; i++){
cin >> c;
days[c].push_back(i);
}
int l = 1, r = 1e6, mid, ans = INT_MAX;
while(l <= r){
mid = (l + r) / 2;
if (check(mid)){
ans = min(ans, mid);
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << ans << "\n";
queue<int> q;
int m;
for (int i = 1; i <= n; i++){
if (i <= n - d){
m = ans;
while(!q.empty() and m > 0){
cout << q.front() << " ";
m--;
q.pop();
}
for (int j : days[i]){
if (m > 0) {cout << j << " "; m--;}
else q.push(j);
}
}
cout << 0 << "\n";
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
//setIO("swap");
solve();
return 0;
}