Submission #1153902

#TimeUsernameProblemLanguageResultExecution timeMemory
1153902zhasynJob Scheduling (CEOI12_jobs)C++20
21 / 100
357 ms41024 KiB
//#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e6 + 100, M = 1e7 + 10, len = 21, inf = 1e18;
const ll mod = 1000000009LL;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll um(ll a, ll b){
	return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
ll n, d, from = 0, m;
pll a[N];
vector <vector <ll>> vec;
bool check(ll x){
	ll st = 1;
	for(ll i = 1; i <= n; i++){
		if((ll)vec.size() - from >= d) return 0;
		vector <ll> cur;
		while(st <= m){
			if(a[st].F == i){
				cur.pb(a[st].S);
				st++;
			} else break;
		}
		vec.pb(cur);
		ll xx = x;
		while(xx--){
			while(from < (ll)vec.size()){
				if(vec[from].size() == 0) from++;
				else break;
			}
			if(from >= (ll)vec.size()) break;
			vec[from].pop_back();
			while(from < (ll)vec.size()){
				if(vec[from].size() == 0) from++;
				else break;
			}
		}
	}
	if(from == (ll)vec.size()) return true;
	return false;
}

void make(ll x){
	ll st = 1;
	for(ll i = 1; i <= n; i++){
		vector <ll> cur;
		while(st <= m){
			if(a[st].F == i){
				cur.pb(a[st].S);
				st++;
			} else break;
		}
		vec.pb(cur);
		ll xx = x;
		while(xx--){
			while(from < (ll)vec.size()){
				if(vec[from].size() == 0) from++;
				else break;
			}
			if(from >= (ll)vec.size()) break;
			cout << vec[from].back() << " ";
			vec[from].pop_back();
			while(from < (ll)vec.size()){
				if(vec[from].size() == 0) from++;
				else break;
			}
		}
		cout << 0 << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  	cin >> n >> d >> m;
  	for(int i = 1; i <= m; i++){
  		cin >> a[i].F;
  		a[i].S = i;
  	}
  	sort(a + 1, a + 1 + m);
  	ll l = 0, r = m;
  	while(r - l > 1){
  		ll mid = (l + r) / 2;
  		vec.clear();
  		from = 0;
  		if(check(mid)) r = mid;
  		else l = mid;
  	}
  	cout << r << endl;
  	make(r);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...