text
stringlengths
0
801
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.
The first line of each test case contains $n$ ($1 \le n \le 3 \cdot 10^5$) — the length of the array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{12}$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
For each test case, output a single integer — the maximum possible length of $a$ after performing some sequence of operations.
In the first test case, we can first choose $i = 4$, since $a_4 = 5 + 1 - 4 = 2$. After this, the array becomes $[2, 4, 6, 2, 5, 0, 0, 0]$. We can then choose $i = 3$ since $a_3 = 8 + 1 - 3 = 6$. After this, the array becomes $[2, 4, 6, 2, 5, 0, 0, 0, 0, 0]$, which has a length of $10$. It can be shown that no sequence of operations will make the final array longer.
In the second test case, we can choose $i=2$, then $i=3$, then $i=4$. The final array will be $[5, 4, 4, 5, 1, 0, 0, 0, 0, 0, 0]$, with a length of $11$.
Alice mixed up the words transmutation and permutation! She has an array $a$ specified via three integers $n$, $b$, $c$: the array $a$ has length $n$ and is given via $a_i = b\cdot (i - 1) + c$ for $1\le i\le n$. For example, if $n=3$, $b=2$, and $c=1$, then $a=[2 \cdot 0 + 1, 2 \cdot 1 + 1, 2 \cdot 2 + 1] = [1, 3, 5]$.
Now, Alice really enjoys permutations of $[0, \ldots, n-1]$$^{\text{∗}}$ and would like to transform $a$ into a permutation. In one operation, Alice replaces the maximum element of $a$ with the $\operatorname{MEX}$$^{\text{†}}$ of $a$. If there are multiple maximum elements in $a$, Alice chooses the leftmost one to replace.
Can you help Alice figure out how many operations she has to do for $a$ to become a permutation for the first time? If it is impossible, you should report it.
$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $0$ to $n-1$ in arbitrary order. Please note, this is slightly different from the usual definition of a permutation. For example, $[1,2,0,4,3]$ is a permutation, but $[0,1,1]$ is not a permutation ($1$ appears twice in the array), and $[0,2,3]$ is also not a permutation ($n=3$ but there is $3$ in the array).
$^{\text{†}}$The $\operatorname{MEX}$ of an array is the smallest non- negative integer that does not belong to the array. For example, the $\operatorname{MEX}$ of $[0, 3, 1, 3]$ is $2$ and the $\operatorname{MEX}$ of $[5]$ is $0$.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.
The only line of each test case contains three integers $n$, $b$, $c$ ($1\le n\le 10^{18}$; $0\le b$, $c\le 10^{18}$) — the parameters of the array.
For each test case, if the array can never become a permutation, output $-1$. Otherwise, output the minimum number of operations for the array to become a permutation.
In the first test case, the array is already $[0, 1, \ldots, 9]$, so no operations are required.
In the third t
Alice is at the Mad Hatter's tea party! There is a long sheet cake made up of $n$ sections with tastiness values $a_1, a_2, \ldots, a_n$. There are $m$ creatures at the tea party, excluding Alice.
Alice will cut the cake into $m + 1$ pieces. Formally, she will partition the cake into $m + 1$ subarrays, where each subarray consists of some number of adjacent sections. The tastiness of a piece is the sum of tastiness of its sections. Afterwards, she will divvy these $m + 1$ pieces up among the $m$ creatures and herself (her piece can be empty). However, each of the $m$ creatures will only be happy when the tastiness of its piece is $v$ or more.
Alice wants to make sure every creature is happy. Limited by this condition, she also wants to maximize the tastiness of her own piece. Can you help Alice find the maximum tastiness her piece can have? If there is no way to make sure every creature is happy, output $-1$.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
The first line of each test case contains three integers $n, m, v$ ($1\le m\le n\le 2\cdot 10^5$; $1\le v\le 10^9$) — the number of sections, the number of creatures, and the creatures' minimum requirement for tastiness, respectively.
The next line contains $n$ space separated integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the tastinesses of the sections.
The sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
For each test case, output the maximum tastiness Alice can achieve for her piece, or $-1$ if there is no way to make sure every creature is happy.
For the first test case, Alice can give the first and second section as their own pieces, and then take the remaining $10 + 1 + 1 + 10 = 22$ tastiness for herself. We can show that she cannot do any better.
For the second test case, Alice could give the first and second section as one piece, and the sixth section as one piece. She can then take the remaining $10 + 1 + 1
Note that the memory limit is unusual.
The Cheshire Cat has a riddle for Alice: given $n$ integers $a_1, a_2, \ldots, a_n$ and a target $m$, is there a way to insert $+$ and $\times$ into the circles of the expression $$a_1 \circ a_2 \circ \cdots \circ a_n = m$$ to make it true? We follow the usual order of operations: $\times$ is done before $+$.
Although Alice is excellent at chess, she is not good at math. Please help her so she can find a way out of Wonderland!
Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $n, m$ ($1\le n\le 2\cdot 10^5$; $1\le m\le 10^4$) — the number of integers and the target, respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0\le a_i\le 10^4$) — the elements of the array $a$.
The sum of $n$ over all test cases does not exceed $2\cdot 10^5$.
For each test case, output "YES" without quotes if it is possible to get the target by inserting $+$ or $\times$ and "NO" otherwise.
You can output each letter in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
Possible solutions for the first four test cases are shown below. $$\begin{align*} 2 \times 1 + 1 \times 1 \times 2 &= 4 \\\ 2 \times 1 + 1 + 1 \times 2 &= 5 \\\ 2 \times 1 + 1 + 1 \times 2 &= 6 \\\ 2 + 1 + 1 + 1 + 2 &= 7 \\\ \end{align*}$$ It is impossible to get a result of $8$ in the fifth test case.
You have a binary string$^{\text{∗}}$ $s$ of length $n$, and Iris gives you another binary string $r$ of length $n-1$.
Iris is going to play a game with you. During the game, you will perform $n-1$ operations on $s$. In the $i$-th operation ($1 \le i \le n-1$):
* First, you choose an index $k$ such that $1\le k\le |s| - 1$ and $s_{k} \neq s_{k+1}$. If it is impossible to choose such an index, you lose; * Then, you replace $s_ks_{k+1}$ with $r_i$. Note that this decreases the length of $s$ by $1$.
If all the $n-1$ operations are performed successfully, you win.
Determine whether it is possible for you to win this game.
$^{\text{∗}}$A binary string is a string where each character is either $\mathtt{0}$ or $\mathtt{1}$.
Each test contains multiple test cases. The first line of the input contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer $n$ ($2\le n\le 10^5$) — the length of $s$.
The second line contains the binary string $s$ of length $n$ ($s_i=\mathtt{0}$ or $\mathtt{1}$).
The third line contains the binary string $r$ of length $n-1$ ($r_i=\mathtt{0}$ or $\mathtt{1}$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
For each test case, print "YES" (without quotes) if you can win the game, and "NO" (without quotes) otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
In the first test case, you cannot perform the first operation. Thus, you lose the game.
In the second test case, you can choose $k=1$ in the only operation, and after that, $s$ becomes equal to $\mathtt{1}$. Thus, you win the game.