Ggeureuda Gimgganom
InterviewTime limit1.5sMemory limit1024 MB
Given N rolls, cut K cm off each end (one end if shorter than 2K, discard if at most K), then find the largest piece length P so the trimmed rolls yield at least M pieces.
- Level
Medium6 of 10
- Topics
- Binary search, Array, Math, Implementation
- Solved
- No attempts yet
Problem
Jeongrae runs a gimbap factory that makes gimbap to supply to the gimbap restaurant "Ggeureuda Gimgganom". Jeongrae calls the two ends of a gimbap roll its "tails", and a gimbap roll with its tails cut off a "trimmed gimbap".
The factory processes gimbap rolls: it cuts off the tails and turns the trimmed gimbap into gimbap pieces. When cutting off the tails, it cuts a uniform cm from both ends. If a roll is shorter than cm, so that only one end can be cut, only one tail is cut off. If a roll is cm or shorter, it is discarded.
Every trimmed gimbap is then cut into pieces of a constant length , giving cm gimbap pieces. must be a positive integer. Jeongrae wants to make at least gimbap pieces cut to the constant length cm. Find the value should be set to when is to be as long as possible.
Input
The first line gives the number of gimbap rolls to trim, , the tail length , and the minimum number of gimbap pieces, . (, , , , are integers)
Starting from the second line, the lengths of gimbap rolls are given. (, is an integer)
Output
Print , the maximum possible length of a gimbap piece. If no such exists, print -1.