프로그램 명: coci_kolinje(special judge)
제한시간: 1 초

당신은 N개의 유리잔을 진열해놓고, 그 안에 주스를 담으려고 한다. 처음에는 k번째 유리잔에 각각 Ak 만큼의 주스가 담겨있다.

당신은 주스를 더 가져와서 각 유리잔에 B1 : B2 : … : BN 의 비율로 더 넣으려고 한다.

한편, 미관상의 이유로 왼쪽 잔(번호가 작은 잔)의 주스가 오른쪽 잔(번호가 큰 잔)의 주스보다 적어지면 안 된다. 주스를 아름답게 담기 위해서 더 가져와야 할 주스의 양을 구하는 프로그램을 작성하여라.

입력 형식

출력 형식

만약 주스를 아름답게 담을 수 없다면 -1을 출력한다. 그렇지 않다면 주스를 아름답게 담기 위해서 더 가져와야 할 주스의 양을 출력한다.

답은 0 이상 1,000,000 이하의 실수이며, 답이 여러 개이면 그 중 아무거나 출력한다.

입출력 예

입력 예 1
출력 예 1
3
7 1
3 2
10 0
10.5
입력 예 2
출력 예 2
3
2 1
4 0
0 3
-1


입력 예 3
출력 예 3
5
15 4
6 7
12 5
9 6
1 7
87


입력 예 1 설명
10.5의 주스를 가져오면 각 유리잔에 3.5, 7, 0만큼 주스를 담게 된다. 담겨진 주스의 총량은 10.5, 10, 10이므로 아름다운 주스 분배이다.

Melita has just returned from the annual pig slaughter. Don't worry, this is a regular thing in Croatia. The best part was the abundance of food! There was everything, starting from good spicy sausages, ham, black pudding, up to teewurst, top quality bacon and ?varci, all with warm white bread and butter.

After these appetizers, it was the perfect time to whip up a deep pot full of sarma (Melita ate twentyish of them) as well as a large platter of fine roast pork, so soft that it almost melts in your mouth. They watered all of this down with copious gulps of the best dry white wine that made them even hungrier.

Butcher Bajs kept his award-winning ham for the very end. N people attented the annual pig slaughter, labeled with numbers from 1 to N. These people already ate a lot of meat: the k th person ate A[k] kilograms of meat so far. Bajs will distribute his ham to the people in the ratio B[1] : B[2] : … : B[N], exactly in that order, but he doesn't know the total amount (number of kilos) of ham which he will be distributing yet.

At the end of the slaughter, the Man of the Year will be declared. A ranking list is made according to the total kilos of meat eaten. Bajs impacts directly on this list by choosing the amount of ham to distribute. Although Bajs has been offered bribes many times, he refused each time, saying that he was an honest man who would not hurt a fly.

Bajs cares about order, because he's a nice gentleman, and wants to have the order of people in the exact form of 1, 2, 3, ..., N, respectively from the one who ate the most kilos of meat to those who ate less, allowing ties between participants. Help Bajs select the total amount of ham that he will distribute (in the ratio mentioned before) to achieve his intention.

입력

출력

The first and only line of output must contain -1 if the required order cannot be achieved.

Otherwise, output the required amount of ham in kilos, a real number (rounded up to 12 decimal places) between 0 and 10^7 (inclusive).

If there are multiple possible solutions, output any.

입출력 예

input 
 
3 
7 1 
3 2 
10 0 
 
output 
 
10.5 

input 
 
3 
2 1 
4 0 
0 3 
 
output 
 
-1 

input 
 
5 
15 4 
6 7 
12 5 
9 6 
1 7 
 
output 
 
87 

Clarification of the first example: 10.5 kilos of ham is distributed in the ratio 1 : 2 : 0, which gives us 
3.5, 7 and 0 kilos of ham, respectively. If we add this to the already eaten amount of meat, we conclude 
that the participants ate 10.5, 10 and 10 kilos in total, which is a valid order. 
출처:coci/2013-2014/contest3 4/6
번역:functionx
special judge:Fate

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]