#P14089. [ICPC 2023 Seoul R] K-Lottery
[ICPC 2023 Seoul R] K-Lottery
题目描述
-Lottery awards only one winner in each round. For each round, tickets are produced and each ticket contains different numbers from to , and no two tickets are identical. Among the tickets produced each round, tickets are sold. The draw is conducted as follows each round. While randomly generating () distinct numbers one by one, if the relative order of the last consecutive numbers matches the numbers on any of the sold tickets, the draw ends immediately, and the corresponding ticket wins. Some rounds may not have any winning tickets.
For instance, let's consider a round where tickets are produced (). The ticket sequences produced are , and . Among them, let's say and are sold (). Let's assume that the following random numbers are scheduled to be generated (). Then the relative order of , say matches the sold ticket , so that ticket wins.
In another scenario, let's consider a round where tickets are produced (). The ticket sequences produced are , and . Among them, let's assume $(1, 2, 3, 4), (1, 2, 4, 3), (3, 4, 1, 2), (4, 1, 2, 3)$, and are sold (). Let's assume that the following random numbers are scheduled to be generated (). Then the relative order of , say matches the sold ticket , so that ticket wins.
Given information about a round of the -Lottery, including the number of produced tickets, the number sequences of the sold tickets, and the sequence scheduled to be randomly generated for the winning ticket, write a program to output the number sequence of the winning ticket.
输入格式
Your program is to read from standard input. The input starts with a line containing three integers, , and ($3 \le K \le 10,000 , 1 \le M\le \min (K!, 1,000) , K\le N\le 1,000,000 , 3\le KM \le 100,000$), where is the number of numbers in each ticket, is the number of tickets sold, and is the number of numbers in the randomly generated sequence of the round. In each of the following lines, integers of a ticket sold in the round are given. The final line contains different positive integers () which is the number sequence for determining a winner.
输出格式
Your program is to write to standard output. Print exactly one line. The line should contain the number sequence of the winning ticket. If there is no winning ticket, print 0
.
3 2 10
1 2 3
1 3 2
20 35 10 7 99 53 72 33 88 16
1 3 2
4 5 10
1 2 3 4
1 2 4 3
3 4 1 2
4 1 2 3
4 2 3 1
19 31 9 1 89 48 63 30 78 12
4 2 3 1
3 3 7
1 3 2
2 3 1
2 1 3
11 22 33 44 55 66 77
0