#P14698. [ICPC 2024 Tehran R] Double Radars

[ICPC 2024 Tehran R] Double Radars

题目描述

Ali recently found a treasure and has arranged the coins from the treasure around a circle. There are kk houses around the circle with equal distances. Houses are numbered 1 through kk consecutively in the clockwise direction. The treasure contains nn coins, where the ithi^{th} coin (for 1in1 \leq i \leq n) has the value wiw_i and is located at the house xix_i.

To protect the treasure, Ali has installed two radars stationed at the center of the circle, monitoring its circumference. Radar ii (for i{1,2}i \in \{1,2\}) starts by monitoring house rir_i and moves 1vi\frac{1}{v_i} houses per minute. More intuitively, every viv_i minutes, the Radar ii goes one house forward. Initially, the first radar moves clockwise, and the second radar moves counterclockwise. Whenever the two radars meet, they both reverse their directions. Note that this can happen in the area between two adjacent houses.

Gholi, who wants to steal as many coins as possible, plans to start at an arbitrary house on the circle and move at most 1v\frac{1}{v} houses per minute in either direction (clockwise or counterclockwise). He starts moving at the time zero. He can reverse his direction anytime or stay still for a while. If Gholi crosses paths with one of the radars at any moment, he will be immediately caught and sent to jail. He cannot steal a coin if this happens at a house.

Help Gholi to maximize the total value of the coins he can steal before being detected by the radars.

输入格式

The first line contains three integers, nn (1n1051 \leq n \leq 10^5) number of coins, kk (1k1091 \leq k \leq 10^9) number of houses around the circle, and vv (1v1041 \leq v \leq 10^4) speed of Gholi.

The second line contains the starting monitoring house r1r_1 and speed v1v_1 of the first radar (1r1k1 \leq r_1 \leq k, 1v11041 \leq v_1 \leq 10^4).

The third line contains the starting monitoring house r2r_2 and speed v2v_2 of the second radar (1r2k1 \leq r_2 \leq k, 1v21041 \leq v_2 \leq 10^4). It is guaranteed that r1r2r_1 \neq r_2.

The fourth line contains nn distinct integers, x1,x2,,xnx_1, x_2, \ldots, x_n, representing the houses where the coins are located (1xik1 \leq x_i \leq k).

The fifth line contains nn integers, w1,w2,,wnw_1, w_2, \ldots, w_n, representing the value of each coin (1wi1091 \leq w_i \leq 10^9).

输出格式

Output the maximum total value of coins Gholi can steal before being detected by the radars.

3 5 1
1 2
2 3
1 2 4
1 2 4
6