text
stringlengths 0
801
|
---|
More formally, you need to choose a permutation$^{\ddagger}$ $p$ of length $n$, so that the array $b = [a_{p_1,1}, a_{p_1,2}, a_{p_2, 1}, a_{p_2, 2}, \ldots, a_{p_n,1}, a_{p_n,2}]$ contains as few inversions as possible. |
$^{\dagger}$The number of inversions in an array $c$ is the number of pairs of indices $i$ and $j$ such that $i < j$ and $c_i > c_j$. |
$^{\ddagger}$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]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). |
Each test consists of multiple 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 a single integer $n$ ($1 \le n \le 10^5$) — the number of arrays. |
Each of the following $n$ lines contains two integers $a_{i,1}$ and $a_{i,2}$ ($1 \le a_{i,j} \le 10^9$) — the elements of the $i$-th array. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. |
For each test case, output $2n$ integers — the elements of the array you obtained. If there are multiple solutions, output any of them. |
In the first test case, we concatenated the arrays in the order $2, 1$. Let's consider the inversions in the resulting array $b = [2, 3, 1, 4]$: |
* $i = 1$, $j = 3$, since $b_1 = 2 > 1 = b_3$; * $i = 2$, $j = 3$, since $b_2 = 3 > 1 = b_3$. |
Thus, the number of inversions is $2$. It can be proven that this is the minimum possible number of inversions. |
In the second |
In the heart of an ancient kingdom grows the legendary Tree of Life — the only one of its kind and the source of magical power for the entire world. The tree consists of $n$ nodes. Each node of this tree is a magical source, connected to other such sources through magical channels (edges). In total, there are $n-1$ channels in the tree, with the $i$-th channel connecting nodes $v_i$ and $u_i$. Moreover, there exists a unique simple path through the channels between any two nodes in the tree. |
However, the magical energy flowing through these channels must be balanced; otherwise, the power of the Tree of Life may disrupt the natural order and cause catastrophic consequences. The sages of the kingdom discovered that when two magical channels converge at a single node, a dangerous "magical resonance vibration" occurs between them. To protect the Tree of Life and maintain its balance, it is necessary to select several paths and perform special rituals along them. A path is a sequence of distinct nodes $v_1, v_2, \ldots, v_k$, where each pair of adjacent nodes $v_i$ and $v_{i+1}$ is connected by a channel. When the sages perform a ritual along such a path, the resonance vibration between the channels $(v_i, v_{i+1})$ and $(v_{i+1}, v_{i+2})$ is blocked for each $1 \leq i \leq k - 2$. |
The sages' task is to select the minimum number of paths and perform rituals along them to block all resonance vibrations. This means that for every pair of channels emanating from a single node, there must exist at least one selected path that contains both of these channels. |
Help the sages find the minimum number of such paths so that the magical balance of the Tree of Life is preserved, and its power continues to nourish the entire world! |
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 4 \cdot 10^4$) — the number of test cases. The description of the test cases follows. |
The first line of each test case contains a single integer $n$ ($2 \leq n \leq 5 \cdot 10^5$) — the nu |
Alice has $a$ coins. She can open a bank deposit called "Profitable", but the minimum amount required to open this deposit is $b$ coins. |
There is also a deposit called "Unprofitable", which can be opened with any amount of coins. Alice noticed that if she opens the "Unprofitable" deposit with $x$ coins, the minimum amount required to open the "Profitable" deposit decreases by $2x$ coins. However, these coins cannot later be deposited into the "Profitable" deposit. |
Help Alice determine the maximum number of coins she can deposit into the "Profitable" deposit if she first deposits some amount of coins (possibly $0$) into the "Unprofitable" deposit. If Alice can never open the "Profitable" deposit, output $0$. |
Each test consists of multiple 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. |
A single line of each test case contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the number of coins Alice has and the initial minimum amount required to open the "Profitable" deposit. |
For each test case, output a single integer — the maximum number of coins that Alice can deposit into the "Profitable" deposit. If Alice can never open the "Profitable" deposit, output $0$. |
In the first test case, $a \ge b$, so Alice can immediately open the "Profitable" deposit with all $10$ coins. |
In the second test case, Alice can open the "Unprofitable" deposit with $2$ coins. Then she will have $5$ coins left, but the minimum amount required to open the "Profitable" deposit will decrease by $4$ coins, making it equal to $5$ coins. Thus, Alice will be able to open the "Profitable" deposit with $5$ coins. |
In the third test case, Alice will not be able to open the "Profitable" deposit. |
You are given $n$ arrays $a_1$, $\ldots$, $a_n$. The length of each array is two. Thus, $a_i = [a_{i, 1}, a_{i, 2}]$. You need to concatenate the arrays into a single array of length $2n$ such that the number of inversions$^{\dagger}$ in the resulting array is minimized. Note that you do not need to count the actual number of inversions. |
More formally, you need to choose a permutation$^{\ddagger}$ $p$ of length $n$, so that the array $b = [a_{p_1,1}, a_{p_1,2}, a_{p_2, 1}, a_{p_2, 2}, \ldots, a_{p_n,1}, a_{p_n,2}]$ contains as few inversions as possible. |
$^{\dagger}$The number of inversions in an array $c$ is the number of pairs of indices $i$ and $j$ such that $i < j$ and $c_i > c_j$. |
$^{\ddagger}$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]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). |
Each test consists of multiple 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 a single integer $n$ ($1 \le n \le 10^5$) — the number of arrays. |
Each of the following $n$ lines contains two integers $a_{i,1}$ and $a_{i,2}$ ($1 \le a_{i,j} \le 10^9$) — the elements of the $i$-th array. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. |
For each test case, output $2n$ integers — the elements of the array you obtained. If there are multiple solutions, output any of them. |
In the first test case, we concatenated the arrays in the order $2, 1$. Let's consider the inversions in the resulting array $b = [2, 3, 1, 4]$: |
* $i = 1$, $j = 3$, since $b_1 = 2 > 1 = b_3$; * $i = 2$, $j = 3$, since $b_2 = 3 > 1 = b_3$. |
Thus, the number of inversions is $2$. It can be proven that this is the minimum possible number of inversions. |
In the second |
Recently, you received a rare ticket to the only casino in the world where you can actually earn something, and you want to take full advantage of this opportunity. |
The conditions in this casino are as follows: |
* There are a total of $n$ games in the casino. * You can play each game at most once. * Each game is characterized by two parameters: $p_i$ ($1 \le p_i \le 100$) and $w_i$ — the probability of winning the game in percentage and the winnings for a win. * If you lose in any game you decide to play, you will receive nothing at all (even for the games you won). |
You need to choose a set of games in advance that you will play in such a way as to maximize the expected value of your winnings. |
In this case, if you choose to play the games with indices $i_1 < i_2 < \ldots < i_k$, you will win in all of them with a probability of $\prod\limits_{j=1}^k \frac{p_{i_j}}{100}$, and in that case, your winnings will be equal to $\sum\limits_{j=1}^k w_{i_j}$. |
That is, the expected value of your winnings will be $\left(\prod\limits_{j=1}^k \frac{p_{i_j}}{100}\right) \cdot \left(\sum\limits_{j=1}^k w_{i_j}\right)$. |
To avoid going bankrupt, the casino owners have limited the expected value of winnings for each individual game. Thus, for all $i$ ($1 \le i \le n$), it holds that $w_i \cdot p_i \le 2 \cdot 10^5$. |
Your task is to find the maximum expected value of winnings that can be obtained by choosing some set of games in the casino. |
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of games offered to play. |
The $i$-th of the following $n$ lines contains two integers $p_i$ and $w_i$ ($1 \leq p_i \leq 100$, $1 \leq w_i, p_i \cdot w_i \leq 2 \cdot 10^5$) — the probability of winning and the size of the winnings in the $i$-th game. |
Output a single number — the maximum expected value of winnings in the casino that can be obtained by choosing some subset of games. |
Your answer will be accepted if the relative or absolute error does not exceed $10^{-6}$. Formally, if |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.