#P11027. [COTS 2020] 餐厅 Restoran
[COTS 2020] 餐厅 Restoran
Background
Translated from Izborne Pripreme 2020 (Croatian IOI/CEOI Team Selection) D2T2。。
Problem Description
There are people queuing in front of a Soviet restaurant, numbered in order.
There is only one dish in the restaurant, and it is also the signature dish—fried eggs. There is no chef in the restaurant, so the food is cooked by the customers themselves.
Due to limited equipment, at any moment, at most one person can cook, and at any moment, at most one person can eat.
Define the “total dining time” as the time needed from when the first person starts preparing food to when the last person finishes eating.
Cooking and eating do not have to follow the queue order; a customer who cooks earlier may eat later.
Person has cooking time and eating time . You need to find the minimum possible total dining time under an optimal arrangement.
In addition, there are events:
- : A new customer arrives, with cooking time and eating time . Suppose this is the -th arriving new customer, then their number is .
- : Customer leaves the queue.
- : The customers are very impatient and want to know the optimal strategy that makes the total dining time as short as possible.
For the first two types of events, you need to output the minimum total dining time after the event ends.
For the third type of event, you need to output the best cooking order and eating order at that moment.
Input Format
The first line contains two positive integers .
The next lines: the -th line contains two positive integers .
The next lines: each line describes an event.
The testdata guarantees that all events are valid, and at every moment there is at least one customer.
Output Format
Output lines.
The first line outputs the minimum total dining time initially.
Then for the next lines, for the -th line:
- If the -th event is or , output one integer, the minimum total dining time after this event ends.
- Otherwise, suppose there are currently customers, output integers describing an optimal strategy: the first integers are the cooking order, and the last integers are the eating order.
2 1
1 3
2 3
POREDAK
7
1 2 1 2
1 4
4 3
DOLAZI 3 8
DOLAZI 5 2
ODLAZI 1
ODLAZI 3
7
14
16
13
11
Hint
Constraints
For of the testdata, it is guaranteed that:
- ;
- ;
- All events are valid, and at every moment there is at least one customer;
- There are at most events.
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| A | ||||
| B | ||||
- Special Property A: Only events.
- Special Property B: There are no events.
Translated by ChatGPT 5