Bounded Nim
N piles; a move removes between 1 and K stones from ONE pile; last to move wins. Determine the winner under perfect play.
Input: the first line has N and K; the second line has the N pile sizes.
Output: FIRST or SECOND.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ K ≤ 100
- 0 ≤ piles ≤ 109
Sample Tests
Input 1
2 2 4 5
Output 1
FIRST
Input 2
1 3 3
Output 2
FIRST
Discussion (opens after you solve — no spoilers before)
No comments yet.