Submission #975669

# Submission time Handle Problem Language Result Execution time Memory
975669 2024-05-05T17:09:34 Z vjudge1 Job Scheduling (CEOI12_jobs) C++17
100 / 100
425 ms 17336 KB

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int n, m, d;
vector< pair<int,int> > jobs;


bool isok(int x) {//each day can process x jobs.
   int j = 0;
   for (int i = 1; i <= n; i++) {
       int count = x;
       while (j < m && jobs[j].first <= i && count > 0) {
           if (i - jobs[j].first > d) return false;
           j++;
           count--;
       }
   }
   return j == m;
}


int main() {
   cin >> n >> d >> m;
   jobs = vector< pair<int,int> >(m);
   for (int i = 0; i < m; i++) {
       cin >> jobs[i].first;
       jobs[i].second = i+1;
   }
   sort(jobs.begin(),jobs.end());
   int l = 1, r = m;
   int mid;
   int ans;
   while (l <= r) {
       mid = (l+r)/2;
       if (isok(mid)) {
           ans = mid;
           r = mid -1;
       }
       else {l = mid+1; }
   }
   cout << ans << '\n';
   int j = 0;
   for (int i = 1; i <= n; i++) {
       int count = ans;
       while (j < m && jobs[j].first <= i && count > 0) {
           cout << jobs[j].second << " ";
           j++;
           count--;
       }
       cout << 0 << endl;
   }
   return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:38:8: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |    int ans;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1884 KB Output is correct
2 Correct 37 ms 2036 KB Output is correct
3 Correct 36 ms 1880 KB Output is correct
4 Correct 39 ms 1884 KB Output is correct
5 Correct 36 ms 2040 KB Output is correct
6 Correct 36 ms 1872 KB Output is correct
7 Correct 36 ms 1872 KB Output is correct
8 Correct 37 ms 1964 KB Output is correct
9 Correct 141 ms 2128 KB Output is correct
10 Correct 141 ms 2128 KB Output is correct
11 Correct 34 ms 2140 KB Output is correct
12 Correct 69 ms 4040 KB Output is correct
13 Correct 109 ms 5700 KB Output is correct
14 Correct 159 ms 8016 KB Output is correct
15 Correct 168 ms 9556 KB Output is correct
16 Correct 237 ms 11988 KB Output is correct
17 Correct 275 ms 14072 KB Output is correct
18 Correct 286 ms 15100 KB Output is correct
19 Correct 425 ms 17336 KB Output is correct
20 Correct 269 ms 13904 KB Output is correct