問題一覧 > 通常問題

No.586 Double Booking

レベル : / AI推定難易度 : 118 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 540
作問者 : No / テスター : ciel
お気に入りにしたユーザー ProblemId : 1779 / 自分の提出
問題文最終更新日: 2026-06-25 06:17:40
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 176 (順位表) の他の問題:

Problem Statement


Yuki Hotel accepts reservations over the Internet.
However, one day a system malfunction occurred, and reservations came to be accepted
even for rooms that had already been reserved.
As a result, reservations overlapped, and for the guests who could not stay,
the hotel decided to refund their charges and then transfer them to another hotel at Yuki Hotel's expense.

Given the room charge of Yuki Hotel (P1), the room charge of the transfer destination hotel (P2), and the reservation status of Yuki Hotel (R),
calculate the amount of Yuki Hotel's loss (C) for this day.
The loss is calculated as follows.

(Loss of Yuki Hotel) = (Opportunity loss of Yuki Hotel) + (Cost of the transfers)

The opportunity loss is the amount that Yuki Hotel
would have earned if there had been no overlaps.

(Hint)
Even if reservations overlap for one room, one party of guests can stay.
For example, even if a single room has 3 reservations,
one party of guests can stay, and two parties of guests need to be
transferred.

Input

P1
P2
N
R1
...
Rn

P1 --- Room charge of Yuki Hotel
P2 --- Room charge of the transfer destination hotel
N --- Number of reservations
R1 --- Reserved room number
・
・
・
Rn

1 ≤ P1,P2 ≤ 100,000
1 ≤ N ≤ 100
1 ≤ R ≤ 999

Output

C --- Amount of Yuki Hotel's loss

Sample

Sample 1
Input
20000
17000
3
302
511
511
Output
37000

Reservations overlapped for room 511.
The loss of Yuki Hotel is 37000.

Sample 2
Input
30000
50000
5
402
402
605
605
605
Output
240000

Reservations overlapped for rooms 402 and 605.
The loss of Yuki Hotel is 240000.

Sample 3
Input
12000
7200
10
112
309
402
510
102
201
305
304
401
302
Output
0

There were 10 reservations, but no overlaps occurred.
The loss is 0.
There are also cases where no overlap occurs at all.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。