eolymp
bolt
Try our new interface for solving problems
Məsələlər

Formula 1

Formula 1

The Formula 1 season consists of a series of races, known as Grand Prix, organized by the International Federation of Automobile (FIA). The results of each Grand Prix are combined to determine Pilots' World Championship. More specifically, for each race some points are distributed to pilots, depending on their classification in the race. At the end of the season, the pilot who has earned the most points is declared the World Champion. Formula 1 organisers change constantly the competition rules, aiming to provide more excitement to fans. One rule modified for the 2010 season was the distribution of points in each Grand Prix. Since 2003, the scoring rule rewarded the top eight pilots, according to the following table That is, the winning driver received \textbf{10} points, second place received \textbf{8} points, and so on. In the 2010 season the top ten will receive points, obeying the following table: The change in the scoring system led to much speculation about what would have been the effect to the World Championship in the past if the new score had been used. For example, would Lewis Hamilton have been champion in 2008, considering he and Felipe Massa were separated by just one point? To end the speculation, FIA hired you to write a program that, given the results of each race of a season determines the World Champion for different scoring systems. \InputFile The input contains several test cases. The first line of a test case contains two integers \textbf{G} and \textbf{P} separated by a blank space, indicating the number of Grand Prix (\textbf{1} ≤ \textbf{G} ≤ \textbf{100}) and the number of pilots (\textbf{1} ≤ \textbf{Q} ≤ \textbf{100}). Pilots are identified by integers from \textbf{1} to \textbf{P}. Each of the following \textbf{G} lines indicates the result of a race, and contains \textbf{Q} integers separated by spaces. On each line, the \textbf{(i)}-th number indicates the order of arrival of pilot \textbf{i} in the race (the first number indicates the order of arrival of a pilot \textbf{1} in that race, the second number indicates the order of arrival of pilot \textbf{2} in that race and so on). The next line contains a single integer \textbf{S} indicating the number of scoring systems (\textbf{1} ≤ \textbf{S }≤ \textbf{10}). After that, each of the following lines \textbf{S} contains a description of a scoring system. The description of a scoring system begins with an integer \textbf{K} (\textbf{1} ≤ \textbf{K} ≤ \textbf{P}), indicating the last finishing order to receive points, followed by a blank space, followed by \textbf{K} integers \textbf{k_0}, \textbf{k_1}, ..., \textbf{k_\{n-1\}} (\textbf{1} ≤ \textbf{k_i} ≤ \textbf{100}) separated by spaces, indicating the number of points to be assigned (the first integer indicates the points for first place, the second integer indicates the points for second place and so on). The last test case is followed by a line containing only two zeros separated by a blank space. \OutputFile For each scoring system in the input your program must print one line, containing the identifier of the World Champion. If more than one pilot are World Champions (ie, if there is a tie), the line must contain all World Champions, in increasing order of identifier, separated by a space.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
1 3
3 2 1
3
3 5 3 2
3 5 3 1
3 1 1 1
3 10
1 2 3 4 5 6 7 8 9 10
10 1 2 3 4 5 6 7 8 9
9 10 1 2 3 4 5 6 7 8
2
5 5 4 3 2 1
3 10 5 1
2 4
1 3 4 2
4 1 3 2
2
3 3 2 1
3 5 4 2
0 0
Çıxış verilənləri #1
3
3
1 2 3
3
3
2 4
4
Mənbə Maratona de Programa¸c˜ao da SBC – ACM ICPC – 2010