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

Game Rooms

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1280    Accepted Submission(s): 402


Problem Description
Your company has just constructed a new skyscraper, but you just noticed a terrible problem: there is only space to put one game room on each floor! The game rooms have not been furnished yet, so you can still decide which ones should be for table tennis and which ones should be for pool. There must be at least one game room of each type in the building.

Luckily, you know who will work where in this building (everyone has picked out offices). You know that there will be $T_{i}$ table tennis players and $P_{i}$ pool players on each floor. Our goal is to minimize the sum of distances for each employee to their nearest game room. The distance is the difference in floor numbers: 0 if an employee is on the same floor as a game room of their desired type, 1 if the nearest game room of the desired type is exactly one floor above or below the employee, and so on.
 

Input
The first line of the input gives the number of test cases, $T(1¡ÜT¡Ü100)$. $T$ test cases follow. Each test case begins with one line with an integer $N(2¡ÜN¡Ü4000)$, the number of floors in the building. $N$ lines follow, each consists of 2 integers, $T_{i}$ and $P_{i}(1¡ÜT_{i},P_{i}¡Ü10^{9})$, the number of table tennis and pool players on the $i_{th}$ floor. The lines are given in increasing order of floor number, starting with floor 1 and going upward.
 

Output
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the minimal sum of distances.
 

Sample Input
1 2 10 5 4 3
 

Sample Output
Case #1: 9
 

Hint

In the first case, you can build a table tennis game room on the first floor and a pool game room on the second floor.
In this case, the 5 pool players on the first floor will need to go one floor up, and the 4 table tennis players on the second floor will need to go one floor down. So the total distance is 9.
 

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-05-03 19:36:12, Gzip enabled