text
stringlengths 0
801
|
---|
In the first test case, the following sequence of operations is possible:
|
* perform the operation on $v=3$, then the values on the vertices will be $[0, 1, 1, 1]$; * perform the operation on $v=1$, then the values on the vertices will be $[1, 0, 0, 0]$.
|
I see satyam343. I'm shaking. Please more median problems this time. I love those. Please satyam343 we believe in you.
|
— satyam343's biggest fan
|
You are given an array $a$ of length $n$ and an integer $k$. You are also given a binary array $b$ of length $n$.
|
You can perform the following operation at most $k$ times:
|
* Select an index $i$ ($1 \leq i \leq n$) such that $b_i = 1$. Set $a_i = a_i + 1$ (i.e., increase $a_i$ by $1$).
|
Your score is defined to be $\max\limits_{i = 1}^{n} \left( a_i + \operatorname{median}(c_i) \right)$, where $c_i$ denotes the array of length $n-1$ that you get by deleting $a_i$ from $a$. In other words, your score is the maximum value of $a_i + \operatorname{median}(c_i)$ over all $i$ from $1$ to $n$.
|
Find the maximum score that you can achieve if you perform the operations optimally.
|
For an arbitrary array $p$, $\operatorname{median}(p)$ is defined as the $\left\lfloor \frac{|p|+1}{2} \right\rfloor$-th smallest element of $p$. For example, $\operatorname{median} \left( [3,2,1,3] \right) = 2$ and $\operatorname{median} \left( [6,2,4,5,1] \right) = 4$.
|
The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
|
Each test case begins with two integers $n$ and $k$ ($2 \leq n \leq 2 \cdot 10^5$, $0 \leq k \leq 10^9$) — the length of the $a$ and the number of operations you can perform.
|
The following line contains $n$ space separated integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — denoting the array $a$.
|
The following line contains $n$ space separated integers $b_1, b_2, \ldots, b_n$ ($b_i$ is $0$ or $1$) — denoting the array $b$.
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
|
For each test case, output the maximum value of score you can get on a new line.
|
For the first test case, it is optimal to perform $5$ operations on both elements so $a = [8,8]$. So, the maximum score we can achieve is $\max(8 + \operatorname{median}[8], 8 + \operatorname{median}[8]) = 16$, as $c_1 = [a_2] = [
|
MOOOOOOOOOOOOOOOOO
|
— Bessie the Cow, The Art of Racing on Islands
|
Two of Farmer John's cows, Bessie and Elsie, are planning to race on $n$ islands. There are $n - 1$ main bridges, connecting island $i$ to island $i + 1$ for all $1 \leq i \leq n - 1$. Additionally, there are $m$ alternative bridges. Elsie can use both main and alternative bridges, while Bessie can only use main bridges. All bridges are one way and can only be used to travel from an island with a lower index to an island with a higher index.
|
Initially, Elsie starts on island $1$, and Bessie starts on island $s$. The cows alternate turns, with Bessie making the first turn. Suppose the cow is on island $i$. During a cow's turn, if there are any bridges connecting island $i$ to island $j$, then the cow can move to island $j$. Then, island $i$ collapses, and all bridges connecting to island $i$ also collapse. Also, note the following:
|
* If there are no bridges connecting island $i$ to another island, then island $i$ collapses, and this cow is eliminated from the race. * If the other cow is also on island $i$, then after this cow moves to another island, the island collapses, and the other cow is eliminated from the race. * After an island or bridge collapses, no cows may use them. * If a cow is eliminated, their turn is skipped for the rest of the race.
|
The race ends once either cow reaches island $n$. It can be shown that regardless of the cows' strategies, at least one cow reaches island $n$. Bessie wins if and only if she reaches island $n$ first.
|
For each $1 \leq s \leq n - 1$, determine whether Bessie wins if she starts the race on island $s$. Assume both cows follow optimal strategies to ensure their own respective victories.
|
The first line contains $t$ ($1 \leq t \leq 10^4$) – the number of test cases.
|
The first line of each test case contains $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^5$, $0 \leq m \leq 2 \cdot 10^5$) – the number of islands and the number of alternative bridges.
|
The next $m$ lines of each test case conta
|
Drink water.
|
— Sun Tzu, The Art of Becoming a Healthy Programmer
|
This is the easy version of the problem. The only difference is that $x=n$ in this version. You must solve both versions to be able to hack.
|
You are given two integers $n$ and $x$ ($x=n$). There are $n$ balls lined up in a row, numbered from $1$ to $n$ from left to right. Initially, there is a value $a_i$ written on the $i$-th ball.
|
For each integer $i$ from $1$ to $n$, we define a function $f(i)$ as follows:
|
* Suppose you have a set $S = \\{1, 2, \ldots, i\\}$.
|
* In each operation, you have to select an integer $l$ ($1 \leq l < i$) from $S$ such that $l$ is not the largest element of $S$. Suppose $r$ is the smallest element in $S$ which is greater than $l$.
|
* If $a_l > a_r$, you set $a_l = a_l + a_r$ and remove $r$ from $S$. * If $a_l < a_r$, you set $a_r = a_l + a_r$ and remove $l$ from $S$. * If $a_l = a_r$, you choose either the integer $l$ or $r$ to remove from $S$: * If you choose to remove $l$ from $S$, you set $a_r = a_l + a_r$ and remove $l$ from $S$. * If you choose to remove $r$ from $S$, you set $a_l = a_l + a_r$ and remove $r$ from $S$.
|
* $f(i)$ denotes the number of integers $j$ ($1 \le j \le i$) such that it is possible to obtain $S = \\{j\\}$ after performing the above operations exactly $i - 1$ times.
|
For each integer $i$ from $x$ to $n$, you need to find $f(i)$.
|
The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
|
The first line of each test case contains two integers $n$ and $x$ ($1 \leq n \leq 2 \cdot 10^5; x = n$) — the number of balls and the smallest index $i$ for which you need to find $f(i)$.
|
The second line of each test case contains $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the initial number written on each ball.
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
|
For each test case, output $n-x+1$ space separated integers on a new line, where the $j$-th integer should represent $f(x+j-1)$.
|
In
|
As a computer science student, Alex faces a hard challenge — showering. He tries to shower daily, but despite his best efforts there are always challenges. He takes $s$ minutes to shower and a day only has $m$ minutes!
|
He already has $n$ tasks planned for the day. Task $i$ is represented as an interval $(l_i$, $r_i)$, which means that Alex is busy and can not take a shower in that time interval (at any point in time strictly between $l_i$ and $r_i$). No two tasks overlap.
|
Given all $n$ time intervals, will Alex be able to shower that day? In other words, will Alex have a free time interval of length at least $s$?
|

|
In the first test case, Alex can shower for the first $3$ minutes of the day and not miss any of the tasks.
|
The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
|
The first line of each test case contains three integers $n$, $s$, and $m$ ($1 \leq n \leq 2 \cdot 10^5$; $1 \leq s, m \leq 10^9$) — the number of time intervals Alex already has planned, the amount of time Alex takes to take a shower, and the amount of minutes a day has.
|
Then $n$ lines follow, the $i$-th of which contains two integers $l_i$ and $r_i$ ($0 \leq l_i < r_i \leq m$) — the time interval of the $i$-th task. No two tasks overlap.
|
Additional constraint on the input: $l_i > r_{i-1}$ for every $i > 1$.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.