eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Arm Wrestling Tournament

Arm Wrestling Tournament

As you might have heard, Mr. Kumis is holding an arm wrestling tournament. There are \textbf{2^N} contestants who will participate in this tournament numbered from \textbf{1} to \textbf{2^N}. The first contestant (\textbf{C_1}) will compete with the second contestant (\textbf{C_2}). \textbf{C_3} will compete with the \textbf{C_4}, and so on. The winner of \textbf{C_1} and \textbf{C_2} will compete with the winner of \textbf{C_3} and \textbf{C_4}. The winner of \textbf{C_5} and \textbf{C_6} will compete with the winner of \textbf{C_7} and \textbf{C_8}, and so on (see the diagram below). \includegraphics{https://static.e-olymp.com/content/40/40a4f976bb19d7e19db1e4aad4e99c878e06b9cb.jpg} Each contestant initially has \textbf{P_i }strength. When two contestants wrestle, the stronger one will win and his strength will be reduced as much as his enemy's strength. However, before his next match, he has time to regain his strength and will recover at most \textbf{K} strength but his strength will not exceed his initial strength (\textbf{Pi}). If two contestants possess an equal strength then the contestant with smaller index will win. Given the initial strength of all contestants, determine who will win the tournament and which contestant he will beat. \InputFile The first line of input contains an integer \textbf{T} (\textbf{T} ≤ \textbf{100}) denoting the number of testcases. Each testcase begins with two integer \textbf{N} (\textbf{1} ≤ \textbf{N} ≤\textit{ }\textbf{15}) and \textbf{K} (\textbf{0} ≤ \textbf{K} ≤ \textbf{1, 000}). The next line contains \textbf{2^N} integers \textbf{Pi} (\textbf{1} ≤ \textbf{Pi} ≤ \textbf{1, 000}) denoting the initial strength of \textbf{i}-th contestant for \textbf{i} = \textbf{1..2^N}. \OutputFile For each testcase, print two lines. The first line contains an integer, the winner of the tournament. The second line contains \textbf{N} integers which are all contestants the winner beat based on match order. Each integer is separated by a single space.
Лимит времени 3 секунды
Лимит использования памяти 64 MiB
Входные данные #1
3
3 0
100 90 79 37 60 50 39 95
2 10
50 50 60 60
2 10
3 5 60 59
Выходные данные #1
8
7 5 3
1
2 3
3
4 2
Источник ACM-ICPC 2010 Jakarta