Submission #1046672

#TimeUsernameProblemLanguageResultExecution timeMemory
1046672mtshastaJob Scheduling (CEOI12_jobs)C++17
35 / 100
150 ms16248 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve() { int n, d, m; cin >> n >> d >> m; vector<int> jobs(m), o(m); vector<vector<int>> res(n); for (int i = 0; i < m; ++i) { cin >> jobs[i]; --jobs[i]; } iota(o.begin(), o.end(), 0); sort(o.begin(), o.end(), [&](int i, int j) { return jobs[i] < jobs[j]; }); auto ok = [&](int mach) -> bool { int id = 0; for (int i = 0; i < n; ++i) { if (jobs[o[id]] > i) continue; int cnt = 0; while (id < m && jobs[o[id]] + d >= i && cnt < mach) { ++id; ++cnt; } } return id == m; }; int l = 1, r = 1e6, ans; while (l <= r) { int mid = l + (r - l) / 2; if (!ok(mid)) l = mid + 1; else { ans = mid; r = mid - 1; } } cout << ans << '\n'; int id = 0; for (int i = 0; i < n; ++i) { if (jobs[o[id]] > i) continue; int cnt = 0; while (id < m && jobs[o[id]] + d >= i && cnt < ans) { cout << o[id] + 1 << ' '; ++id; ++cnt; } cout << 0 << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }

Compilation message (stderr)

jobs.cpp: In function 'void solve()':
jobs.cpp:44:47: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |         while (id < m && jobs[o[id]] + d >= i && cnt < ans) {
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...