Submission #1020134

#TimeUsernameProblemLanguageResultExecution timeMemory
1020134adrielcpJob Scheduling (CEOI12_jobs)C++17
100 / 100
287 ms22980 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
#define int ll
#define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// const ll INF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const lld PI = acos(-1.0);
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
#define debug(x) cout << #x << ": " << x << endl;
#define add(a, b) a += b, a %= mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define all(x) x.begin(),x.end()

void solve() {
  int n,d,m;cin>>n>>d>>m;
  vector<pair<int, int>> a(m);
  for (int i = 0; i < m; i++) cin >> a[i].first, a[i].second = i;
  sort(all(a));
  
  // vector<pair<int, int>> s;
  int cnt = 0;
  function<bool(int, bool)> chk = [&](int k, bool ou) {
    int day = 1;
    for (int i = 0; i < m;) {
      int l = i;
      for (;i<min(l+k, m); i++) {
        if (a[i].first > day) break;
        if (ou) {
          cout << a[i].second+1 << " ";
        }
        if (a[i].first + d < day) return 0;  
      }
      if (ou) {
        cnt++;
        cout << 0 << endl;
      }
      day++;
    }
    return 1;
  };

  int l = 1, r = m;
  int ans = -1;
  while (l <= r) {
    int mid = (l+r)>>1;
    if (chk(mid,0)) {
      r = mid-1;
      ans = mid;
    } else l = mid+1;
  }
  cout << ans << endl;
  chk(ans, 1);
  for (int i = cnt; i < n; i++) cout << 0 << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);cin.tie(0);
  int t=1;
  while(t--) solve();

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...