Brownies vs. Candies vs. Cookies
Time limit1sMemory limit1024 MB
For each practice, double the brownie count whenever a group is at least as large as the remaining brownies, then print the count left after each group takes one.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Everyone is welcome to the UCF Programming Team practices, and many students take advantage of this opportunity. The main benefit is that these students improve their problem solving and programming skills. Another benefit is that they enjoy the refreshments Dr. Orooji brings every week! Dr. O usually brings candies, but sometimes he brings cookies or brownies. Brownies are very popular and do not usually last long. Dr. O has to find a clever trick to make the brownies last longer, so that the students stay for the entire practice. The easiest solution is to cut the brownies in half. That doubles the number of brownies.
Given the original number of brownies and the number of students in each group that wants brownies, track the brownie count as Dr. O cuts them in half.
If a group of students approaches the refreshment table and Dr. O sees that the number of remaining brownies is less than or equal to the number of students in the group, Dr. O cuts the brownies in half so that they will not all be gone after each student in the group takes one. Dr. O cuts the brownies as many times as needed. For example, if there are 3 brownies left and 24 students approach the table, Dr. O has to cut the brownies four times (3 → 6 → 12 → 24 → 48) so that the brownies will not all be gone after each student grabs one.
Input
The first line contains a positive integer n, the number of practices. Each practice starts with a line containing two integers s and b, separated by a space. Here s is the number of students in the practice (between 1 and 30 inclusive), and b is the number of brownies Dr. O brought that day (between 60 and 600 inclusive).
The next line for the practice contains a positive integer m, the number of groups that approach the refreshment table. Then come the m group sizes, one number per line. The input values are valid. Each group has at least 1 student, and no group is larger than the number of students in the practice.
Output
For each practice, first print 'Practice #p: s b', where p is the practice number starting from 1, s is the number of students, and b is the number of brownies.
Then print one line for each group. The line contains the number of students in the group and the number of brownies left after each student in the group has grabbed one. Cutting may happen before the grabbing. Leave a blank line after the output for each practice.