@@ -0,0 +1,1031 @@
+package com.hackerearth;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.Scanner;%0A%0A/**%0A * For a task i, it takes one day to start a job, and ki days to complete.%0A * For given n tasks, schedule it effectively such that it takes min days to complete%0A * %3Cp/%3E%0A * input:%0A * 2 (No of tasks)%0A * 3%0A * 1%0A * %3Cp/%3E%0A * output:%0A * 4%0A */%0Apublic class TaskScheduler %7B%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A%0A        Scanner scanner = new Scanner(System.in);%0A        int K = scanner.nextInt();%0A        Integer%5B%5D queue = new Integer%5BK%5D;%0A%0A        for (int i = 0; i %3C K; i++) %7B%0A            queue%5Bi%5D = scanner.nextInt();%0A        %7D%0A%0A        Arrays.sort(queue, Collections.reverseOrder());%0A%0A%0A        int time = 0;%0A        int pendingTime = 0;%0A%0A        for (Integer i : queue) %7B%0A            if (pendingTime %3E 0)%0A                pendingTime--;%0A            time = time + 1;%0A            if (pendingTime %3C i)%0A                pendingTime = i;%0A        %7D%0A%0A%0A        System.out.println(time + pendingTime);%0A    %7D%0A%7D%0A

For a task i, it takes one day to start a job, and ki days to complete. For given n tasks, schedule it effectively such that it takes min days to complete