Number Game 2
Time limit2sMemory limit128 MB
Given a set of integers and a cap K on how many may be summed, find the first integer that cannot be formed and decide which player loses at that turn.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Math, Number theory, Greedy
- Solved
- No attempts yet
Problem
Holsoon and Jjaksoon play a number game. Starting from 1, they take turns making consecutive positive integers. Holsoon makes 1 first. After that, each player must make the integer that is exactly 1 larger than the number made on the previous turn.
To make one number, a player may choose and add the given integers in any way, but the total number of chosen integers must not exceed K. The same integer may be chosen more than once.
The integer 1 is always included, so small numbers can be made. However, because the number of chosen integers is limited, not every number is necessarily possible. When the usable integers are 1 and 3 and K is 5, every number through 13 can be made, but 14 cannot.
Given the usable integers and the maximum count K, determine the first number that cannot be made and the player who wins at that number.
Input
The first line contains N, the number of integers used in the game.
The second line contains the N integers in increasing order.
The third line contains K, the maximum number of integers that may be used to make one number.
Output
Print one line in the format <winner> win at <x>.
x is the first positive integer that cannot be made. If x is odd, Holsoon was supposed to make it, so Jjaksoon wins. If x is even, Jjaksoon was supposed to make it, so Holsoon wins.
Print the winner name as either holsoon or jjaksoon.
Constraints
- 1 <= N <= 1,000
- 1 <= K <= 50,000
- Each usable integer is between 1 and 1,000, inclusive.
- The usable integers are distinct.
- The usable integers always include 1.