#P7564. [JOISC 2021] ボディーガード (Day3)
[JOISC 2021] ボディーガード (Day3)
Description
On a number line, there are people, and they are all customers of the Bookworm Bodyguard Company. Customer will move from position to position at time . Their speed is one unit of length per unit of time.
If a bodyguard and a customer are at the same position at the same time, we say that the bodyguard is protecting that customer. Suppose the bodyguard starts protecting customer at time and stops protecting at time . Then the interval is called the protection time of this customer, time is called the start time of protection, and time is called the stop time of protection. Here, and do not have to be integers. In particular, if a bodyguard is at the same position at the same time with two customers, the bodyguard can protect only one customer.
A bodyguard can move freely on the number line with speed at most one unit of length per unit of time and at least staying still. When a bodyguard stops protecting one customer, they can go to another position to protect another customer. If the path length that the bodyguard walks together with customer while protecting them is , then customer will pay the bodyguard Zimbabwe dollars, at a rate of Zimbabwe dollars per unit length.
As the owner of the Bookworm Bodyguard Company, Bookworm holds planned protection proposals. In proposal , a bodyguard starts working at time from position .
For each proposal, find the maximum total wage (in Zimbabwe dollars) that the bodyguard can earn.
Input Format
The first line contains two integers , representing the number of customers and the number of planned protection proposals.
The next lines each contain four integers , describing one customer.
The next lines each contain two integers , describing one planned protection proposal.
Output Format
Output lines. Each line contains one integer, representing the maximum total wage (in Zimbabwe dollars) that the bodyguard can earn for the corresponding proposal.
2 2
1 2 1 4
3 1 3 2
1 2
3 3
8
2
3 2
3 1 5 2
1 4 1 4
4 2 4 4
2 2
6 3
15
0
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
Hint
Explanation for Sample 1
- In proposal , the bodyguard can earn Zimbabwe dollars in the following way.
- Start moving from position at time .
- Protect customer from time to time . The path length traveled together is , so the wage is Zimbabwe dollars.
- Stay at position from time to time .
- Protect customer from time to time . The path length traveled together is , so the wage is Zimbabwe dollars.
- In proposal , the bodyguard can earn Zimbabwe dollars in the following way.
- Start moving from position at time .
- Move from position to position from time to time .
- Protect customer from time to time . The path length traveled together is , so the wage is Zimbabwe dollars.
Explanation for Sample 2
- In proposal , the bodyguard can earn Zimbabwe dollars in the following way.
- Start moving from position at time .
- Move from position to position from time to time .
- Protect customer from time to time . The path length traveled together is , so the wage is Zimbabwe dollars.
- Protect customer from time to time . The path length traveled together is , so the wage is Zimbabwe dollars.
- Protect customer from time to time . The path length traveled together is , so the wage is Zimbabwe dollars.
- Protect customer from time to time . The path length traveled together is , so the wage is Zimbabwe dollars.
- In proposal , no matter how the bodyguard moves, they cannot earn any wage, and can only get Zimbabwe dollars.
Constraints and Notes
This problem uses bundled subtasks.
- Subtask 1 (6 pts): .
- Subtask 2 (7 pts): .
- Subtask 3 (15 pts): .
- Subtask 4 (20 pts): .
- Subtask 5 (52 pts): No special restrictions.
For all testdata, , , , , is even, and .
Note
Translated from The 20th Japanese Olympiad in Informatics Spring Training Camp, Day3 B ボディーガード (Bodyguard) English version.
Translated by ChatGPT 5
京公网安备 11011102002149号