luogu#P5016. [NOIP 2018 普及组] 龙虎斗
[NOIP 2018 普及组] 龙虎斗
Background
NOIP2018 Junior T2.
Problem Description
Xuanxuan and Kaikai are playing a game called Dragon-Tiger Battle. The game board is a line segment with barracks on it (numbered from left to right as ). The distance between two adjacent barracks is centimeter, so the board is a line segment of length centimeters. Barrack contains engineers. Figure 1 below shows an example with :

Xuanxuan is on the left, representing the “Dragon”; Kaikai is on the right, representing the “Tiger”. They take barrack as the boundary: engineers on the left belong to the Dragon side, engineers on the right belong to the Tiger side, and the engineers in barrack are undecided and do not belong to either side.
The momentum of a barrack is defined as: (number of engineers in the barrack) (distance from the barrack to barrack ).
The power of a side is defined as: the sum of the momentum of all barracks belonging to that side.
Figure 2 below shows an example with , where red is the Dragon side and yellow is the Tiger side:

During the game, at some moment, reinforcements arrive from the sky: a total of engineers suddenly appear in barrack . As a friend of Xuanxuan and Kaikai, you know that if the difference in power between the Dragon and Tiger becomes too large, they will not want to continue playing. To keep the game going, you need to choose a barrack and send all engineers in your hand to barrack , so that the difference in power between the two sides is as small as possible.
Note: The engineers you send will have the same side affiliation as the engineers already in that barrack (if they land in barrack , they do not belong to any side).
Input Format
The first line contains a positive integer , representing the number of barracks.
The next line contains positive integers, separated by single spaces. The -th positive integer represents the initial number of engineers in barrack .
The next line contains four positive integers, separated by single spaces, representing .
Output Format
Output one line containing a positive integer, namely , the index of the barrack you choose. If multiple indices achieve the optimal result at the same time, output the smallest index.
6
2 3 2 3 2 3
4 6 5 2
2
6
1 1 1 1 1 16
5 4 1 1
1
Hint
Explanation for Sample 1
See Figure 2 in the problem description.
The two sides are divided by barrack . There are engineers that suddenly appear in barrack .
The Dragon side’s power is:
The Tiger side’s power is:
When you send your engineers to barrack , the Dragon side’s power becomes:
At this time, the two sides have equal power.
Explanation for Sample 2
The two sides are divided by barrack . There are engineers that suddenly appear in barrack .
The Dragon side’s power is:
The Tiger side’s power is:
When you send your engineers to barrack , the Dragon side’s power becomes:
At this time, the difference in power between the two sides can be minimized.
Constraints
, .
For of the testdata, .
Another of the testdata has .
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5