Cover Them All! Problem in Hacker Blocks

There are N soldiers located on our X-AXIS. The point at which soldier is located also has some number of bombs.
The war is near and every soldier wants to communicate with every other soldier.
If the ith soldier has b number of bombs and is located at position X then the cost of communicating with any other soldier j having c number of bombs located at position Y is defined as |X-Y|*max(b,c).
Find the sum of costs of communication if every soldier wants to communicate with every other soldier.
NOTE :- You have to consider pair(i,j) only once in sum of costs.

Input Format
First line consists of number of test cases T. Each test case consists of three lines. The first line indicates the number of soldiers (N). The second line indicates the coordinates of the N soldiers ( X[i] ). The third line contains the number of bombs at every soldiers location ( B[i] ) . The x-coordinates needn’t be in increasing order in the input.

Constraints
1 <= T <= 20 1 <= N <= 200000 1 <= X[i] <= 1000000000 1 <= B[i] <= 10000

Output Format
The total cost modulo 10^9+7.

Sample Input
1
3
1 3 6
10 20 30
Sample Output
280
Explanation
there are 3 pairs (1,2) -> cost = abs(3-1) * 20 = 40 (1,3) -> cost = abs(1-6) * 30 = 150 (2,3) -> cost = abs(3-6) * 30 = 90 sum = 40 + 150 + 90 = 280

My Code - https://ide.codingblocks.com/s/182205

Test Case Error and run-error.

@arhanchoudhury Run error is due to accessing array index outside the legal range.
Check the constraints in the question 1 <= N <= 200000 1 <= X[i] <= 1000000000 1 <= B[i] <= 10000
But you have used an array of size 1000 and type int. So change the datatypes to long long int to hold large values such as 1 <= X[i] <= 1000000000. Also increase the size of your array to 200000

okay I will try that

I am getting wrong answer

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

i had also done the same code with correction as suggested by you but still its showing failed cases