제출 #642587

#제출 시각아이디문제언어결과실행 시간메모리
642587accidentacJob Scheduling (CEOI12_jobs)C++17
0 / 100
293 ms14420 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

// return true if can use count no. of machines to handle all jobs
bool ok(int count, int n, int d, int m, vector<array<int, 2>>& jobs) {
  queue<int> q;
  for (int i = 1, j = 0; i <= n; i++) {
    while (j < m && jobs[j][0] == i) {
      q.push(j++);
    }
    if (q.size() && i - jobs[q.front()][0] > d) return false;
    for (int rep = 0; rep < count && !q.empty(); rep++) {
      q.pop();
    }
  }
  return true;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, d, m;
  cin >> n >> d >> m;
  vector<array<int, 2>> jobs(m);
  for (int i = 0; i < m; i++) {
    cin >> jobs[i][0];
    jobs[i][1] = i + 1;
  }
  sort(jobs.begin(), jobs.end());
  int lo = 1, hi = m, ans = m;
  while (lo <= hi) {
    int mid = lo + (hi - lo) / 2;
    if (ok(mid, n, d, m, jobs)) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...