传统题 100ms 64MiB

A-2 Baggage Carousel

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

bc.png

When a flight arrives, the passengers will go to the Arrivals area to pick up their luggages from a baggage carousel(行李转盘).
Now assume that we have a special airport that has only one pickup window for each baggage carousel. The passengers are asked to line up to pick up their luggage one by one at the window. The carousel can hold at most mm luggages, and each luggage has a unique tag number. When a passenger's tag number is matched by a luggage on the carousel, the luggage is then handed to the passenger and the next luggage will be sent onto the carousel.
But if one arrives at the window yet finds out that one's luggage is not on the carousel, one will have to move to the end of the queue and wait for the next turn. Suppose that each turn takes 1 minute, your job is to calculate the total time taken to clear the baggage carousel.

输入格式

Each input file contains one test case. The first line gives 2 positive integers nn ( 500\le 500 ) and mm ( 50\le 50 ), which are the number of passengers and the size of the baggage carousel, respectively.
Then nn distinct tag number are given in the next line, each is an 8-digit number. The tag numbers are given in the order of being sent to the carousel. It is assumed that min(n,m)\min (n, m) luggages are already on the carousel at the beginning.
The next line gives another sequence of nn distinct tag numbers, which corresponds to the passengers in the queue.
All the numbers in a line are separated by a space.

输出格式

For each test case, print in a line the total time taken to clear the baggage carousel.
Note:
If the tag number of a passenger cannot be found at all, that means the passenger's luggage is lost. In this case you must output in a lineTagNumber is lost!whereTagNumberis the tag number, and then remove this passenger from the queue right away. Since the number of luggages is the same as the number of passengers, if one passenger's luggage is lost, there must be one luggage left and the carousel can never be cleared. In this case, output in the last line the total time taken to clear the passengers' queue.

题目示例数据

10 4
00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010
00000010 00000008 00000006 00000001 00000004 00000007 00000003 00000009 00000005 00000002
16
10 4
00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010
00000008 12345678 00000006 00000001 00000004 00000007 87654321 00000009 00000005 00000002
12345678 is lost!
87654321 is lost!
14

PAT2024秋季重现赛

未参加
状态
已结束
规则
IOI
题目
11
开始于
2025-8-3 14:00
结束于
2025-8-3 17:30
持续时间
3.5 小时
主持人
参赛人数
51