Watson And his tasks

0

0 votes
Medium
Problem

My dear Watson, I cannot agree with those who rank modesty among the virtues. To the logician all things should be seen exactly as they are, and to underestimate one’s self is as much a departure from truth as to exaggerate one’s own powers.

Watson has one interesting task for Sherlock. Task is as follows:

Given two array of length N. find two indexes i and j (1 <= i <= j <= N) such that s1 is sum of elements between this indexes of first array and s2 is sum of elements between this indexes of second array and sum of square of s1 and s2 is minimum.

Help Sherlock to solve this problem.

Input Format

  • First line contains T (1 <= T <=100000) number of tasks.
  • For every tasks there are three lines.
  • First line contains N length of array. (sum of N over all test cases is <= 500000).
  • Second line contains N integers, elements of first array.
  • Third line contains N integers, elements of second array. (array elements are in between -100000 to 100000).
  • Inputs are designed in such way that there won't be overflow if you use long datatype.

Output Format

  • For every task print required minimum sum.

Setter: Umang Upadhyay

Time Limit: 2.5
Memory Limit: 256
Source Limit:
Editor Image

?