The Not-So-Intelligent Dictator
All submissions for this problem are available.
Mountain-View (MV) is a linear, street-like country.
By linear, we mean all the cities of the country are placed on a single straight line - the x-axis.
Thus every city's position can be defined by a single coordinate, xi, the distance from the left borderline of the country. You can treat all cities as single points.
Unfortunately, the dictator of telecommunication of MV (Mr. LL) is not an intelligent man. He doesn't know anything about the modern telecom technologies, except for peer-to-peer connections.
Even worse, his thoughts on peer-to-peer connections are extremely faulty: he believes that, if Pi people are living in city i, there must be at least Pi cables from city i to every other city of MV - this way he can guarantee no congestion will ever occur!
Mr. LL is not good in math and computing. He hires an engineer to find out how much cable they need to implement this telecommunication system, given the coordination of the cities
and their respective population.
A number T is given in the first line and then comes T blocks, each representing a scenario.
Each scenario consists of three lines. The first line indicates the number of cities (N).
The second line indicates the co-ordinates of the N cities. The third line contains the population of each of the cities.
The cities needn't be in increasing order in the input..
For each scenario of the input, write the length of cable needed in a single line modulo 1,000,000,007.
1 ≤ T ≤ 20
1 ≤ N ≤ 200,000
Border to border length of the country <= 1,000,000,000
Input: 2 3 1 3 6 10 20 30 5 5 55 555 55555 555555 3333 333 333 33 35 Output: 280 463055586
For the first test case, having 3 cities requires 3 sets of cable connections. Between city 1 and 2, which has a population of 10 and 20, respectively, Mr. Treat believes at least 10 cables should come out of city 1 for this connection, and at least 20 cables should come out of city 2 for this connection.
Thus, the connection between city 1 and city 2 will require 20 cables, each crossing a distance of 3-1 = 2 km.
Applying this absurd logic to connection 2,3 and 1,3, we have
[1,2] => 20 connections x 2 km = 40 km of cable
[2,3] => 30 connections x 3 km = 90 km of cable
[1,3] => 30 connections x 5 km = 150 km of cable
For a total of 280 , Output is 280 % 1000000007 = 280km of cable.
|Time Limit:||10 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.