Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Coderun 04 - The Revival  

  Mar 14, 2023

Problem C. Make round greedily


Time limit 4000 ms
Code length Limit 50000 B
OS Linux

Mr.Krish is the CEO of a software company. Being the CEO he leads a very luxurious life. He lives
in a large villa and has a collection of N expensive cars. One day he arranged them all in a
circular path, each car is one unit distance apart from the other. He wishes to create a video
rallying around the cars. Each car has a different tank gasoline capacity. The i-th car's tank can
be filled up to fi liters of gasoline, with cost ci coins per liter.
​ ​

When creating a video, at first he will choose a car and start driving it in a clockwise direction.
To move one unit distance, 1 liter of gasoline is used. While passing around the other cars he can
take gasoline from them and fill up the current car's tank. His video will be completed when he
reaches the car location from where he started.

He wants to fill up the tank of the cars in such a way that he can create the rally video with the
minimum number of coins.

Input

The first line of the input contains a single integer T (1 ≤ T ≤ 10) denoting the number of
test cases. The description of T test cases follows.
The first line of each test case contains a single integer N (1
≤ N ≤ 200, 000).
The second line contains N space-separated integers f1 , f2 , … , fN (0 ≤ fi ≤ 109 for each
​ ​ ​ ​

valid i).
The third line contains N space-separated integers c1 , c2 , … , cN (0 ≤ ci ≤ 109 for each
​ ​ ​ ​

valid i).

Output

For each test case, print a single line containing one integer ― the smallest possible number of
coins you need to pay.

Sample 1

-
Coderun 04 - The Revival    Mar 14, 2023

Input Output

3 3
3 30
1 1 1 3
1 1 1
3
3 0 0
10 0 0
3
3 3 3
3 2 1

You might also like