Submission #1097085

#TimeUsernameProblemLanguageResultExecution timeMemory
1097085TrinhKhanhDungJob Scheduling (CEOI12_jobs)C++14
100 / 100
213 ms27728 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 + 10 #define INF (ll)1e9 #define MOD (ll)(998244353) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX = 1e6 + 10; int N, D, M; pair<int, int> a[MAX]; int ans[MAX]; void solve(){ cin >> N >> D >> M; for(int i = 1; i <= M; i++){ cin >> a[i].fi; a[i].se = i; } sort(a + 1, a + M + 1); auto OK = [&](int k) -> bool{ int day = 1, cnt = 0; for(int i = 1; i <= M; i++){ if(day - a[i].fi > D) return false; if(maximize(day, a[i].fi)) cnt = 0; cnt++; ans[a[i].se] = day; if(cnt == k){ day++; cnt = 0; } } return true; }; int l = 1, r = M; while(l < r){ int m = (l + r) >> 1; if(OK(m)) r = m; else l = m + 1; } OK(r); cout << r << '\n'; vector<vector<int>> trace(N + 3); for(int i = 1; i <= M; i++){ trace[ans[i]].push_back(i); } for(int i = 1; i <= N; i++){ for(int x: trace[i]) cout << x << ' '; cout << 0 << '\n'; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("task.inp","r",stdin); // freopen("task.out","w",stdout); int T = 1; // cin >> T; for(; T; T--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...