We define the beauty of a list of $$$n$$$ numbers $$$a_1, a_2, \ldots, a_n$$$ as the sum of the terms with odd indices minus the sum of the terms with even indices, that is, $$$a_1 - a_2 + a_3 - \ldots + (-1)^{n+1}a_n = \sum_{i=1}^n (-1)^{i+1}a_i$$$.
You are given a list of $$$n$$$ numbers and an integer $$$k$$$, and you must determine the maximum beauty you can obtain after performing the following operation exactly $$$k$$$ times: you choose two different indices $$$1 \leq i \lt j \leq n$$$ and exchange the values of $$$a_i$$$ and $$$a_j$$$.
The input begins with a number $$$T$$$ — the number of test cases.
Each test case starts with a line with two integers $$$n$$$ and $$$k$$$: the length of the list and the number of exchanges to be performed.
Next, there is a line with $$$n$$$ integers $$$a_1, \ldots, a_n$$$.
For each test case, you must print a line with the maximum beauty that can be obtained by performing exactly $$$k$$$ exchanges.
45 11 4 2 3 72 11 22 21 29 01000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000
9 1 -1 5000000000
$$$1 \leq T \leq 2000$$$.
$$$2 \leq n \leq 2 \cdot 10^5$$$.
The sum of $$$n$$$ for all cases is at most $$$2 \cdot 10^5$$$.
$$$0 \leq k \leq 10^9$$$.
$$$0 \leq a_i \leq 10^9$$$ for all $$$i = 1, \ldots, n$$$.
Herminia wants to divide her lands among her four children. Herminia's estate consists of $$$n$$$ possessions, the $$$i$$$-th of which is located at the point $$$(x_i, y_i)$$$ in the plane (where $$$x_i$$$, $$$y_i$$$ are integer coordinates) and has a value $$$v_i$$$.
Herminia will divide her lands as follows: she will choose a point $$$(a, b)$$$ and give each child the possessions contained in one of the four quadrants defined by the point. That is:
Herminia wants each child to receive the same total value in possessions. Help Herminia find the number of points $$$(a, b)$$$ with integer coordinates such that the sum of the values of the possessions in each of the quadrants is equal.
The input begins with a number $$$T$$$ — the number of test cases.
Each test case starts with a line with an integer $$$n$$$, the number of possessions. Next, there are $$$n$$$ lines, the $$$i$$$-th of which has three integers $$$x_i$$$, $$$y_i$$$, and $$$v_i$$$: the coordinates and the value of the $$$i$$$-th possession.
For each test case, your program should print a line with the number of points with integer coordinates $$$(a, b)$$$ such that the values of the possessions in each of the four quadrants defined by those points add up to the same total.
35-1 -2 13 4 22 -5 2-2 -1 1-4 3 210 0 14-1000000000 -1000000000 11000000000 -1000000000 1-1000000000 1000000000 11000000000 1000000000 1
12 0 4000000000000000000
$$$1 \leq T \leq 1000$$$.
$$$1 \leq n \leq 2 \cdot 10^5$$$.
The sum of $$$n$$$ for all cases will be at most $$$2 \cdot 10^5$$$.
$$$-10^9 \leq x_i, y_i \leq 10^9$$$.
There are no repeated pairs $$$(x_i, y_i)$$$.
$$$1 \leq v_i \leq 10^9$$$.
Given two lists $$$X = (x_1, \ldots, x_n)$$$ and $$$Y = (y_1, \ldots, y_n)$$$ of $$$n$$$ integers, we say that $$$X$$$ is dominated by $$$Y$$$ if $$$x_i \leq y_i$$$ for all $$$i = 1, 2, \ldots, n$$$. We say that $$$X$$$ is dominated by a reordering of $$$Y$$$ if $$$Y$$$ can be rearranged in such a way that $$$X$$$ is dominated by $$$Y$$$: formally, if there exists a permutation $$$\sigma$$$ such that $$$x_i \leq y_{\sigma(i)}$$$ for all $$$i = 1, 2, \ldots, n$$$.
Three lists $$$A$$$, $$$B$$$, $$$C$$$ of $$$n$$$ integers are given. The following operation can be performed: exchange the element $$$a_i$$$ with the element $$$b_i$$$, for $$$1 \leq i \leq n$$$.
Find the minimum number of operations necessary so that, after performing the operations, $$$A$$$ is dominated by a reordering of $$$C$$$. If this is not possible, print $$$-1$$$.
The first line contains an integer $$$T$$$, the number of cases to process.
Each case begins with a line containing $$$n$$$, the size of the lists $$$A$$$, $$$B$$$, and $$$C$$$.
The next line of each case contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$.
The next line of each case contains $$$n$$$ integers $$$b_1, \ldots, b_n$$$.
The next line of each case contains $$$n$$$ integers $$$c_1, \ldots, c_n$$$.
For each case, print an integer, the minimum number of operations or $$$-1$$$ if it is not possible to make $$$A$$$ dominated by a reordering of $$$C$$$.
331 2 33 3 31 2 231 3 21 1 12 1 122 34 34 2
-1 1 0
$$$1 \le T \le 10^5$$$.
$$$1 \le n \le 10^5$$$.
The sum of $$$n$$$ over all cases will be less than or equal to $$$10^5$$$.
$$$1 \le a_i, b_i, c_i \le 10^9$$$.
Huize and Jacobo are playing a conquest video game. In the game, there are $$$N$$$ cities and $$$M$$$ bidirectional roads between pairs of cities. Initially, Huize occupies $$$H$$$ cities, and Jacobo occupies $$$J$$$ cities with some soldiers. They have already placed the soldiers, and now it's time to see who wins. The soldiers can be divided into any number of groups and march through all the roads incident to the cities they occupy. Each city is conquered by the first group of soldiers that reaches the city. If multiple groups arrive at the same time, Jacobo's soldiers will conquer the city. Once a city is conquered, the opponent cannot enter it.
The roads can have different lengths, so each road is specifically associated with the travel time between cities. Additionally, some roads are blocked and require a code to open, which can be obtained in exactly one city (not necessarily one of the cities at the ends of the road). The player who conquers that city can use the road from the moment they conquer the city, and the other player cannot use it.
The objective of this game is to occupy more cities than the opponent. Jacobo, who wants to spend more time with his daughter, is only willing to play if he knows he will win. Help Jacobo: if Jacobo is going to win, print two lines, the first with the text "La hora de juego" (without quotes), and the second with the difference between the number of cities Jacobo will occupy and the number of cities Huize will occupy. If Jacobo is going to tie or lose, print in a single line "Hasta luego Huize, es la hora de Olivia" (without quotes).
The input begins with an integer $$$T$$$, the number of test cases.
Each case begins with two integers on a line: $$$N$$$, $$$M$$$.
The following $$$M$$$ lines contain four integers each: $$$u_i$$$, $$$v_i$$$, $$$w_i$$$, $$$c_i$$$, indicating that there is a road connecting cities $$$u_i$$$ and $$$v_i$$$, it takes $$$w_i$$$ minutes to travel, and the secret code is located in city $$$c_i$$$ (if $$$c_i = 0$$$, no code is needed to travel).
The next line contains an integer $$$H$$$.
In the following line, there are $$$H$$$ integers $$$h_i$$$, representing the cities initially occupied by Huize.
The next line contains an integer $$$J$$$.
In the following line, there are $$$J$$$ integers $$$j_i$$$, representing the cities initially occupied by Jacobo.
For each test case, if Jacobo is going to win, write "La hora de juego" and, on a new line, how many more cities than Huize he will occupy. Otherwise, write "Hasta luego Huize, es la hora de Olivia" on a single line.
37 81 2 2 01 4 1 02 4 1 12 3 1 13 7 3 73 5 1 67 6 3 06 5 100 627 4117 81 2 2 01 4 1 02 4 1 12 3 1 13 7 3 73 5 1 37 6 3 06 5 100 627 4115 43 1 116 31 4 14 44 2 100 22 5 2 01315
Hasta luego Huize, es la hora de Olivia La hora de juego 1 La hora de juego 3
$$$1 \leq H, J, h_i, j_i, c_i \leq N \leq 2 \times 10^5$$$, $$$H+J \leq N$$$.
$$$0 \leq M \leq \min\left(\frac{N \cdot (N-1)}{2}, 2 \times 10^5\right)$$$.
$$$1 \leq w_i \leq 10^9$$$.
$$$1 \leq T \leq 10000$$$; The sum of $$$N$$$ in all cases is less than $$$2 \times 10^5$$$; The sum of $$$M$$$ in all cases is less than $$$2 \times 10^5$$$.
Given that IOI 2023 was in Hungary and IOI 2024 will be in Egypt, what better than a problem about a conjecture of Hungarian mathematicians about Egyptian fractions!
The Erdős-Straus conjecture states that for every integer $$$n \geq 2$$$, there exist positive integers $$$x$$$, $$$y$$$, $$$z$$$ such that
$$$$$$\frac{4}{n} = \frac{1}{x} + \frac{1}{y} + \frac{1}{z}.$$$$$$
Since this problem is very difficult, you are asked to solve a variant in which $$$z=xy$$$. That is, given $$$n \geq 1$$$, you must find a pair of positive integers $$$x$$$, $$$y$$$ such that
$$$$$$\frac{4}{n} = \frac{1}{x} + \frac{1}{y} + \frac{1}{xy}$$$$$$
if they exist.
The input begins with an integer $$$T$$$, the number of test cases. Then follow $$$T$$$ lines, each with an integer $$$n$$$.
For each test case, you should print a line with the two positive integers $$$x$$$, $$$y$$$ separated by spaces, or with a single $$$0$$$ in case those numbers do not exist. If there are multiple valid pairs of integers $$$x$$$, $$$y$$$, you can print any of them.
4 2 1 5 6
2 1 0 2 5 3 4
$$$1 \leq T \leq 100$$$. $$$1 \leq n \leq 10^9$$$.