## Girls Invitational '18 J5 - Kstar and Party

View as PDF

Points: 7
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Kstar is hosting a party and knows that exactly people will come, and the order in which they will enter the house. Each person has an integer energy level, which is also known to Kstar.

The synergy level between a pair of people is the product of the two people’s energy levels. The combined synergy in the house is equal to the sum of the synergy levels of all distinct pairs of people in the house. Note that Kstar can choose to lock everyone out before anyone comes in.

Kstar wants to start the party after some people have arrived and the energy level is maximized. After which person should Kstar lock the door and stop people from getting in? If there are multiple times where locking the door would yield the maximum synergy, output the first such possible time.

#### Input Specification

The first line of input will contain , the number of people invited to Kstar’s party. The next lines will contain an integer , the energy level of the person.

#### Output Specification

Output the least number of people Kstar should let in before closing the door and locking everyone out, in order to maximize total synergy.

#### Sample Input

4
1
2
8
-5

#### Sample Output

3

#### Explanation for Sample Input

After the first person comes in, the combined synergy is .

After the second person comes in, the combines synergy is .

After the third person comes in, the combines synergy is .

After the fourth person comes in, the combines synergy is .

Since the combined synergy was the maximum when the third person comes in, Kstar should lock the door after the third person comes in.