Submission #499632

#TimeUsernameProblemLanguageResultExecution timeMemory
499632Shreyan_PaliwalJob Scheduling (CEOI12_jobs)C++17
0 / 100
341 ms7324 KiB
#include <algorithm> #include <iostream> #include <vector> using namespace std; vector<pair<int, int>> jobs; int n, d, m; bool works(int mid) { int counter = 0; int day = 1; for (int i = 0; i < jobs.size(); i++) { if (day <= jobs[i].first + d) { counter = (counter + 1) % mid; if (counter == 0) day++; } else { return false; } } return true; } int main() { // freopen("jobscheduling.in", "r", stdin); 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; } sort(jobs.begin(), jobs.end()); int lo = 1; int hi = 1000000; while (lo != hi) { int mid = (lo + hi) / 2; if (works(mid)) { hi = mid; } else { lo = mid + 1; } } cout << lo << endl; int counter = 0; // for (int i = 0; i < n; i++) { // for (int j = 0; j < lo; j++) { // if (counter < jobs.size()) // cout << jobs[counter++].second + 1 << " "; // else // break; // } // cout << 0 << endl; // } return 0; }

Compilation message (stderr)

jobs.cpp: In function 'bool works(int)':
jobs.cpp:13:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   for (int i = 0; i < jobs.size(); i++) {
      |                   ~~^~~~~~~~~~~~~
jobs.cpp: In function 'int main()':
jobs.cpp:51:7: warning: unused variable 'counter' [-Wunused-variable]
   51 |   int counter = 0;
      |       ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...