Integer Browser

Integer Browser
Aakash has invented a new kind of Web Browser known as an Integer Browser.

It downloads files in integer speeds.

The way it works is as follows:

Suppose there are 12 files downloading with an internet speed of 100 kb/s. Then the speed of download for each file is the floor of 100/12 i.e. 8 kb/s.
Now suppose we have a file of 27 kb downloading at a speed of 8 kb/s. The time taken for the download of this file is the ceiling of 27/8 which is 4 seconds.
Now, let’s assume that we have 8 files of different sizes, and an internet speed of 23 kb/s.
The file sizes are 84, 53, 96, 101, 53, 87, 89, and 42 KB respectively.

How long will it take for the files to download? Note that once a file has finished downloading,
then the speed of download increases for the other files.

The calculation is outlined in the diagram below:

![alt text][1]
enter image description here
First, the speed of each file downloading is 2 kb/s. The download happens parallely. It takes 21 seconds for the file of size 42 KB to be downloaded.

And 42 KB of each of the rest of the files have been downloaded. Now, only 7 files are left to be downloaded.

This time the download speed is 3 kb/s.

It takes 4 seconds to download the remaining 11 kb of two of the files. (Remember point 2.)

This process is repeated until all files are downloaded. As you can see, it takes a total of 37 seconds for all files to be downloaded.

Input Format

The first line of input consists of an integer t. This is the number of test cases.

For each test case, the first line of input contains two space separated integers n and s.
Here n is the number of files and s is the internet speed (in KB/s). Then the next line contains n space separated integers which are the sizes (in KB) of the n files.
Here n will always be less than s, because, if not, then s/n will be 0 and no files could be downloaded.

Output Format

For each test case, output a single integer which is the time taken by the Integer Browser to download all the files.

Constraints

0 < t <= 1000 (This is the number of test cases)

0 < n <= 10000 (This is the number of files)

0 < s <= 30000 (This is the speed of internet in kb/s)

0 < Xi < 100000 (This is the size of each files in kb)

Sample input:
3

8 23

84 53 96 101 53 87 89 42

9 17

79 64 23 53 47 103 100 109 68

7 15

30 24 26 25 100 98 78

Sample Output:
37
56
30

package mango.exception;

import java.util.Arrays;
import java.util.LinkedHashMap;

public class IntegerBrowserDownloading {

public static void main(String[] args) {
	@SuppressWarnings("resource")
	java.util.Scanner scanner=new java.util.Scanner(System.in);
	System.out.println("Enter the Number of test cases: ");
	Integer testCases=Integer.parseInt(scanner.nextLine());
	LinkedHashMap<String,Integer[]> fileSizesMap=new LinkedHashMap<>();
	for(int i=1;i<=testCases;i++){
		String tempCountSpeed=scanner.nextLine();
		int count = Integer.parseInt(tempCountSpeed.split(" ")[0]);
		Integer[] listOfFile=new Integer[count];
		String[] array = scanner.nextLine().split(" ");
		int j=0;
		for (String s : array) {
			if(s!=null && !s.equals("")){
				listOfFile[j]=Integer.parseInt(s);
				j++;
			}
		}
		Arrays.sort(listOfFile);
		fileSizesMap.put(tempCountSpeed, listOfFile);
	}
	// start processing here
	fileSizesMap.forEach((countSpeed,fileSizeArr)->{
		Integer count = Integer.parseInt(countSpeed.split(" ")[0]);
		Integer Speed = Integer.parseInt(countSpeed.split(" ")[1]);
		Integer phaseSpeedSum=0;
		int phaseSpeed = 0 ;
		Integer actualSpeed;
		Integer holder;
		Integer adCount=count;
		//84 53 96 101 53 87 89 42
		for(int j=0;j<count;j++){
			actualSpeed=Speed/adCount;
			if(fileSizeArr[j]%actualSpeed==0)
				phaseSpeed = fileSizeArr[j]/actualSpeed;
			else
				phaseSpeed = (fileSizeArr[j]/actualSpeed)+1;	
			holder=fileSizeArr[j];
			for(int i=0;i<count;i++){
				if(fileSizeArr[i]!=0){
					Integer tempsize = fileSizeArr[i];
					tempsize=tempsize-holder;
					fileSizeArr[i]=tempsize;
					if(tempsize==0){
						--adCount;
					}
				}

			}
			phaseSpeedSum=phaseSpeedSum+phaseSpeed;
		}
		System.out.println(phaseSpeedSum);
		
	});
	
	
}

}