A Math Contest P1 - Arrays

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 256M

Problem type

You are given an array of N integers a_1, a_2, \dots, a_N. Suppose b_1, b_2, \dots, b_N is any array of N integers. Find the minimum possible positive value of X = \sum_{i=1}^N a_i \times b_i.


1 \le N \le 2 \times 10^5

-10^9 \le a_i \le 10^9

At least one a_i \ne 0.

Input Specification

The first line contains an integer, N.

The next line contains N space-separated integers, a_1, a_2, \dots, a_N.

Output Specification

Output the minimum positive value of X.

Sample Input

2 -1 3

Sample Output


Explanation for Sample

One possible value for array b is [-2, 4, 3]. Then, X = (2)(-2) + (-1)(4) + (3)(3) = 1. This is the minimum positive value of X amongst all values of b.


There are no comments at the moment.