text
stringlengths 0
801
|
---|
If strictly more than half of the total population $n$ are unhappy, Robin Hood will appear by popular demand.
|
Determine the minimum value of $x$ for Robin Hood to appear, or output $-1$ if it is impossible.
|
$^{\text{∗}}$The average wealth is defined as the total wealth divided by the total population $n$, that is, $\frac{\sum a_i}{n}$, the result is a real number.
|
The first line of input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
The first line of each test case contains an integer $n$ ($1 \le n \le 2\cdot10^5$) — the total population.
|
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$) — the wealth of each person.
|
It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
|
For each test case, output one integer — the minimum number of gold that the richest person must find for Robin Hood to appear. If it is impossible, output $-1$ instead.
|
In the first test case, it is impossible for a single person to be unhappy.
|
In the second test case, there is always $1$ happy person (the richest).
|
In the third test case, no additional gold are required, so the answer is $0$.
|
In the fourth test case, after adding $15$ gold, the average wealth becomes $\frac{25}{4}$, and half of this average is $\frac{25}{8}$, result
|
Impress thy brother, yet fret not thy mother.
|
Robin's brother and mother are visiting, and Robin gets to choose the start day for each visitor.
|
All days are numbered from $1$ to $n$. Visitors stay for $d$ continuous days, all of those $d$ days must be between day $1$ and $n$ inclusive.
|
Robin has a total of $k$ risky 'jobs' planned. The $i$-th job takes place between days $l_i$ and $r_i$ inclusive, for $1 \le i \le k$. If a job takes place on any of the $d$ days, the visit overlaps with this job (the length of overlap is unimportant).
|
Robin wants his brother's visit to overlap with the maximum number of distinct jobs, and his mother's the minimum.
|
Find suitable start days for the visits of Robin's brother and mother. If there are multiple suitable days, choose the earliest one.
|
The first line of the input contains a single integer $t$ ($1\leq t \leq 10^4$) — the number of test cases.
|
The first line of each test case consists of three integers $n$, $d$, $k$ ($1 \le n \le 10^5, 1 \le d, k \le n$) — the number of total days, duration of the visits, and the number of jobs.
|
Then follow $k$ lines of each test case, each with two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the start and end day of each job.
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
|
For each test case, output two integers, the best starting days of Robin's brother and mother respectively. Both visits must fit between day $1$ and $n$ inclusive.
|
In the first test case, the only job fills all $2$ days, both should visit on day $1$.
|
In the second test case, day $2$ overlaps with $2$ jobs and day $1$ overlaps with only $1$.
|
In the third test case, Robert visits for days $[1,2]$, Mrs. Hood visits for days $[4,5]$.
|
"Why, master," quoth Little John, taking the bags and weighing them in his hand, "here is the chink of gold."
|
The folk hero Robin Hood has been troubling Sheriff of Nottingham greatly. Sheriff knows that Robin Hood is about to attack his camps and he wants to be prepared.
|
Sheriff of Nottingham built the camps with strategy in mind and thus there are exactly $n$ camps numbered from $1$ to $n$ and $n-1$ trails, each connecting two camps. Any camp can be reached from any other camp. Each camp $i$ has initially $a_i$ gold.
|
As it is now, all camps would be destroyed by Robin. Sheriff can strengthen a camp by subtracting exactly $c$ gold from each of its neighboring camps and use it to build better defenses for that camp. Strengthening a camp doesn't change its gold, only its neighbors' gold. A camp can have negative gold.
|
After Robin Hood's attack, all camps that have been strengthened survive the attack, all others are destroyed.
|
What's the maximum gold Sheriff can keep in his surviving camps after Robin Hood's attack if he strengthens his camps optimally?
|
Camp $a$ is neighboring camp $b$ if and only if there exists a trail connecting $a$ and $b$. Only strengthened camps count towards the answer, as others are destroyed.
|
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
Each test case begins with two integers $n$, $c$ ($1 \le n \le 2\cdot10^5, 1 \le c \le 10^9$) — the number of camps and the gold taken from each neighboring camp for strengthening.
|
The second line of each test case contains $n$ integers $a_1,a_2,\dots,a_n$ ($-10^9 \le a_i \le 10^9$) — the initial gold of each camp.
|
Then follow $n-1$ lines, each with integers $u$, $v$ ($1 \le u, v \le n$, $u \ne v$) — meaning that there is a trail between $u$ and $v$.
|
The sum of $n$ over all test cases doesn't exceed $2\cdot10^5$.
|
It is guaranteed that any camp is reachable from any other camp.
|
Output a single integer, the maximum gold Sheriff of Nottingham can keep in his surviving camps after Robin Hood
|
[DJ Genki vs Gram - Einherjar Joker](https://soundcloud.com/leon- hwang-368077289/einherjar-joker-dj-genki-vs-gram)
|
⠀
|
You have some cards. An integer between $1$ and $n$ is written on each card: specifically, for each $i$ from $1$ to $n$, you have $a_i$ cards which have the number $i$ written on them.
|
There is also a shop which contains unlimited cards of each type. You have $k$ coins, so you can buy at most $k$ new cards in total, and the cards you buy can contain any integer between $\mathbf{1}$ and $\mathbf{n}$, inclusive.
|
After buying the new cards, you must partition all your cards into decks, according to the following rules:
|
* all the decks must have the same size; * there are no pairs of cards with the same value in the same deck.
|
Find the maximum possible size of a deck after buying cards and partitioning them optimally.
|
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 two integers $n$, $k$ ($1 \leq n \leq 2 \cdot 10^5$, $0 \leq k \leq 10^{16}$) — the number of distinct types of cards and the number of coins.
|
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^{10}$, $\sum a_i \geq 1$) — the number of cards of type $i$ you have at the beginning, for each $1 \leq i \leq n$.
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.