#Q246. 「一本通 6.7 练习 1」取石子游戏
「一本通 6.7 练习 1」取石子游戏
Description
Original source: BeiJing 2009 WC
Little H and Little Z are playing a stone-picking game. The rules of the game are as follows: each player can take a certain number of stones from a pile during their turn. The number of stones that can be taken each time is limited, and the player who cannot make a move loses the game. Little H goes first, and he wants to know if he has a winning strategy. If he does, he also wants to know how to make the first move.
Input Format
The first line contains the number of stone piles, .
The next lines each contain a number , representing the number of stones in each pile. The following line is the number of types of stone-picking moves, .
The next lines each contain a number , representing the allowed number of stones that can be taken in a single move.
The input guarantees that these numbers are given in increasing order.
Output Format
The first line should be YES or NO, indicating whether Little H has a winning strategy.
If the result is YES, the second line should contain two numbers: the first indicates which pile to take stones from, and the second indicates how many stones to take. If there are multiple possible answers, choose the one with the smallest pile number. If there are still multiple answers, choose the one with the smallest number of stones to take.
Sample 1
The sample input consists of four piles of stones with counts of . Each player can take either or stones from any pile in a single move. Little H has a winning strategy; in fact, he can simply take one stone from the first pile.
4
7
6
9
3
2
1
2
YES
1 1
Constraints and Hints
For all data, .