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 nn barracks on it (numbered from left to right as 1n1 \sim n). The distance between two adjacent barracks is 11 centimeter, so the board is a line segment of length n1n-1 centimeters. Barrack ii contains cic_i engineers. Figure 1 below shows an example with n=6n=6:

Xuanxuan is on the left, representing the “Dragon”; Kaikai is on the right, representing the “Tiger”. They take barrack mm 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 mm are undecided and do not belong to either side.

The momentum of a barrack is defined as: (number of engineers in the barrack) × \times (distance from the barrack to barrack mm).
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 n=6,m=4n = 6, m = 4, 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 s1s_1 engineers suddenly appear in barrack p1p_1. 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 p2p_2 and send all s2s_2 engineers in your hand to barrack p2p_2, 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 mm, they do not belong to any side).

Input Format

The first line contains a positive integer nn, representing the number of barracks.

The next line contains nn positive integers, separated by single spaces. The ii-th positive integer represents the initial number of engineers cic_i in barrack ii.

The next line contains four positive integers, separated by single spaces, representing m,p1,s1,s2m, p_1, s_1, s_2.

Output Format

Output one line containing a positive integer, namely p2p_2, 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 m=4m=4. There are s1=5s_1=5 engineers that suddenly appear in barrack p1=6p_1=6.
The Dragon side’s power is:

2×(41)+3×(42)+2×(43)=142 \times (4-1)+3 \times (4-2)+2 \times (4-3) = 14

The Tiger side’s power is:

2×(54)+(3+5)×(64)=182 \times (5 - 4) + (3 + 5) \times (6 - 4) = 18

When you send your s2=2s_2 = 2 engineers to barrack p2=2p_2 = 2, the Dragon side’s power becomes:

14+2×(42)=1814 + 2 \times (4 - 2) = 18

At this time, the two sides have equal power.

Explanation for Sample 2

The two sides are divided by barrack m=5m = 5. There are s1=1s_1 = 1 engineers that suddenly appear in barrack p1=4p_1 = 4.
The Dragon side’s power is:

$$1 \times (5 - 1) + 1 \times (5 - 2) + 1 \times (5 - 3) + (1 + 1) \times (5 - 4) = 11$$

The Tiger side’s power is:

16×(65)=1616 \times (6 - 5) = 16

When you send your s2=1s_2 = 1 engineers to barrack p2=1p_2 = 1, the Dragon side’s power becomes:

11+1×(51)=1511 + 1 \times (5 - 1) = 15

At this time, the difference in power between the two sides can be minimized.

Constraints

1<m<n1 < m < n, 1p1n1 \le p_1 \le n.
For 20%20\% of the testdata, n=3,m=2,ci=1,s1,s2100n = 3, m = 2, c_i = 1, s_1, s_2 ≤ 100.
Another 20%20\% of the testdata has n10,p1=m,ci=1,s1,s2100n ≤ 10, p_1 = m, c_i = 1, s_1, s_2 ≤ 100.
For 60%60\% of the testdata, n100,ci=1,s1,s2100n ≤ 100, c_i = 1, s_1, s_2 ≤ 100.
For 80%80\% of the testdata, n100,ci,s1,s2100n ≤ 100, c_i, s_1, s_2 ≤ 100.
For 100%100\% of the testdata, n105n ≤ 10^5, ci,s1,s2109c_i, s_1, s_2 ≤ 10^9.

Translated by ChatGPT 5