#P11112. [ROI 2024] 机器人物流 (Day 1)

[ROI 2024] 机器人物流 (Day 1)

Background

Translated from ROI 2024 D1T1

When ROI 2224 was held, a group of robots that can clone themselves were responsible for deliveries. People did not need to go outside and could receive packages directly through their windows.

At the beginning, there is only one delivery robot. At any time, the topmost robot can clone one or more new robots above itself, forming a “robot stack”. The height of each robot is equal to one floor.

During delivery, the robot stack moves from left to right along the dormitory building. The robots’ database contains a list of orders, and each order specifies a window that needs a delivery. When the robot queue passes a window, if there is a robot at the same height as that window, the delivery can be completed immediately.

While moving, the robot stack may hit obstacles. After hitting an obstacle, only the robots above the obstacle’s height can continue moving. After passing the obstacle, these robots immediately regroup into a robot stack, and can continue moving, cloning, and completing deliveries.

The distance between obstacles and windows is large enough, so when the robots pass an obstacle, they will not pass a window at the same time.

Problem Description

For each completed order, the robot company earns pp units of virtual currency, and the cost to clone one new robot is cc units of virtual currency. The final profit equals the total income from delivered orders minus the total cost of all robot cloning. The company wants to maximize the profit. Determine the maximum profit the company can obtain.

The company does not have to complete all orders, and the robots may stop delivering at any time.

Input Format

The first line contains four integers n,m,c,pn, m, c, p (0n,m1000000 \le n, m \le 100000, 1c,p10000001 \le c, p \le 1000000), representing the number of obstacles, the number of orders, the cost to clone one robot, and the income for delivering each order, respectively.

The next n+mn + m lines describe the obstacles and windows in detail, given in left-to-right order. Each line contains two integers tit_i and hih_i (1ti21 \le t_i \le 2, 1hi10000001 \le h_i \le 1000000), where tit_i indicates the type of the object (11 for an obstacle, 22 for a window), and hih_i indicates the height of the obstacle or the floor of the window.

It is guaranteed that there are nn obstacles, and the remaining mm objects are windows.

Output Format

Output one integer, the maximum profit that can be obtained.

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

Hint

Explanation for sample 11:

Below is one of the best strategies for delivering orders. If you choose to deliver to the second window, it will not increase the company’s profit.

Explanation for sample 22:

You only need to clone a robot once to deliver to the first window, because this newly cloned robot can continue to deliver to the second window. Additional cloning to deliver to the third window is not cost-effective.

Below is the table of scores and special properties for each subtask. For the full Constraints, see the input format.

Subtask Score Special Property
11 2424 n100,m100,hi100n \le 100, m \le 100, h_i \le 100
22 1212 n=0n = 0
33 1414 n=1n = 1
44 1515 m=1m = 1
55 1717 c=1,p=106c = 1, p = 10^6 and all obstacle heights are 11
66 1818 None

Translated by ChatGPT 5