시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
25 초 | 2048 MB | 40 | 9 | 6 | 18.182% |
JOI Street is a long street from west to east. It is considered as the number line.
From now, N very important people (VIP) will come to JOI Street and walk along it. VIPs are numbered from 1 to N. VIP i (1 ≤ i ≤ N) will depart from the coordinate Ai at time Ti, and walk to the coordinate Bi. Its speed is 1 per unit time. If Ai < Bi, VIP i will move toward the positive direction at the constant speed. Similarly, if Ai > Bi, VIP i will move toward the negative direction at the constant speed.
A bodyguard’s job is to walk along JOI Street and guard the VIPs. To guard a VIP, it is necessary to walk with the VIP for some time. It is allowed for a bodyguard to start guarding a VIP in the middle of their walk, or to quit guarding before they end walking. The time to start or end guarding need not be an integer. However, even if multiple VIPs are at the same coordinate, a bodyguard can guard at most one VIP at a time.
A bodyguard can walk JOI Street freely at the speed of at most 1 per unit time. When they finish guarding a VIP, it is allowed to move to another place and start guarding another VIP. If a bodyguard walks with VIP i, the VIP gives the bodyguard the reward of Ci yen per unit distance, according to the distance where the bodyguard guards the VIP. Here it is guaranteed that Ci is an even integer.
You, working for a security company, are planning Q projects to guard the VIPs. The projects are numbered from 1 to Q. For the project j (1 ≤ j ≤ Q), a bodyguard starts working at coordinate Xj at time Pj. Your task is to calculate the maximum total reward for each project.
Write a program which, given information of VIPs and projects, calculates the maximum total reward for each project.
Under the constraints of this task, it can be proved that the maximum total reward of a project is always an integer.
Read the following data from the standard input. Given values are all integers.
N Q T1 A1 B1 C1 . . . TN AN BN CN P1 X1 . . . PQ XQ
Write Q lines to the standard output. The j-th line (1 ≤ j ≤ Q) of the output should contain an integer which is the maximum total reward for the project j.
번호 | 배점 | 제한 |
---|---|---|
1 | 6 | Ti ≤ 3 000, Ai ≤ 3 000, Bi ≤ 3 000 (1 ≤ i ≤ N). Pj ≤ 3 000, Xj ≤ 3 000 (1 ≤ j ≤ Q). |
2 | 7 | Q = 1. |
3 | 15 | Q ≤ 3 000. |
4 | 20 | Q ≤ 40 000. |
5 | 52 | No additional constraints. |
2 2 1 2 1 4 3 1 3 2 1 2 3 3
8 2
In the project 1, a bodyguard gets a total reward of 4 + 4 = 8 yen by the following way.
Since it is the maximum value, output 8 in the first line of the output.
In the project 2, a bodyguard will get a total reward of 2 yen by the following way.
Since it is the maximum value, output 2 in the second line of the output.
This sample input satisfies the constraints of Subtasks 1, 3, 4, 5.
3 2 3 1 5 2 1 4 1 4 4 2 4 4 2 2 6 3
15 0
In the project 1, a bodyguard will get a total reward of 4 + 1 + 8 + 2 = 15 yen by the following way.
Since it is the maximum value, output 15 in the first line of the output.
In the project 2, a bodyguard starts working at coordinate 3 at time 6. However, it is impossible to guard a VIP. Thus, the maximum amount of reward is 0 yen. Therefore, output 0 in the second line of the output.
This sample input satisfies the constraints of Subtasks 1, 3, 4, 5.
5 5 8 1 4 10 8 3 7 6 1 4 6 2 3 9 5 4 6 1 9 6 7 6 6 8 1 3 9 4 2 4
30 27 48 30 48
This sample input satisfies the constraints of Subtasks 1, 3, 4, 5.