Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Author : Saurav Kalsoor
- import java.util.*;
- public class Test {
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- int n = sc.nextInt();
- int racks[] = new int[n];
- for (int i = 0; i < n; i++) {
- racks[i] = sc.nextInt();
- }
- int seniorCapacity = sc.nextInt();
- int juniorCapacity = sc.nextInt();
- int result[][] = optimizeWorkforce(n, racks, seniorCapacity, juniorCapacity);
- for(int i=0; i < n; i++){
- System.out.println("senior : " + result[i][0] + ", junior : " + result[i][1]);
- }
- }
- public static int[][] optimizeWorkforce(int n, int[] racks, int seniorCapacity, int juniorCapacity) {
- int result[][] = new int[n][2];
- for(int i=0; i < n; i++){
- result[i] = getCount(racks[i], seniorCapacity, juniorCapacity);
- }
- return result;
- }
- public static int[] getCount(int rackSize, int seniorCapacity, int juniorCapacity){
- int count[] = new int[2];
- count[0] = (int)Math.ceil(rackSize/(seniorCapacity*1.0));
- count[1] = 0;
- int minExcess = count[0]*seniorCapacity - rackSize;
- for(int seniors = 1; seniors <= rackSize/seniorCapacity; seniors++){
- int juniors = (int)Math.ceil((rackSize - seniors*seniorCapacity)/(1.0*juniorCapacity));
- int excess = (seniors*seniorCapacity + juniors*juniorCapacity) - rackSize;
- if(excess <= minExcess){
- minExcess = excess;
- count[0] = seniors;
- count[1] = juniors;
- }
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement