Submission #999555

# Submission time Handle Problem Language Result Execution time Memory
999555 2024-06-15T19:29:07 Z m_bezrutchka Job Scheduling (CEOI12_jobs) C++14
100 / 100
365 ms 20052 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;

int n, d, m;
pair<int, int> requests[10*MAXN];
vector <int> resp[MAXN];

bool possible(int k) {
  if (k <= 0) return false;
  if (k >= m) return true;
  int pos = 0;
  for (int day = 1; day <= n; day++) {
    resp[day].clear();
    for (int j = 0; j < k; j++) {
      if (pos >= m) break;
      int day_pos = requests[pos].first;
      int idx_pos = requests[pos].second;
      if (day_pos > day) break;
      if (day_pos + d < day) return false;
      resp[day].push_back(idx_pos);
      pos++;
    }
  }
  return (pos >= m);
}

int b_search() {
  int l = 0, r = m;
  while (l < r) {
    int mid = (l + r) / 2;
    if (possible(mid)) r = mid;
    else l = mid + 1;
  }
  return r;
}

int main() {
  cin >> n >> d >> m;
  int x;
  for (int i = 0; i < m; i++) {
    cin >> x;
    requests[i] = {x, i + 1};
  }
  sort(requests, requests + m);
  int ans = b_search();
  cout << ans << endl;
  
  possible(ans);
  for (int i = 1; i <= n; i++) {
    for (int x : resp[i]) cout << x << " ";
    cout << 0 << endl;
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 5724 KB Output is correct
2 Correct 31 ms 5736 KB Output is correct
3 Correct 29 ms 5720 KB Output is correct
4 Correct 29 ms 5976 KB Output is correct
5 Correct 29 ms 5716 KB Output is correct
6 Correct 30 ms 5724 KB Output is correct
7 Correct 31 ms 5740 KB Output is correct
8 Correct 30 ms 5748 KB Output is correct
9 Correct 125 ms 5864 KB Output is correct
10 Correct 127 ms 6000 KB Output is correct
11 Correct 29 ms 5716 KB Output is correct
12 Correct 57 ms 7004 KB Output is correct
13 Correct 87 ms 10584 KB Output is correct
14 Correct 133 ms 12116 KB Output is correct
15 Correct 155 ms 12880 KB Output is correct
16 Correct 227 ms 16240 KB Output is correct
17 Correct 237 ms 19028 KB Output is correct
18 Correct 240 ms 18536 KB Output is correct
19 Correct 365 ms 20052 KB Output is correct
20 Correct 227 ms 19028 KB Output is correct