Submission #447987

# Submission time Handle Problem Language Result Execution time Memory
447987 2021-07-28T11:45:10 Z Vishnu Job Scheduling (CEOI12_jobs) Java 11
Compilation error
0 ms 0 KB
import java.io.IOException;
import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;


public class JobScheduling {

	public static void main(String[] args) throws IOException {
		Scanner myObj = new Scanner(System.in);
		int n = myObj.nextInt();
		int d = myObj.nextInt();
		int m = myObj.nextInt();

		int [][] arr = new int [m][2];
		for (int index = 0; index < m; index++) {
			arr[index][0] = myObj.nextInt();
			arr[index][1] = index + 1;
		}
		Arrays.sort(arr, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				Integer pos1 = o1[0];
				Integer pos2 = o2[0];
						
				if (pos1 > pos2) return 1;
				else if (pos1 == pos2) return 0;
				else return -1;
			}
		});
		
		
		int a = 1;
		int b = m;
		int mid;
		while (a != b) {
			mid = (a+b)/2;
			if (works(mid, m, arr, d)) {
				b = mid;
			}
			else {
				a = mid + 1;
			}
		}
		System.out.println(a);
		
		
		String output = "";
		int [] mach = new int [a];
		int machine = 0;
		for (int index = 0; index < m; index++) {
			mach[machine] += 1;
			output = output + String.valueOf(arr[index][1]);
			machine++;
			output = output + " ";
			if (machine == a) {
				Arrays.sort(mach);
				machine = 0;
				output = output + "0\n";
			}
		}
		
		int needFinish = n - (m/a);
		for (int index = 0; index < needFinish; index++) {
			output = output + "0\n";
		}
		System.out.println(output);
	}

	public static boolean works (int mid, int m, int [][] request_arr, int allowDelay) {		
		int [] mach = new int [mid];
		int delay = 0;
		int machine = 0;
		for (int index = 0; index < m; index++) {
			mach[machine] += 1;
			delay = mach[machine] - request_arr[index][0];
			if (delay > allowDelay) {
				return false;
			}
			machine++;
			if (machine == mid) {
				Arrays.sort(mach);
				machine = 0;
			}
		}
		return true;
	}
}

Compilation message

jobs.java:9: error: class JobScheduling is public, should be declared in a file named JobScheduling.java
public class JobScheduling {
       ^
1 error