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

Let`s Go to the Movies

Let`s Go to the Movies

\includegraphics{https://static.e-olymp.com/content/40/405327b7775c3b841014482342d99aa85eb198bb.jpg} A favorite pastime for big families in Acmestan is going to the movies. It is quite common to see a number of these multi-generation families going together to watch a movie. Movie theaters in Acmestan have two types of tickets: A \textit{single ticket} is for exactly one person while a \textit{family ticket} allows a parent and their children to enter the theater. Needless to say, a family ticket is always priced higher than a single ticket, sometimes as high as five times the price of a single ticket. It is quite challenging for families to decide which ticket arrangement is most economical to buy. For example, the family depicted in the figure on the right has four ticket arrangements to choose from: Seven single tickets; Two family tickets; One family ticket (for adam, bob, cindy) plus four single tickets for the rest; Or, one family ticket (for bob and his four children) plus single tickets for the remaining two. Write a program to determine which ticket arrangement has the least price. If there are more than one such arrangement, print the arrangement that has the least number of tickets. \InputFile Your program will be tested on one or more test cases. The first line of each test case includes two positive integers (\textbf{S} and \textbf{F}) where \textbf{S} is the price of a single ticket and \textbf{F} is the price of a family ticket. The remaining lines of the test case are either the name of a person going by him/herself, or of the form: \textbf{N_1 N_2 N_3 … N_k} where \textbf{N_1} is the name of a parent, with \textbf{N_2} … \textbf{N_k} being his/her children. Names are all lower-case letters, and no longer than \textbf{1000} characters. No parent will be taking more than \textbf{1000} of their children to the movies :-). Names are unique, the name of a particular person will appear at most twice: Once as a parent, and once as a child. There will be at least one person and at most \textbf{100000} people in any test case. The end of a test case is identified by the beginning of the following test case (a line made of two integers.) The end of the last test case is identified by two zeros. \OutputFile For each test case, write the result using the following format: \textbf{k. NS NF T} Where \textbf{k} is the test case number (starting at \textbf{1}), \textbf{NS} is the number of single tickets, \textbf{NF} is the number of family tickets, and \textbf{T} is the total cost of tickets.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
1 3
adam bob cindy
bob dima edie fairuz gary
0 0
Выходные данные #1
1. 2 1 5