問題一覧 > 通常問題

No.2623 Room Allocation

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 139
作問者 : 👑 AngrySadEight / テスター : Magentor zeta7532
お気に入りにしたユーザー ProblemId : 10482 / 自分の提出
問題文最終更新日: 2024-01-10 03:07:06
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 417 (順位表) の他の問題:

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 A or B.

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もしくは右上の雲マークをクリックしてアカウントを作成してください。