placi
Dănuţ has two mice: Jerry and Terry. As a result of studies carried out on mice, the boy has decided to make an experiment: after the mice fall asleep, he will build in their home a separation wall made out of... cheese. A total of N cheese plates of different types were bought for this experiment. For plate i (i = 1,…, N) we know the time it takes Jerry to eat it - ai seconds or Terry to eat it - bi seconds. The mice wake up in the morning at exactly the same time and immediately begin "destroying" the wall from opposite sides. The plates are destroyed consecutively, without any breaks, at a constant speed for each plate. A plate has to be eaten entirely before going to the next plate. There are no quarrels if "destroying" the same plate together, each mouse eating at a constant speed as much as he can of the last plate. The wall is considered destroyed when the last plate is eaten. Dănuţ wants to arrange the plates so that the duration of the wall be maximal, the time being estimated as of the moment the mice wake up and begin "destroying" the wall. |
![]() |
Task
Write a program that determines the maximum amount of time the separation wall can exist.
Input Data
Input file placi.in contains on line one positive integer N - the number of plates. Each of the following N lines contains two positive integers, ai and bi, separated by a space - the time it takes plate i to be eaten by Jerry, and respectively Terry.
Output Data
Output file placi.out will contain a single line, with one positive integer, with at least three decimals - the maximum duration of the separation wall.
Constraints
Examples
placi.in | placi.out | placi.in | placi.out |
4 1 2 1 2 0.5 1.5 7 3.5 |
6.000 | 1 3 6 |
2.000 |
Time limit: 0.1 seconds/test
prof. Sergiu Corlat
Chişinău Moldavian-Turkish High-School, Republic of Moldova
Contact:scorlat@gmail.com