제출 #260552

#제출 시각아이디문제언어결과실행 시간메모리
260552kshitij_sodaniJob Scheduling (CEOI12_jobs)C++14
100 / 100
423 ms16984 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
int n,d;
int m;
vector<int> ac[100001];
bool check(int mid,int xx=0){
	int cur=1;
	int le=mid;
	for(int j=1;j<=n;j++){

		for(auto jj:ac[j]){
			
			if(cur>j+d){
				return false;
			}
			le-=1;
			if(xx){
				cout<<jj+1<<" ";
			}
			if(le==0){
				if(xx){
					cout<<0<<endl;
				}
				cur+=1;
				le=mid;
			}
			
		}
		if(cur==j){
			if(xx){
				cout<<0<<endl;
			}
			cur+=1;
			le=mid;
		}
	}


}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>d>>m;
	for(int i=0;i<m;i++){
		int bb;
		cin>>bb;
		ac[bb].pb(i);
	}
	int low=1;
	int high=m;
	while(low<high-1){
		int mid=(low+high)/2;
		if(check(mid)){
			high=mid;
		}
		else{
			low=mid;
		}
	}
	int ans=high;
	if(check(low)){
		ans=min(ans,low);
	}
	cout<<ans<<endl;
	check(ans,1);








	return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/

컴파일 시 표준 에러 (stderr) 메시지

jobs.cpp: In function 'bool check(int, int)':
jobs.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...