Advertisement
saurav_kalsoor

Optimize Workforce - JAVA

Dec 8th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. // Author : Saurav Kalsoor
  2.  
  3. import java.util.*;
  4.  
  5. public class Test {
  6.  
  7.     static Scanner sc = new Scanner(System.in);
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         int n = sc.nextInt();
  12.         int racks[] = new int[n];
  13.  
  14.         for (int i = 0; i < n; i++) {
  15.             racks[i] = sc.nextInt();
  16.         }
  17.  
  18.         int seniorCapacity = sc.nextInt();
  19.         int juniorCapacity = sc.nextInt();
  20.         int result[][] = optimizeWorkforce(n, racks, seniorCapacity, juniorCapacity);
  21.  
  22.         for(int i=0; i < n; i++){
  23.             System.out.println("senior : " + result[i][0] + ", junior : " + result[i][1]);
  24.         }
  25.  
  26.     }
  27.  
  28.     public static int[][] optimizeWorkforce(int n, int[] racks, int seniorCapacity, int juniorCapacity) {
  29.         int result[][] = new int[n][2];
  30.  
  31.         for(int i=0; i < n; i++){
  32.             result[i] = getCount(racks[i], seniorCapacity, juniorCapacity);
  33.         }
  34.         return result;
  35.     }
  36.  
  37.     public static int[] getCount(int rackSize, int seniorCapacity, int juniorCapacity){
  38.         int count[] = new int[2];
  39.         count[0] = (int)Math.ceil(rackSize/(seniorCapacity*1.0));
  40.         count[1] = 0;
  41.  
  42.         int minExcess = count[0]*seniorCapacity - rackSize;
  43.  
  44.         for(int seniors = 1; seniors <= rackSize/seniorCapacity; seniors++){
  45.  
  46.             int juniors = (int)Math.ceil((rackSize - seniors*seniorCapacity)/(1.0*juniorCapacity));
  47.             int excess = (seniors*seniorCapacity + juniors*juniorCapacity) - rackSize;
  48.  
  49.             if(excess <= minExcess){
  50.                 minExcess = excess;
  51.                 count[0] = seniors;
  52.                 count[1] = juniors;
  53.             }
  54.         }
  55.  
  56.         return count;
  57.     }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement