#P6015. Winning Strategy in a Card Game
Winning Strategy in a Card Game
Winning Strategy in a Card Game
Consider a deck of (n) cards in which the (i)-th card has a number (a_i) and the first card is at the top of the deck. Two players, Z and Y, take turns picking cards from the top. First, player Z picks a number of consecutive cards from the top (he may even pick 0 cards). Then player Y picks consecutively from the remaining deck (again, she may pick 0 cards).
The scoring rule is as follows: after a player picks his or her cards, let (S) be the sum of the numbers on these cards. If (S \le X) then the score is (S); otherwise (i.e. if (S > X)) the score becomes (0). The player with the higher score wins; if both scores are equal, there is no winner.
Player Z is equipped with a special ability that lets him see the entire deck (i.e. he knows every (a_i)). For each integer (X) in the range (1 \le X \le K), determine whether player Z has a winning strategy. In other words, does there exist a choice of (k) (with (0 \le k \le n)) such that if Z picks the top (k) cards (with a score (S) satisfying (0 < S \le X)), then regardless of how many cards player Y picks afterwards (from the remaining deck), her maximum possible score is strictly less than (S)?
Your task is to output all values of (X) (in increasing order) for which Z can guarantee a win.
inputFormat
The first line contains two integers (n) and (K) representing the number of cards and the maximum possible value of (X), respectively. The second line contains (n) integers (a_1, a_2, \ldots, a_n) --- the numbers written on the cards, in order (with (a_1) at the top).
outputFormat
Output two lines. The first line should contain a single integer (m) denoting the number of values of (X) (within ([1, K])) for which player Z can force a win. The second line should list these (X) values in increasing order, separated by a space. If no such (X) exists, output a single 0 on the first line.
sample
3 10
1 2 3
5
6 7 8 9 10
</p>