Double Radars

시간 제한1초메모리 제한2048 MB

요약
두 레이더가 원형 마을의 집들을 반대 방향으로 돌며 서로 만나면 되튕기고, 속도 v인 도둑이 레이더와 만나지 않고 훔칠 수 있는 동전 가치 합의 최댓값을 구한다.
난이도

어려움10점 중 9점

유형
수학, 정렬, 구간
정답자
아직 제출이 없습니다

문제

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 11 through kk consecutively in the clockwise direction. The treasure contains nn coins, where the iith coin (for 1≤i≤n1 \le i \le n) has the value w_iw\_i and is located at the house x_ix\_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,2i \in \\{1, 2\\}) starts by monitoring house r_ir\_i and moves 1v_i\frac{1}{v\_i} houses per minute. More intuitively, every v_iv\_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 (1≤n≤1051 \le n \le 10^5 ) number of coins, kk (1≤k≤1091 \le k \le 10^9) number of houses around the circle, and vv (1≤v≤1041 \le v \le 10^4 ) speed of Gholi.

The second line contains the starting monitoring house r_1r\_1 and speed v_1v\_1 of the first radar (1≤r_1≤k1 \le r\_1 \le k, 1≤v_1≤1041 \le v\_1 \le 10^4).

The third line contains the starting monitoring house r_2r\_2 and speed v_2v\_2 of the second radar (1≤r_2≤k1 \le r\_2 \le k, 1≤v_2≤1041 \le v\_2 \le 10^4). It is guaranteed that r_1≠r_2r\_1 \ne r\_2.

The fourth line contains nn distinct integers, x_1,x_2,…,x_nx\_1, x\_2, \dots , x\_n, representing the houses where the coins are located (1≤x_i≤k1 \le x\_i \le k).

The fifth line contains nn integers, w_1,w_2,…,w_nw\_1, w\_2, \dots , w\_n, representing the value of each coin (1≤w_i≤1091 \le w\_i \le 10^9 ).

출력

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

예제1

  1. 예제 1

    입력
    3 5 1
    1 2
    2 3
    1 2 4
    1 2 4
    
    예상 출력
    6