Pizza delivery
시간 제한2초메모리 제한1024 MB
한 명의 배달원이 왕복 배달을 순서대로 처리할 때, 각 고객의 irritability에 대기 시간과 앞선 배달 수를 곱한 값의 합을 최소로 만드는 순서를 정한다.
문제
JAG Pizza is the famous pizza shop. Since the number of delivery orders has been increasing, it has been busier than before.
One day, several orders came to this shop at the same time! There were orders, and customers who placed the order. The -th customer placed the -th order.
Through past orders, this shop knows information for each customer. For the -th customer, it takes hours for delivering the pizza from the shop, and also takes hours for going back to the shop. Moreover, his or her "irritability" is . The bigger irritability a person has, the easier to be angry.
JAG Pizza has to deliver orders for customers, and keep their minds on less customer stress. To formulate the amount of stress which the -th customer feels, let be the time from order to delivery, and let be the number of other customers whose delivery time is faster than that of -th customer. The amount of stress for the -th customer () is formulated as follows: .
For less customer stress, and gaining high satisfaction rates, a better delivery plan is necessary. When you think about it, you must take the following things into account:
- There is only one delivery person.
- A delivery person cannot deliver several orders in parallel. It means that he or she can deliver a single order at once, and when achieved, he or she gets back to the shop for delivering the next order.
- You can assume that it tooks no time for preparing an order, passing it from the shop to a delivery person, and passing it from a delivery person to a customer.
You are the delivery planner of JAG Pizza. Above these information and conditions, you have to minimize the total amount of stress for all customers.
입력
The input consists of a single test case of the following format.
The first line is the number of customers ().
The -th of the following lines consists of two integers and , which represent that it takes () hours for delivering the pizza from the shop to the -th customer, and also takes hours for going back to the shop. Moreover, its irritability is ().
출력
Print the minimum total amount of stress.