The Crow's Last Attack
Time limit2sMemory limit512 MB
Simulate a crow that attacks around a circular line of enemies, reversing on kills, and report which enemy takes the last attack.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
A hero summons a crow that attacks a line of enemies.
The line holds enemies, numbered to from left to right. Enemy starts with hitpoints. The two ends of the line are connected. Moving right past enemy leads to enemy , and moving left past enemy leads to enemy .
The crow starts on enemy facing right. One attack subtracts hitpoints from the enemy the crow stands on. An enemy whose hitpoints drop to or below is dead.
After every attack the crow follows these rules.
- If the attack killed the enemy, the crow immediately reverses its direction.
- The crow then moves in its current direction to the nearest enemy that is still alive, passing over dead enemies without attacking them.
The crow attacks times. If every enemy is dead before that count is reached, the crow stops attacking.
Print the number of the enemy that receives the crow's last attack.
Input
The first line contains the number of test cases ().
The first line of each test case contains two space-separated integers and , the number of enemies and the crow's damage (, ). The next line contains integers , the initial hitpoints of the enemies in order ().
Output
For each test case, print the number of the enemy that receives the crow's last attack on its own line.