Submission #424778

#TimeUsernameProblemLanguageResultExecution timeMemory
424778aris12345678Job Scheduling (CEOI12_jobs)C++14
100 / 100
329 ms17244 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 100005; const int mxM = 1000005; pair<int, int> day[mxM]; bool check(int x, int m, int d, int n) { int j = 0; for(int i = 1; i <= n+1; i++) { int md = x; while(md-- && j < m && day[j].first <= i) { if(i > d+day[j].first) return false; j++; } } return true; } int main() { int n, d, m; scanf("%d %d %d", &n, &d, &m); for(int i = 0; i < m; i++) { scanf("%d", &day[i].first); day[i].second = i+1; } sort(day, day+m); int lb = 1, rb = m, md, ans = -1; while(lb <= rb) { md = (lb+rb)/2; if(check(md, m, d, n)) { ans = md; rb = md-1; } else lb = md+1; } printf("%d\n", ans); int j = 0; for(int i = 1; i <= n; i++) { int x = ans; while(x-- && j < m && day[j].first <= i) { printf("%d ", day[j].second); j++; } printf("0\n"); } return 0; }

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d %d %d", &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d", &day[i].first);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...