F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Phage War

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1460    Accepted Submission(s): 799


Problem Description
Phage War is a little flash game. In this game, we want infect all cells by the transmission and breed of phages.
Originally, there is a cell infected by phages and this cell can breed a new phage every second. You should know that only the new born phages can inject other cells.

There are n cells around this cell, numbered from 1 to n. If there are Di phages reaching the i-th cell, the cell would be infected, and the phages journey will cost Ti seconds. To simplify it, we assume these phages will stay in this new cell and they can¡¯t infect other cells. And the new cell cannot breed new phages and infect other cells.
Can you tell me how much time it costs to infect all cells at least?
 

Input
In the first line there is an integer T (T <= 50), indicates the number of test cases.
In each case, the first line contains a integers N (1 <= N <= 10^5). Then there are N lines, each line contain two integers Di, Ti (1<=Di, Ti<=100).
 

Output
For each case, output the least time needed in one line.(as shown in the sample output)
 

Sample Input
2 2 2 1 5 6 2 1 11 3 10
 

Sample Output
Case 1: 11 Case 2: 14
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-24 18:06:07, Gzip enabled