2002 LSU Computer Science High School Programming Contest

Sponsored by Microsoft

Novice - Problem 6

Tropical Trouble

Add the life of a pirate as yet another notch in Sam Slacker's belt of 'dubious jobs'. Consistently the last to wake, the most inefficient worker, and the tail end of any off-ship trip, it's unsurprising that his mates managed to, ah, accidentally forget him on one of their excursions. This is how Sam found himself on the small Caribbean island of Lolé.

Lolé features sweeping mountains, lush forests, and beautiful sandy beaches. However, it lacks any consistent source of fresh water. The mountain streams are quickly swallowed by brackish swampland, and the forests seem to draw their nourishment out of thin air.

Despite this, a small village manages to exist on Lolé, which produces drinkable water with an ingenious method. They pour buckets of salt water into a central basin during the cool morning hours. A large clear plastic dome sits above the basin, and the heat of the sunlight causes the collected water to evaporate. Instead of escaping into the atmosphere, the water condenses on the plastic shell. At night, when the temperature drops, the water runs down the dome and collects in a circular fresh-water catch-all. The Loléians draw their water from that catch-all, and life is good.

Sam has befriended the Loléians--they are particularly clueful when it comes to slack--and they have agreed to let him stay until the next cruise ship passes by, in exchange for a little work from him. After sizing him up, they have decided that he's good for keeping track of the amount of water that the village produces. Using his handy solar-powered PDA, he decides to write a program to figure it all out so he can spend time chilling in the tropical paradise . . .

Description:

Your task is to help Sam write the program that calculates how much water the Loléians produce over a period of days. The size of the basin is known, and the methods used are simple. Every morning, the citizens pour some amount of water into the basin. It's hard to see just how much water is in the basin in the weak pre-dawn light, so it's quite probable that they try to pour in more than the basin can handle, in which case it simply spills over. The catch-all is far enough away that none of the salt water from an overfill will pour into it. Each day has a certain number of hours of sunlight, and during a given day the amount of water evaporated can be averaged to some number of gallons per hour. Any water not evaporated in a given day stays in the basin. Note that the sun may be strong enough to evaporate all of the water in the basin; no new water is added during the day due to not wanting water vapour to escape, so all of the water may evaporate, but no more than is available.

For each simulation, the basin starts out empty. Any number n fits within a 32-bit signed integer, including the results of any necessary calculation.

Input:

The first piece of data in the file is the number of simulations to run, represented by a non-negative integer. For each simulation, the first piece of data is the capacity of the village basin in gallons. The next piece of data, d, is the number of days that the simulation will run. Each day is represented by three lines of data, each line with a single non-negative integer. The first integer is the amount of water added; the second integer is the number of hours of sunlight that the basin received; the third integer is the average gallons per hour that the sun can evaporate that day.

Output:

For each simulation, print

	Simulation x: The village produced t gallons of water.
where x is the simulation number, starting from 1, and t is the total number of gallons of fresh water generated during the simulation.

Sample Input:

2	Number of simulations
100	Size of basin in the first simulation
3	Number of days that the first simulation runs
50	Amount of water added to the basin the first day
5	Number of hours of sunlight the first day
5	Average gallons/hour the sun could evaporate
80	Amount of water added to the basin the second day
10	Number of hours of sunlight the second day
5	Average gallons/hour the sun could evaporate
0	Amount of water added to the basin the third day
10	Number of hours of sunlight the third day
6	Average gallons/hour the sun could evaporate
10	Size of basin in the second simulation
1	Number of days that the second simulation runs
100	Amount of water added to the basin in the first day
10	Number of hours of sunlight the first day
10	Average gallons/hour the sun could evaporate

Sample Output:

Simulation 1: The village produced 125 gallons of fresh water.
Simulation 2: The village produced 10 gallons of fresh water.