Joys of Trading
시간 제한1초메모리 제한1024 MB
두 마을이 자원별 단위당 작업 시간과 현재 생산량을 가질 때, 각 자원의 총생산량을 그대로 유지하면서 필요한 최소 총 작업 시간을 분수 생산을 허용해 구한다.
문제
Apolyanka and Büdelsdorf are two small neolithic villages that have recently come into contact. There are resources, numbered from to , and each village is capable of independently producing any of them, albeit with different efficiencies. In order to produce one unit of resource , Apolyanka needs person-hours, while Büdelsdorf needs person-hours. Currently Apolyanka is producing units of resource in each given time period, while Büdelsdorf is producing units.
Each village is currently working at maximum capacity, that is, there is no way they can put more person-hours to work than they are employing now. However, through the recently discovered benefits of trade, it is possible for both villages to produce all the resources they need while reducing the total person-hours worked, and thus becoming able to spend those freed person-hours resting and playing some games. All that is needed is that the villages cooperate, coordinate work and exchange resources among them.
For example, suppose , resource is wood, resource is food, , , , , , , , and . Then Apolyanka is doing person-hours of work: for producing units of wood, and for producing unit of food. Similarly, Büdelsdorf is doing person-hours of work: for producing unit of wood, and for producing units of food. Thus, the total production is units of wood and units of food, requiring person-hours.
However, a better organization is possible: Apolyanka could produce units of wood and units of food, while Büdelsdorf could produce no wood and units of food. The total production of each resource would be the same, but requiring only person-hours.
Another example with is , , , , , , and for . In this case, each village is currently working person-hours. With a slight reorganization however, they can each work person-hours while producing the exact same total resources! All that is required is for Apolyanka to produce one less unit of resource and one more of resource , while Büdelsdorf does the opposite.
Given all of these values, can you compute what is the minimum total number of person-hours that the villages have to work, in order to produce exactly the same total resources? Note that the number of person-hours invested in producing a resource is not required to be integer.
입력
The first line contains an integer () indicating the number of resources. Each resource is identified by a distinct integer from to .
The -th of the next lines describes resource with four integers , , and ( for ), as explained in the statement.
출력
Output a single line with the minimum total number of person-hours required to produce the resources. The output must have an absolute or relative error of at most .