Chunk size
Statement
A lab wants to move K record files it has kept to an outside store. The size is fixed for each file, and two files may have the same size. The store takes files as chunks, every chunk sent has to be the same size, and the chunk size has to be a natural number.
Chunks are made as follows. One file is cut from the front at the chosen chunk size, and the tail that is left over and smaller than the chunk size is thrown away. Two different files cannot be joined to make one chunk. The number of chunks that come from a file is therefore the size of that file divided by the chunk size, keeping only the quotient.
At least N chunks have to be sent to the store. A larger chunk means fewer chunks from each file, so the lab sets the size of one chunk as large as it can while still being able to make at least N. The input given is always a case where at least N chunks can be made.
Write a program that, given the sizes of the K files and the number of chunks N that are needed, finds the largest chunk size that can be used.
For example, suppose the sizes of K=4 files are as in the following table and the number of chunks N that are needed is 11.
| File | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| Size | 802 | 743 | 457 | 539 |
With the chunk size at 200, the files give 4 and 3 and 2 and 2 chunks, which add up to 11. That meets the 11 that are needed. Raising the chunk size one step to 201 gives 3 and 3 and 2 and 2, which add up to 10, so the 11 are not met.
| Chunk size | File 1 | File 2 | File 3 | File 4 | Total chunks |
|---|---|---|---|---|---|
| 200 | 4 | 3 | 2 | 2 | 11 |
| 201 | 3 | 3 | 2 | 2 | 10 |
The answer in this example is therefore 200. With the chunk size at 200, taking every chunk off leaves 2 and 143 and 57 and 139 in the four files, and all of that leftover is thrown away.
Exactly N chunks are not required. A chunk size that gives more than N chunks can be used as well.
Input and Output Examples
Example 1
Input
4 11 802 743 457 539
Output
200
Example 2
Input
2 108 471 173
Output
5
Example 3
Input
3 3 1 1 1
Output
1
Input
The number of files K and the number of chunks N that are needed are given first, in that order on the first line, separated by one space. K is a natural number from 1 to 10,000, and N is a natural number from 1 to 1,000,000.
From the second line through line K+1, the size of each file is given one per line. Each size is a natural number from 1 to 2,147,483,647. The input given is always a case where at least N chunks can be made.
Output
Print the largest chunk size that can be used on the first line.
Print one number and then a newline. Do not attach any other character or space before or after it.
Requirements
- Read the input from standard input and write the answer to standard output
- Every chunk sent has to be the same size, and the chunk size is a natural number
- Two different files cannot be joined to make one chunk. The tail that is left over and smaller than the chunk size is thrown away
- Making at least N chunks is enough. Exactly N is not required
- A file size goes up to 2,147,483,647. The number of chunks that come from a file is its size divided by the chunk size as a quotient, and the remainder is thrown away
- The input is always a case where at least N chunks can be made
- Grading compares the output with the expected value down to the last character
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- There are 16 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 16 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 16 cases to solve this.
2 108 471 173
5
4 11 802 743 457 539
200
3 3 1 1 1
1
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Log in and you can see the code once you solve this problem.