Submission #498624

# Submission time Handle Problem Language Result Execution time Memory
498624 2021-12-25T20:52:27 Z sohomdutta Job Scheduling (CEOI12_jobs) Java 11
0 / 100
155 ms 12428 KB
import java.util.*;
class jobschedule {
    static int n, d, m;
    static int [] requests;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        d = sc.nextInt();
        m = sc.nextInt();
        requests = new int[m];
        for(int i = 0; i < m; i++){
            requests[i]=sc.nextInt();
        }
        Arrays.sort(requests);

        //System.out.println(Arrays.toString(requests));
        int left = 1;
        int right = m;
        while(left!=right){
            int mid = left + (right-left)/2;
            if(works(mid)){
                right=mid;
            }else{
                left=mid+1;
            }
        }

        System.out.println(left);
        for(int i = 0; i < n; i++){
            System.out.println(0);
        }
    }
    public static boolean works(int machines){
        int [] timeArray = new int[m];
        int time = 1;
        timeArray[0]=1;
        int currentMachines = machines-1;
        for(int i = 1; i < m; i++){
            if(requests[i]==requests[i-1]){
                if(currentMachines==0){
                    currentMachines=machines-1;
                    time++;
                    timeArray[i]=time;
                }else{
                    currentMachines--;
                    timeArray[i]=time;
                }
            }else{
                time=Math.max(time+1, requests[i]);
                timeArray[i]=time;
                currentMachines=machines-1;
            }
        }
        for(int i = 0; i < m; i++){
            if(timeArray[i]-requests[i]>d){
                return false;
            }
        }
        return true;
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 143 ms 12072 KB Execution failed because the return code was nonzero
2 Runtime error 141 ms 11948 KB Execution failed because the return code was nonzero
3 Runtime error 150 ms 12396 KB Execution failed because the return code was nonzero
4 Runtime error 143 ms 11924 KB Execution failed because the return code was nonzero
5 Runtime error 133 ms 12160 KB Execution failed because the return code was nonzero
6 Runtime error 140 ms 12428 KB Execution failed because the return code was nonzero
7 Runtime error 144 ms 12284 KB Execution failed because the return code was nonzero
8 Runtime error 132 ms 12232 KB Execution failed because the return code was nonzero
9 Runtime error 154 ms 12252 KB Execution failed because the return code was nonzero
10 Runtime error 137 ms 12252 KB Execution failed because the return code was nonzero
11 Runtime error 153 ms 11976 KB Execution failed because the return code was nonzero
12 Runtime error 155 ms 12228 KB Execution failed because the return code was nonzero
13 Runtime error 137 ms 12032 KB Execution failed because the return code was nonzero
14 Runtime error 130 ms 12052 KB Execution failed because the return code was nonzero
15 Runtime error 147 ms 11920 KB Execution failed because the return code was nonzero
16 Runtime error 145 ms 12136 KB Execution failed because the return code was nonzero
17 Runtime error 139 ms 12096 KB Execution failed because the return code was nonzero
18 Runtime error 132 ms 12032 KB Execution failed because the return code was nonzero
19 Runtime error 143 ms 12044 KB Execution failed because the return code was nonzero
20 Runtime error 142 ms 12248 KB Execution failed because the return code was nonzero