No.2623 Room Allocation
タグ : / 解いたユーザー数 139
作問者 : 👑
Magentor
Problem Statement
There is a shop that offers rental rooms. In this shop, $1$ machine is installed per $1$ room.
There are $2$ types of machines, machine A and machine B: $X$ rooms have machine A installed, and $Y$ rooms have machine B installed.
It is known that $N$ groups of customers, customers $1, 2, \dots, N$, will come to the shop in this order. Customer $i$ consists of $P_i$ people and wants a room with machine $c_i$ installed.
When customers come, the shop shows them to a room as follows.
- If there are rooms with no customers, choose one of them and show all members of the arriving customer to that room.
- If there is no room without customers, make all members of the customer who was shown to a room earliest among the customers in the shop leave. Then show all members of the newly arrived customer to the room that the departed customer occupied.
Find the maximum number of people who can be shown to a room with the machine they want (note that this is not the maximum number of customer groups).
Customers never leave voluntarily unless the shop orders them to leave.
Constraints
- $N, X, Y, P_i$ are integers.
- $1 \leq N \leq 2 \times 10^5$
- $0 \leq X, Y \leq 2 \times 10^5$
- $X + Y \geq 1$
- $1 \leq P_i \leq 10^9$
- $c_i$ is
AorB.
Input
The input is given from standard input in the following format.
$N$ $X$ $Y$ $P_1$ $c_1$ $P_2$ $c_2$ $\vdots$ $P_N$ $c_N$
Output
Print the answer.
Sample
Sample 1
Input
6 1 2 1 A 2 B 3 B 3 A 2 B 1 A
Output
11
You can show the customers to rooms as follows.
- Show customer $1$ to a room with machine A.
- Show customer $2$ to a room with machine B.
- Show customer $3$ to a room with machine B.
- Make customer $1$ leave, and show customer $4$ to the room where customer $1$ was. That room has machine A.
- Make customer $2$ leave, and show customer $5$ to the room where customer $2$ was. That room has machine B.
- Make customer $3$ leave, and show customer $6$ to the room where customer $3$ was. That room has machine B.
In this case, all customers except customer $6$ are shown to a room with the machine they want, and the number of such people is $1 + 2 + 3 + 3 + 2 = 11$. It is not possible to show more people to rooms with the machine they want.
Sample 2
Input
9 100 0 1 B 2 B 3 B 4 B 5 B 6 B 7 B 8 B 9 B
Output
0
Every customer wants machine B, but every room has machine A installed. Therefore, no customer can be shown to the room they want.
Sample 3
Input
8 2 2 1 B 9 A 7 A 7 B 5 A 8 B 4 B 8 A
Output
27
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。