Bridge Building
Time limit2sMemory limit512 MB
Given x logs of length a and y logs of length b, find the largest width W so that l rows of whole logs can each have total length at least W.
- Level
Medium4 of 10
- Topics
- Implementation, Brute force
- Solved
- No attempts yet
Problem
Heavy rain regularly floods the Vonyuchka river in the village of Gadyukino, a stream that is normally easy to step over. To cross the flooded river, a floating bridge will be built from logs left over after a local businessman built his bath house.
All remaining logs have the same thickness. There are logs of length and logs of length . The bridge must consist of rows, and each row is made of one or more logs. Logs cannot be cut, because the last saw sank during the flood.
The chief engineer wants to build the widest possible bridge. The width of the bridge is the minimum width among its rows.
For example, if a bridge with seven rows is needed, and there are six logs of length 3 and ten logs of length 2, then a bridge of width 5 can be built.

Input
The input contains five natural numbers: , , , , and . All numbers do not exceed 150. The total number of logs is at least .
Output
Print one number: the maximum possible width of the bridge.