#P6015. [CSGRound3] 游戏

[CSGRound3] 游戏

Description

There is a deck with a total of nn cards. The ii-th card has a number aia_i written on it, where the first card is the top of the deck.

Player Z draws first. He may draw a consecutive number of cards starting from the top of the deck (he may draw 00 cards). The drawn cards are held in his hand, meaning they are removed from the deck.

Then Player Y draws. Similarly, she may draw a consecutive number of cards starting from the top of the deck (she may draw 00 cards).

If the sum of the numbers on a player's hand is greater than XX, then their score is 00; otherwise, their score equals the sum.

The player with the higher score wins; if the scores are equal, then nobody wins.

In order to win, Player Z uses a cheating tool (x-ray vision), meaning he knows the number written on every card in the deck.

Now, for all integers XX satisfying 1XK1 \leq X \leq K, determine which values of XX allow Player Z to have a winning strategy, i.e., after Player Z finishes drawing, no matter how Player Y draws, Player Y will definitely lose.

Input Format

The first line contains an integer nn, representing the number of cards in the deck.

The second line contains nn integers a1na_{1\dots n}, representing the number written on each card.

The third line contains a positive integer KK, as described in the statement.

Output Format

The first line contains an integer, representing the number of values XX that satisfy the requirement.

The second line outputs the values of XX that satisfy the requirement in increasing order, separated by spaces.

5
1 4 3 2 2
5

3
1 2 3

Hint

[Sample Explanation]

When X=1,2,3X=1,2,3, Player Z draws one card, and no matter how Player Y draws, Player Y will get a score of 00.

When X=4X=4, if Player Z draws 11 card, then if Player Y draws 11 card, Player Y will win; otherwise, Player Z can only get a score of 00.

When X=5X=5, if Player Z draws 11 card, then if Player Y draws 11 card, Player Y will win. If Player Z draws 22 cards, then Player Y also draws 22 cards, resulting in a tie. Otherwise, Player Z can only get a score of 00.


[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (3 points): n=1n = 1.
  • Subtask 2 (14 points): K=1K = 1.
  • Subtask 3 (20 points): n,K100n, K \le 100.
  • Subtask 4 (33 points): n,K3333n, K \le 3333.
  • Subtask 5 (30 points): no special restrictions.

For 100%100\% of the testdata, 1n,K1061 \leq n, K \leq 10^6, 1aiK1 \leq a_i \leq K.

Translated by ChatGPT 5