# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1133498 | chanonon | Job Scheduling (CEOI12_jobs) | Java | 0 ms | 0 KiB |
import java.util.Scanner;
import java.util.Arrays;
public class jobs {
static int a=0;
static int b=0;
static int c=0;
static int []m;
public static void main(String args[]) {
Scanner in=new Scanner(System.in);
int in1= in.nextInt();
int in2= in.nextInt();
int in3= in.nextInt();
m=new int[in3];
Arrays.sort(m1);
for(int i=0;i<in3;i++){
m[i]=in.nextInt();
}
int[] m1 = Arrays.copyOf(m, m.length);
a=in1;
b=in2;
c=in3;
int []m3=new int[in3];
for(int i=0;i<in3;i++){
m3[i]=sort(m1[i]);
}
int l=0;
int r=in3-1;
while(l<r){
int mid=(l+r)/2;
if(check(m,mid)==false){
l=1+mid;
}
else{
r=mid;
}
}
System.out.println(l);
for(int j=0;j<in1;j++){
for(int i=0;i<l;i++){
if((i+l*j)<m3.length){System.out.print(m3[i+l*j]+" ");}
}
System.out.println(0);
}
}
public static boolean check(int []x,int num1){
Arrays.sort(x);
for(int i=0;i<c;i++){
x[i]+=b;
}
for(int i=0;i<c;i++){
x[i]-=(i+num1)/num1;
if(i==c-1&&(i+num1)/num1>a){
return false;
}
}
for(int i=0;i<c;i++){
if(x[i]<0){
return false;
}
}
return true;
}
public static int sort(int o){
for(int i=0;i<c;i++){
if(o==m[i]){
m[i]=-1;
return m[i];
}
}
return 0;
}
}