Back
Close

The Wall Breaker

Statement

 Goal

You are the leader of a Wall Breaker squad in a raid. Your goal is to breach the enemy defenses.
Your squad deals a specific amount of damage D upon explosion.
You are facing a wall composed of N segments. Each segment has a certain amount of Health Points H.

Your mission is to find the weak spot. You must target the wall segment that has the HIGHEST Health Points that your squad can successfully destroy in one hit (meaning H is lower than or equal to D).
If there are multiple segments with the same highest Health Points, target the first one (smallest index).

If all wall segments have more Health Points than your damage D, you cannot breach the wall. In this case, print RETREAT.
Input
Line 1: An integer D representing the damage of your squad.
Line 2: An integer N representing the number of wall segments.
Next N lines: An integer H representing the Health Points of a wall segment (ordered from index 0 to N-1).
Output
The index (0-based) of the optimal wall segment to target, or the string RETREAT if no wall can be destroyed.
Constraints
0 < D ≤ 10000
0 < N ≤ 10
0 < H ≤ 10000
Example
Input
1000
4
2000
100
950
1000
Output
3

Game modes
Fastest, Shortest

Test cases
Standard Breach Test
Input
1000 4 2000 100 950 1000
Output
3

Standard Validation Validator
Input
500 4 500 10 400 20
Output
0

Solid Defense Test
Input
50 3 100 200 60
Output
RETREAT

Impossible Breach Validator
Input
10 4 20 15 12 11
Output
RETREAT

Twin Weaknesses Test
Input
400 4 100 400 10 400
Output
1

Priority Validation Validator
Input
50 4 50 10 50 5
Output
0

Progressive Resistance Test
Input
10000 5 1000 2500 5000 7500 10000
Output
4

Max Values Validator
Input
10000 6 2000 4000 6000 8000 9500 10000
Output
5

Solution language

Solution

Stub generator input