luogu#P7979. 「Stoi2033」世界未末日 加强版

「Stoi2033」世界未末日 加强版

Background

Note: Using submission feedback to obtain testdata is cheating.

Even if the world is about to collapse
My dear, I will never shed a tear
I will not give up that feeling of having loved
Cherishing everything that remembers you
Even if the world is about to tilt
My dear, I will never say goodbye
Even if the doomsday threat is stronger than ever
With love, it is not tiring
—— "The World Has Not Ended Yet"

Problem Description

Vinsta and Stella have nn piles of stones, and the ii-th pile has sis_i stones.

They agree to take turns starting from Vinsta. In each move, one may choose at least 11 pile and at most kk piles. For the ii-th pile, one may choose two real numbers a,ba, b such that:

  • a×b=sia \times b = s_i
  • a+b=c,c[1,si]Za + b = c, c \in [1, s_i] \cap \Z

Then discard cc stones from the ii-th pile, i.e., sisics_i \leftarrow s_i - c. The player who cannot make a move loses. They want to know whether Vinsta has a winning strategy.

Input Format

The first line contains a positive integer TT, the number of test cases.

Then follow TT test cases. For each test case, the first line contains three positive integers n,k,Sn, k, S, where S=max{si}S = \max\{s_i\}.

The second line contains nn positive integers sis_i, representing the initial number of stones in the ii-th pile.

Output Format

For each test case, output one line. If there is a winning strategy, output YES, otherwise output NO.

2
7 1 13
2 3 4 5 7 10 11
8 1 13
2 3 4 5 7 10 11 13

YES
NO

1
7 2 100
19 26 8 17 11 45 14

YES

Hint

For 100%100\% of the testdata, 1T101 \le T \le 10, 1kn3×1061 \le k \le n \le 3 \times 10^6, 1S3×10171 \le S \le 3 \times 10^{17}.

Translated by ChatGPT 5