406046: GYM102222 H Fight Against Monsters

Memory Limit:256 MB Time Limit:10 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Fight Against Monsterstime limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Egbert Felix Gaspar Humbert Ignatius Jayden Kasper Leroy Maximilian. As a storyteller, today I decide to tell you and others a story about the hero Huriyyah, and the monsters.

Once upon a time, citizens in the city were suffering from $$$n$$$ powerful monsters. They ate small children who went out alone and even killed innocent persons. Before the hero appeared, the apprehension had overwhelmed the people for several decades.

For the good of these unfortunate citizens, Huriyyah set off to the forest which was the main lair of monsters and fought with $$$n$$$ fierce and cruel monsters. The health point of the $$$i$$$-th monster was $$$HP_i$$$, and its attack value was $$$ATK_i$$$.

They fought in a cave through a turn-based battle. During each second, the hero Huriyyah was attacked by monsters at first, and the damage was the sum of attack values of all alive monsters. Then he selected a monster and attacked it. The monster would suffer the damage of $$$k$$$ (its health point would decrease by $$$k$$$) which was the times of attacks it had been came under. That is to say, for each monster, the damage of the first time that Huriyyah attacked it was $$$1$$$, and the damage of Huriyyah's second attack to this monster was $$$2$$$, the third time to this monster was $$$3$$$, and so on. If at some time, the health point of a monster was less than or equal to zero, it died. The hero won if all monsters were killed.

Now, my smart audience, can you calculate the minimum amount of total damages our hero should suffer before he won the battle?

Input

The input contains several test cases, and the first line is a positive integer $$$T$$$ indicating the number of test cases which is up to $$$10^3$$$.

For each test case, the first line contains an integers $$$n~(1\le n\le 10^5)$$$ which is the number of monsters.

The $$$i$$$-th line of the following $$$n$$$ lines contains two integers $$$HP_i$$$ and $$$ATK_i~(1\le HP_i, ATK_i\le 10^5)$$$ which describe a monster.

We guarantee that the sum of $$$n$$$ in all test cases is up to $$$10^6$$$.

Output

For each test case, output a line containing Case #x: y, where x is the test case number starting from $$$1$$$, and y is the minimum amount of total damages the hero should suffer.

ExampleInput
2
3
1 1
2 2
3 3
3
3 1
2 2
1 3
Output
Case #1: 19
Case #2: 14

加入题单

上一题 下一题 算法标签: