#P1323. Baggage Carousel

Baggage Carousel

Baggage Carousel

题目描述

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 m 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 11 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 22 positive integers nn (500≤500) andand mm (50≤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 88-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.

样例 #1

样例输入 #1

10 4
00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000009 00000010
00000010 00000008 00000006 00000001 00000004 00000007 00000003 00000009 00000005 00000002

样例输出 #1

16

提示

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 line TagNumber is lost! where TagNumber is 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.