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

King Kong II

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 226    Accepted Submission(s): 14


Problem Description
Have you seen the movie King Kong? If you have seen it, you must be impressed by the scene of the exciting fight between dinosaurs and King Kong, right? Though the dinosaurs have been fight off, King Kong has been injured very heavily. Considering that dinosaurs will come back very quickly, King Kong brings a lot of stones for fear that the dinosaurs attack again.
Now King Kong has arranged the stones at random in one line. But Different alignments of these stones would be different to King Kong. If the alignment is not the target in his mind, he will move the stones to their proper positions. Taking the physical consumption into consideration, King Kong could swap only two stones (whose weight is a and b weight units) at one time and for each time he will consume a+b thermal units. In order to minimize the physical consumption, King Kong should set a plan to move these stones. But this is too complex for king Kong and he needs your help.
 

Input
There are several test cases. For each test case, it contains:
Line 1: One integer N (1<=N<=50000) which specifies the total number of stones.
Line 2: N integers (you are ensured that the absolute value of each integer is less than 216) which the weight of each stone initially. These numbers specify the initial stone alignment. There is a blank between two consecutive integers.
Line 3: N integers (you are ensured that the absolute value of each integer is less than 216 ) which the weight of each stone finally. These numbers specify the target alignment in King KongĄ¯s mind. There is a blank between two consecutive integers.
The input will be ended by zero.
 

Output
Output the Case number and the answer of the minimum total thermal units consumed by King Kong in the stone moving process.
 

Sample Input
3 3 2 1 1 2 3 3 1 2 3 1 2 3 4 4 2 1 2 1 2 2 4 4 8 1 2 4 1 2 4 8 5 1 8 9 7 6 1 6 7 8 9 0
 

Sample Output
Case 1: 4 Case 2: 0 Case 3: 8 Case 4: 17 Case 5: 41
 

Author
WHU
 

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-12 00:25:22, Gzip enabled