11

Can someone help me with this question?

 8 months ago
source link: https://codeforces.com/blog/entry/124377
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Can someone help me with this question?

can someone help me with this question

A brave Knight "A" has an array of monsters to face, and will use a combination of might and magic to defeat as many as possible. In this challenge we'd like to know if the knight is successful at defeating them all, and if not, how many monsters are defeated. A can see the monsters and their order ahead of time. Despite being evil monsters they will politely queue and challenge A in the current order. Knowing this, A can plan what to do so that it is optimal.

The first monster will always be defeated by A's squires while A prepares for battle For each other monster there are two possibilities :

1.If the current monster is weaker than the previous one (i.e. monsters[current] < monsters[current-1]), The enemy surrenders — what goblin would face someone who has just defeated a dragon?

2.If the current monster is stronger than the previous one (i.e. monsters[current] > monsters[current-1]), then A has two options :

2.1) Might! A fights the monster taking damage (reducing hit points by the difference between the current and the previous monster). 2.2) Magic! A can drink an invulnerability potion, defeating the monster without taking damage.

Write a function that takes as initial parameters A list of monsters in order of how A will face them, with their strength as values; A’s initial hit points; A’s amount of invulnerability potions. And returns The 0-based index of the last monster A defeated.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK