Problem A
CS2040DE Assignment 1: Farm Management System
In a dungeon, special buffs enhance monsters, giving them better meat quality than those raised on the surface. These monsters are highly sought after by surface dwellers, who appreciate the superior quality. The nutrients for raising these monsters are supplied by the dungeon itself, eliminating additional resource costs. Kattis has decided to lease a farm in this dungeon to raise monsters and generate a stable income by selling them to surface dwellers.
Kattis can perform operations such as buyMonster, raiseMonster, and sellMonster. Assist Kattis in managing this farm.
After leasing a farm that can accommodate up to N monsters, Kattis has X gold coins remaining. The supplier offers three types of monsters: Walking Mushroom, Snake Tail Chicken, and Aquatic Horse, each bought per unit and sold based on weight (kg). Each type of monster has an initial purchase weight and can gain weight daily at a variable rate specified during purchase.
Monster Types
Monster Type 
Walking Mushroom 
Snake Tail Chicken 
Aquatic Horse 
Purchase Price (gold/monster) 
5 
20 
84 
Purchase Weight (kg) 
1 
2 
4 
Daily Weight Gain Range (kg) 
1 to 2 
1 to 4 
1 to 3 
Selling Price (gold/kg) 
1 
4 
6 
Requirements

Buying Monsters: When Kattis buys monsters, they must specify the daily weight gain within the allowed range for each type. The entire purchase operation is invalid if Kattis does not have enough gold or if the farm’s capacity is full.

Selling Monsters: Always sell the heaviest monsters first. If there are not enough monsters to meet a selling demand, the operation is invalid.

Raising Monsters: Increase the weight of all monsters based on the specified daily weight gains.
Input
The first line contains two integers $X$ and $N$, representing the initial amount of gold coins and the farm’s maximum capacity in terms of the number of monsters.
Each subsequent line consists of four integer values separated by a space:

The first value indicates the operation type: 0 for buy, 1 for sell, 2 for raise, 3 for cleanup.

The second value indicates the type of monster (0 for Walking Mushroom, 1 for Snake Tail Chicken, 2 for Aquatic Horse) or the number of days to raise (in the case of a raise operation).

The third value indicates the number of monsters to buy or sell.

The fourth value indicates the daily weight gain (only relevant for buy operations).
Output
After each operation, output the remaining number of coins and the remaining farm capacity.
If a purchase or sale cannot be made, the remaining number of coins and remaining farm capacity remain unchanged.
Example 1
Input
50 10 0 1 1 1 0 0 2 2 2 7 1 1 1 1 1 1 3 1 1 1
Output
30 9 20 7 20 7 56 8 86 10
Explanation:
1. Initial Setup:
Gold: 50 coins
Farm Capacity: 10 monsters
2. Step 1: 0 1 1 1 (Buy Operation)
Operation: Buy 1 Snake Tail Chicken with a daily weight gain of
1 kg/day.
Cost: 1 * 20 = 20 coins
Remaining Coins: 50  20 = 30 coins
Remaining Capacity: 10  1 = 9 monsters
3. Step 2: 0 0 2 2 (Buy Operation)
Operation: Buy 2 Walking Mushrooms, each with a daily weight
gain of 2 kg/day.
Cost: 2 * 5 = 10 coins
Remaining Coins: 30  10 = 20 coins
Remaining Capacity: 9  2 = 7 monsters
4. Step 3: 2 7 1 1 (Raise Operation)
Operation: Raise all monsters for 7 days.
No change in coins or capacity.
Weight Gain:
Snake Tail Chicken: 1 monster at 9 kg (2 kg initial + 7 days *
1 kg/day).
Walking Mushrooms: 2 monsters, each at 15 kg (1 kg initial + 7
days * 2 kg/day).
5. Step 4: 1 1 1 1 (Sell Operation)
Operation: Sell 1 Snake Tail Chicken.
Earnings: 9 kg * 4 coins/kg = 36 coins
Remaining Coins: 20 + 36 = 56 coins
Remaining Capacity: 7 + 1 = 8 monsters
6. Step 5: 3 1 1 1 (Cleanup Operation)
Operation: Sell all remaining monsters.
Earnings:
Walking Mushrooms: 2 monsters, each at 15 kg * 1 coin/kg = 30
coins.
Final Coins: 56 + 30 = 86 coins
Final Capacity: 10 monsters (all slots now empty).
Example 2
Input
240 5 0 2 2 2 0 1 3 1 2 7 1 1 1 1 2 1 1 2 2 1 3 1 1 1
Output
72 3 12 0 12 0 84 2 300 4 336 5
Explanation:
1. Initial Setup:
Gold: 240 coins
Farm Capacity: 5 monsters
2. Step 1: 0 2 2 2 (Buy Operation)
Operation: Buy 2 Aquatic Horses.
Cost: 2 * 84 = 168 coins
Remaining Coins: 240  168 = 72 coins
Remaining Capacity: 5  2 = 3 monsters
3. Step 2: 0 1 3 1 (Buy Operation)
Operation: Buy 3 Snake Tail Chickens.
Cost: 3 * 20 = 60 coins
Remaining Coins: 72  60 = 12 coins
Remaining Capacity: 3  3 = 0 monsters
4. Step 3: 2 7 1 1 (Raise Operation)
Operation: Raise all monsters for 7 days.
No change in coins or capacity.
Weight Gain:
Aquatic Horses: 2 monsters, each at 18 kg.
Snake Tail Chickens: 3 monsters, each at 9 kg.
5. Step 4: 1 1 2 1 (Sell Operation)
Operation: Sell 2 Snake Tail Chickens.
Earnings: 2 * 9 kg * 4 coins/kg = 72 coins
Remaining Coins: 12 + 72 = 84 coins
Remaining Capacity: 0 + 2 = 2 monsters
6. Step 5: 1 2 2 1 (Sell Operation)
Operation: Sell 2 Aquatic Horses.
Earnings: 2 * 18 kg * 6 coins/kg = 216 coins
Remaining Coins: 84 + 216 = 300 coins
Remaining Capacity: 2 + 2 = 4 monsters
7. Step 6: 3 1 1 1 (Cleanup Operation)
Operation: Sell all remaining monsters.
Earnings: 1 Snake Tail Chicken, 9 kg * 4 coins/kg = 36
coins.
Final Coins: 300 + 36 = 336 coins.
Final Capacity: 5 monsters (all slots now empty).
Sample Input 1  Sample Output 1 

50 10 0 1 1 1 0 0 2 2 2 7 1 1 1 1 1 1 3 1 1 1 
30 9 20 7 20 7 56 8 86 10 
Sample Input 2  Sample Output 2 

240 5 0 2 2 2 0 1 3 1 2 7 1 1 1 1 2 1 1 2 2 1 3 1 1 1 
72 3 12 0 12 0 84 2 300 4 336 5 