Bridge Building

시간 제한5.5초메모리 제한1024 MB

요약
길이 a인 통나무 x개와 길이 b인 통나무 y개로 l개의 줄을 만들 때, 각 줄 너비의 최솟값을 최대로 하는 값을 구한다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 수학, 완전 탐색
정답자
아직 제출이 없습니다

문제

A long time ago in 2009...

In the village Zaykino, heavy rain is common. After such rain, the river Dubrovka which can usually be just stepped over, overflows. To be able to get across the flooded river, the villagers want to build a floating bridge. Luckily, after construction of a bath-house which belongs to a businessman who settled nearby, there are some logs left.

All remaining logs have the same thickness. There are xx logs of length aa and yy logs of length bb.

The bridge will consist of ll rows, each of which will be composed of one or more logs. Unfortunately, the last saw in Zaykino drowned in Dubrovka during the previous overflow and disappeared, so the logs can not be cut into pieces.

The chief engineer wants to build a bridge of maximum possible width. The width of a bridge is determined by the minimum width of a row of logs in it.

For example, if the villagers want to build a bridge of seven rows, and there are six logs of length 33 and ten logs of length 22, then they can build a bridge of width 55.

입력

Input contains one or more test cases. Each test case consists of five positive integers xx, aa, yy, bb and ll. Each of these numbers does not exceed 500500. The total number of logs in each test case is at least ll.

Let d=max⁡(x,a,y,b,l)d = \max (x, a, y, b, l). It is guaranteed that the sum of dd over all the tests is at most 50005000.

출력

For each test case, print an integer on a separate line: the maximum possible width of the bridge.

예제1

  1. 예제 1

    입력
    6 3 10 2 7
    10 7 20 9 25
    106 126 135 28 137
    
    예상 출력
    5
    9
    112