# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051872 | manhlinh1501 | Job Scheduling (CEOI12_jobs) | C++17 | 76 ms | 38228 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int MAXN = 1e6 + 5;
int N, M, D;
int a[MAXN];
vector<int> g[MAXN];
bool check(int K) {
int cnt = 0;
for(int i = 1; i <= N; i++) {
cnt += g[i].size();
if(cnt > K * D) return false;
cnt = cnt - min(cnt, K);
}
return true;
}
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> D >> M;
for(int i = 1; i <= M; i++) {
cin >> a[i];
}
for(int i = 1; i <= M; i++) g[a[i]].emplace_back(i);
int low = 1, high = M;
int ans = -1;
while(low <= high) {
int mid = (low + high) / 2;
if(check(mid)) {
ans = mid;
high = mid - 1;
} else low = mid + 1;
}
cout << ans << "\n";
queue<int> Q;
for(int i = 1; i <= N; i++) {
for(int p : g[i])
Q.emplace(p);
int cnt = 0;
while(!Q.empty() and cnt < ans) {
int p = Q.front();
cout << p << " ";
Q.pop();
cnt++;
}
cout << "0\n";
}
return (0 ^ 0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |