Yeongwoo and God4
Time limit1.5sMemory limit512 MB
Given a character and a sequence of monsters generated by recurrence, decide whether the character survives all N fights in order and print the final stats or -1.
- Level
Medium6 of 10
- Topics
- Simulation, Math, Implementation, Number theory
- Solved
- No attempts yet
Problem
Yeongwoo is playing a game called God4 again. In God4 every character and every monster has an attack , a defence , and a maximum health . Combat is always one on one and runs by these rules.
- On your turn you attack the other side. The defender loses the larger of (attacker's attack defender's defence) and health.
- When the attack ends, the turn passes to the other side.
- The two sides keep taking turns until one side's health drops to or below. The side whose health drops first loses.
- Yeongwoo's character always attacks first.
When the character wins, it absorbs the monster's stats exactly as they are. A character with stats that beats a monster with stats ends up with . Every win also restores the character's health to its maximum, so every fight starts at full health.
Yeongwoo wants to beat monsters in a row without a single loss, which means he has to win every fight. Listing the data of all monsters would make the input far too large, so the stats of the -th monster for come from these formulas.
Input
The program reads from standard input.
The first line contains the number of monsters . ()
The second line contains the attack , the defence , and the maximum health of Yeongwoo's character, in that order. (, , )
The third line contains the attack , the defence , and the maximum health of the first monster, in that order. (, , )
The fourth line contains the values , , , , , used to generate the monster stats, in that order. (, , , )
Output
The program writes to standard output.
If Yeongwoo beats all monsters, print the character's final stats on one line in the order attack, defence, maximum health, separated by single spaces. Print each of the three values modulo .
If he loses even once, print -1 on the first line and nothing else.