#P9787. [ROIR 2020] 最大乘积 (Day2)

[ROIR 2020] 最大乘积 (Day2)

Problem Description

Translated from ROIR 2020 Day2 T1. Максимальное произведение, translator: ShineEternal.

You are given an array of natural numbers [a1,a2,,an][a_1,a_2,\ldots,a_n].
Define the weight of an array as the sum of all numbers in the array.

Please split this array into two non-empty arrays [a1,a2,,ai][a_1,a_2,\ldots,a_i] and [ai+1,ai+2,,an][a_{i+1},a_{i+2},\ldots,a_n], so that the product of their weights is as large as possible.
You need to determine the ii that maximizes the product of the weights of the two arrays.

Input Format

The first line contains an integer nn, representing the number of elements.
The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n, representing the elements in the array.

Output Format

Output an ii that maximizes the product of the weights of [a1,a2,,ai][a_1,a_2,\ldots,a_i] and [ai+1,ai+2,,an][a_{i+1},a_{i+2},\ldots,a_n].
If there are multiple answers, you may output any one of them.

3
1 2 3
2

Hint

Sample 1 Explanation

If you choose i=1i=1, then the product of weights is 1(2+3)=51 \cdot (2+3) = 5.
If you choose i=2i=2, then the product of weights is (1+2)3=9(1+2) \cdot 3 = 9.

Constraints

For 100%100\% of the testdata, 2n2105,1ai1092 \le n \le 2\cdot 10^5, 1 \le a_i \le 10^9.
The detailed limits are shown in the table below:

Subtask ID Score Limit Additional Limit
11 1010 2n50002 \le n \le 5000 ai109\sum a_i \le 10^9
22 a1=a2==ana_1 = a_2 = \ldots = a_n
33 2020 ai109a_i \le 10^9
44 2n2000002 \le n \le 200000 ai109\sum a_i \le 10^9
55 a1=a2==ana_1 = a_2 = \ldots = a_n
66 ai109a_i \le 10^9

Translated by ChatGPT 5