You are an audience of Yu-Gi-Oh, the player, Ricky, just won the world championship. However, earthquake is coming and a giant wall is rising which is blocking Ricky’s way so that he can’t leave the place.
At that moment, Ricky wants to summon the monsters to real world then break the wall so that he can get out and receive his reward.
Ricky’s every decision is “Turn-Based”, so he will only make one decision in a turn.
Every turn Ricky will have two decisions:
If Ricky wants to summon the monster with Star Points higher than 4(Star Points > 4), then Ricky needs to sacrifice specific number of monsters. Here is the rule of summon:
Whenever Ricky decides to attack the wall, the damage is based on sum of the Star Points of monsters in the real world.
In the end, you need to explain two things to your Uncle because he wants to know the outcome as well:
Summon -> 4*
//first turn Ricky summons 4 star points monster
//real world:(4*, )
//structure:
real world
/ \
4*
Summon -> 3*
//second turn, Ricky summons 3 star points monster
//real world:(4*, 3*)
//Ricky reach the number of monsters limitation in real world.
//structure:
real world
/ \
4* 3*
Summon -> 5*
//third turn, Ricky summons 5 star points monster
//sacrifice the monster with lower star points in real world first.
//in this case, Ricky will sacrifice 3* monster.
//real world:(4*,5*)
//structure:
real world
/ \
4* 5*
\
3*
Attack
//fourth turn, Ricky does attack
//the wall will receive the damage from sum of star points in real world.
//(4*,5*) -> damage = 4+5 = 9
Summon -> 8*
//fifth turn, Ricky summons 8* monster which needs to sacrifice 2 monsters.
//real world:(4*,5*)->(8*, )
//structure:
real world
/
8*
/ \
4* 5*
\
3*
Summon -> 4*
//sixth turn, Ricky summons 4* monster
//real world:(8*,4*)
//structure:
real world
/ \
8* 4*
/ \
4* 5*
\
3*
Attack
//seventh turn, Ricky does attack
//(8*,4*) -> damage = 8+4 = 12
Attack
//eighth turn, Ricky does attack
//(8*,4*) -> damage = 8+4 = 12
TheEnd
//end tag. if you reach this tag it means the input is over.
how Ricky summon the monsters:
//Ricky's summon structure will be like:
real world
/ \
8* 4*
/ \
4* 5*
\
3*
// Ricky needs to follow the preorder traversing:
->8* 4* 5* 3* 4*
(don't show root node("real world") in your answer!!)
So the answer will be: 8* 4* 5* 3* 4*
Sum of all star points Ricky gave to the wall:
9+12+12=33
So the answer will be 33.
Summon -> 4*
Summon -> 3*
Summon -> 5*
Attack
Summon -> 8*
Summon -> 4*
Attack
Attack
TheEnd
8* 4* 5* 3* 4*
33