Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
北京大学《ACM-ICPC竞赛训练》暑期课面向全球招生。容量有限,报名从速!
Language:
Jimmy's Bad Day
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 1419Accepted: 462

Description

Jimmy works in an express company. His job is to deliver the packages to customers as soon as possible. He should deliver all the packages to their customers according to the orders before the end of the day, i.e. 24:00. Any delay should be fined heavily measured by the time he is late for.

It was a bad day. Jimmy' car was broken. And when he repaired it. It was exactly 24:00. The only thing Jimmy thought then was to find a proper way to deliver to minimize the fine.

He took a look at the map and found that his current position and all the places he would go are on a circle road. And he can drive his car to any place along the circle road clockwise or counter-clockwise. He wanted you to help him to find the best way to minimize the fine.

The fine is described as follows: if Jimmy is late, he has to pay one dollar per minute for each undelivered package.

Input

The input contains several test cases. The first line in each case contains an integer N, no more than 300, where (N-1) is the number of places he has to deliver to. The following N lines describe N points including his current location and the (N-1) destinations he has to go to. These N points are described clockwise based on their locations from Jimmy's current location. Each line consists of two integers m and t. m is the number of packages ordered by this place, which is always 0 in the first line and positive integers in the other lines. t, measured in minute, represents the time to go from this point to the next (the next point of the (N-1)-th destinations is Jimmy's current location).

A test case with N = 0 indicates the end of input, and this case should not be processed.

Output

For each test case, you should output one line containing only an integer which is the minimum fine Jimmy has to pay. You can assume that the answer is less than 1000000000 for all test cases.

Sample Input

4
0 1
6 10
9 50
5 5
5
0 2
5 5
4 20
1 20
7 1
0

Sample Output

240
92

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator