A Math Contest P1 - Arrays

View as PDF

Submit solution

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

Author:
Problem type

You are given an array of N integers a1,a2,,aN. Suppose b1,b2,,bN is any array of N integers. Find the minimum possible positive value of X=i=1Nai×bi.

Constraints

1N2×105

109ai109

At least one ai0.

Input Specification

The first line contains an integer, N.

The next line contains N space-separated integers, a1,a2,,aN.

Output Specification

Output the minimum positive value of X.

Sample Input

Copy
3
2 -1 3

Sample Output

Copy
1

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.


Comments


  • 0
    JajaaGamer  commented 92 days ago edited

    Can someone help me understand why this isn't a valid solution? My process is to initially add all of the values together (analogous to having array b filled with ones) then subtracting values from the array until the sum is minimized (until any further subtraction of values would cause a negative sum, this is essentially decrementing the multiple of the values of a found in the b array). Why does this not work? It passes the given test case but not the grader's cases. Is there some hidden rule that the elements must be distinct?