Submission #556845

#TimeUsernameProblemLanguageResultExecution timeMemory
556845JomnoiJob Scheduling (CEOI12_jobs)C++17
45 / 100
212 ms13892 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_M = 1e6 + 10; int N, D, M; int S[MAX_M], id[MAX_M]; bool solve(int mid) { int days = 1, cnt = mid; for(int i = 1; i <= M; i++) { if(days > S[id[i]] + D) { return false; } cnt--; if(cnt == 0) { cnt = mid; days++; } } return days <= N; } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> N >> D >> M; for(int i = 1; i <= M; i++) { cin >> S[i]; id[i] = i; } sort(id + 1, id + M + 1, [&](const int &a, const int &b) { return S[a] < S[b]; }); int l = 1, r = M, ans = -1; while(l <= r) { int mid = (l + r) / 2; if(solve(mid) == true) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << '\n'; for(int i = 1, j = 1; i <= N; i++) { for(int k = 0; j <= M and k < ans; j++, k++) { cout << id[j] << ' '; } cout << "0\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...