DBMB had a birthday yesterday. He was gifted an array $$$a$$$ of $$$n$$$ elements and a number $$$x$$$. But there is one problem: he only likes arrays where the sum of the elements equals $$$s$$$. To make the array appealing to him, you can perform the following operation any number of times:
Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The following describes the test cases.
The first line of each test case contains three integers $$$n$$$, $$$s$$$, $$$x$$$ ($$$1 \le n, x \le 10$$$, $$$1 \le s \le 100$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots a_n$$$ ($$$1 \le a_i \le 10$$$) — the elements of the array gifted to DBMB.
For each test case, output "YES" if the array can appeal to DBMB. Otherwise, output "NO".
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
63 3 51 1 13 8 21 2 34 7 21 1 1 13 15 12 4 102 100 54 65 12 11 2 2 3 2
YESYESNONOYESYES
In the second test case, $$$a = [1, 2, 3]$$$, applying the operation on $$$a_2$$$ gives us $$$a = [1, 4, 3]$$$. The sum of the array equals $$$s$$$.
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ and $$$[1,3,4]$$$ are not permutations.
You are given a permutation $$$p$$$ of length $$$n$$$. You can perform the following operation exactly once:
Each test consists of several test cases. The first line 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 the number $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$).
The second line of each test case contains $$$n$$$ distinct integers $$$p_1, p_2,...,p_n$$$ $$$(1\le p_i\le n)$$$.
It is guaranteed that the sum of the values of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output the lexicographically maximum permutation that can be obtained with one operation.
443 2 1 433 1 244 3 2 122 1
4 1 2 33 2 14 3 2 12 1
For the first test case, the best segment is $$$[1, 4]$$$. After reversing, $$$a = [4, 1, 2, 3]$$$. For the second test case, the best segment is $$$[2, 3]$$$. After reversing, $$$a = [3, 2, 1]$$$.
Today, KQ has an exam at the Grail Academy. A strict teacher gave a task that KQ could not solve. He was given two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$. KQ is allowed to perform the following operations on the arrays:
Each test consists of several test cases. The first line contains one 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$$$, $$$q$$$ $$$(1\le n, q\le 2 \cdot 10^5)$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2,...,a_n$$$ $$$(1\le a_i\le 10^4)$$$.
The third line of each test case contains $$$n$$$ integers $$$b_1, b_2,...,b_n$$$ $$$(1\le b_i\le 10^4)$$$.
The following $$$q$$$ lines contain two integers $$$l$$$ and $$$r$$$ $$$(1\le l\le r\le n)$$$.
It is guaranteed that the sum of the values of $$$n$$$ and the sum of the values of $$$q$$$ across all test cases do not exceed $$$2 \cdot 10^5$$$.
For each test case, output $$$q$$$ numbers separated by spaces — the maximum values of the sums $$$(a_l + a_{l+1} + a_{l+2} + \dots + a_r)$$$.
43 13 2 11 2 31 31 1121 13 26 7 59 6 81 22 34 34 3 2 15 1 3 11 22 43 4
9217 168 7 4
Consider the first test case. Replace $$$a_3$$$ with $$$b_3$$$, $$$a = [3, 2, 3]$$$. Replace $$$a_2$$$ with $$$a_3$$$, $$$a = [3, 3, 3]$$$. The sum $$$a_1 + a_2 + a_3 = 9$$$.
You have been gifted a new game called "Elatyh". In the game, you are given $$$n$$$ swords, each with its own strength. In particular, the sword numbered $$$i$$$ has a strength of $$$a_i$$$. The game consists of $$$n$$$ levels, each of which features a monster.
You start at level $$$1$$$ and progress further. To pass level $$$i$$$ and move on to level $$$i + 1$$$, you need to defeat the monster at level $$$i$$$. To defeat the monster at level $$$i$$$, you need to deal it $$$b_i$$$ sword strikes. The swords in the game are very fragile, so they can only deal one strike before breaking. If you complete level $$$n$$$ or run out of swords, you can finish the game and proceed to score calculation.
Before the game, you are allowed to choose the difficulty level. If you choose difficulty $$$x$$$, swords with a strength less than $$$x$$$ will not affect the monsters. The game score in this case is equal to $$$x$$$ multiplied by the number of levels completed. Your task is to choose the game difficulty in such a way as to maximize the game score.
Each test consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The following describes the test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 2 \cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1\le a_i\le 10^9)$$$.
The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ $$$(1\le b_i\le n)$$$.
It is guaranteed that the sum of the values of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the maximum game score.
531 3 42 1 122 31 141 2 3 42 2 1 164 4 1 4 5 42 2 4 1 2 2101000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000001 1 1 1 1 1 1 1 1 1
3 4 3 8 10000000000
Consider the first test case. Optimal difficulty to choose is $$$3$$$. If difficulty is $$$3$$$, you can deal strikes with swords number $$$2$$$ and $$$3$$$. With $$$2$$$ swords you can complete $$$1$$$ level, so the game score is $$$3\cdot 1 = 3$$$.
Today, Sabyrzhan was called to the board with an array $$$a$$$ of length $$$n$$$ and was assigned an officer's task — to answer $$$n$$$ questions.
In the $$$i$$$-th question, it is required to determine the minimum number of elements from the array that need to be selected from the board (it is allowed to use the same element multiple times) so that their product is exactly equal to $$$i$$$, or to report that it is impossible to achieve such a product.
Note that at least one element must be selected.
Each test consists of several test cases. The first line contains one 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 one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10 ^ 5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$).
It is guaranteed that the sum of the values of $$$n$$$ across all test cases does not exceed $$$3 \cdot 10 ^ 5$$$.
For the $$$i$$$-th question, output one integer — the minimum number of elements from the array required to obtain a product equal to $$$i$$$, or $$$−1$$$ if it is impossible to achieve such a product.
683 2 2 3 7 3 6 751 2 3 4 531 1 1102 1 2 1 3 5 5 7 7 741 1 2 211
-1 1 1 2 -1 1 1 31 1 1 1 11 -1 -11 1 1 2 1 2 1 3 2 21 1 -1 21
Consider the first test case. The products can be obtained as follows:
Courier YF has earned the title of the best pizza delivery person GR. The manager does not like him, so he decided to give him a very difficult task. The manager provided him with $$$n$$$ coordinates of houses $$$(x_i, y_i)$$$ where he needs to deliver the pizza. He will deliver the pizza in the following way:
Each move takes him exactly one second, and handing over the pizza to the customer takes $$$0$$$ seconds. The manager wants the delivery to be as fast as possible. You need to find the minimum delivery time for all GR pizzas. It is guaranteed that delivery is always possible.
Each test consists of several test cases. The first line contains one 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 five integers $$$n$$$, $$$Ax$$$, $$$Ay$$$, $$$Bx$$$, $$$By$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le Ax, Ay, Bx, By \le 10^9$$$) — the number of houses for delivery, as well as the coordinates of the start and end points.
The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$Ax \lt x_i \lt Bx$$$).
The third line of each test case contains $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$).
It is guaranteed that the sum of the values of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer on a separate line — the minimum time required for pizza delivery.
41 2 3 5 2443 1 3 5 23 4 35 4 16 1 2 7 35 2 3 5 5 36 4 3 1 4 15 6 9 8 67 7 7 7 73 1 8 8 3
6131915
Consider the second test case:
This is an interactive problem.
In this interactive problem, you are given an acyclic, connected, undirected graph consisting of $$$n$$$ vertices. We define a path between two vertices $$$v$$$ and $$$u$$$ as a sequence of distinct vertices $$$p_1, p_2,\dots p_k$$$ such that $$$p_1 = v$$$, $$$p_k = u$$$, and for all $$$i$$$ ($$$1 \le i \lt k$$$), there exists an edge between vertices $$$p_i$$$ and $$$p_{i+1}$$$.
There are hidden vertices $$$x$$$ and $$$y$$$ (they may coincide). You can make the following queries:
Note that the interactor is adaptive, which means that the hidden vertices may change depending on your queries, but will not contradict previous queries.
Each test consists of several test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The following lines describe the test cases.
The first line of each test case contains one integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of vertices in the graph.
Next, there are $$$n - 1$$$ lines, each containing two integers $$$v$$$, $$$u$$$ ($$$1\le v, u\le n$$$), indicating that vertices $$$v$$$ and $$$u$$$ are connected by an edge in the graph.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
To find any vertex on the path, you can use no more than $$$\lfloor\frac{n}{2}\rfloor + 1$$$ queries. For this, use queries of the form "? $$$a$$$ $$$b$$$".
After each query, read one number, either $$$0$$$ or $$$1$$$ — the response to the query.
When you find one of the required vertices, output one line in the following format: "! $$$v$$$" ($$$1\le v\le n$$$), where $$$v$$$ is the vertex you found.
If your program makes more than $$$\lfloor\frac{n}{2}\rfloor + 1$$$ queries for one test case, the response to the query will be $$$-1$$$, and after receiving such a response, your program should terminate immediately to receive a verdict of Incorrect answer. Otherwise, it may receive any other verdict.
After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive a verdict of Solution "timed out". To flush the buffer, use:
3 2 1 2 1 3 1 2 1 3 0 0 4 1 2 2 3 2 4 0 1
? 1 1 ! 1 ? 1 1 ? 2 2 ! 3 ? 1 3 ? 4 4 ! 4
The Great Grail Tree has stood in the kingdom for $$$315$$$ years. It takes up a lot of space, so King Ila decided to get rid of it as soon as possible. The tree itself is an acyclic, connected, undirected graph with $$$n$$$ vertices, each having its own value $$$a_v$$$. The tree can be removed in the following way:
Each test consists of several test case. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line contains the number $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$) — the number of vertices in the Grail Tree.
The second line describes the array $$$a$$$ ($$$1\le a_i\le 10^9$$$) — the values of the vertices in the tree.
Next, there are $$$n - 1$$$ lines, each containing 2 numbers $$$v$$$ and $$$u$$$ ($$$1\le v, u\le n, v\neq u$$$), indicating that vertices $$$v$$$ and $$$u$$$ are connected by an edge in the tree.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output "YES" if it is possible to completely remove the Grail Tree. Otherwise, output "NO". If the answer is "YES", output any sequence of removals.
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
531 2 41 22 343 4 2 11 22 33 469 6 5 1 7 41 22 32 43 54 652 1 1 1 22 13 22 45 451 5 3 7 91 22 33 44 5
NOYES2 3 1 4NOYES1 5 2 3 4YES2 4 1 5 3