Professional Documents
Culture Documents
Problem C - Meta Hacker Cup - 2023 - Practice Round
Problem C - Meta Hacker Cup - 2023 - Practice Round
Problem C - Meta Hacker Cup - 2023 - Practice Round
Scoreboard 18 points
This contest has ended “An apple a day keeps the doctor away” is Steve’s motto. His other motto, “You can never have too
much of a good thing,” holds true for both apples and mottos. Steve would like to eat two apples
You did not participate in this contest.
per day for the next N days, but with strict adherence to his third motto “Consistency is key.”
Speci cally, he’d like the sum of the two apple weights he eats over the next N days to be the
PROBLEMS same for each day.
A1: Cheeseburger
8 pt Steve has already purchased 2 ∗ N − 1 apples, the ith of which weighs Ai ounces. He'd like to
Corollary 1
buy one more apple that's as light as possible to ful ll his goal. Steve can buy an apple of any
A2: Cheeseburger
positive integer weight in ounces from the store. Is it possible for him to reach his goal, and if so,
22 pt what weight apple should he buy?
Corollary 2
D: Road to Nutella 40 pt
The above image depicts the solution to the rst sample. Each day, Steve will eat two apples totalling
FAQ
7 oz. Steve must buy a 4 oz apple to make this happen.
My Clari cations Constraints
1 ≤ T ≤ 70
01:32:08
01:32:08 1 ≤ N ≤ 3 ∗ 105
© 2022 Meta Contact Us The sum of N over all cases is at most 600,000
1 ≤ Ai ≤ 109
Input Format
Input begins with an integer T , the number of test cases. Each test case starts with a single
integer N . The next line contains 2 ∗ N − 1 space-separated integers A1 , ..., A2∗N −1 .
Output Format
For the ith test case, print "Case #i: " followed a single integer, the smallest possible apple weight
in ounces that Steve can buy so that he can eat two apples for the next N days and have the sum
of apple weights be the same every day, or −1 if doing so is impossible.
Sample Explanation
In the rst case, if Steve buys a 4 oz apple, he can group his apples as shown above. For this input,
there's no way to succeed by buying any apple below 4 oz.
In the second case, Steve can buy a 7 oz apple, and eat two apples totaling 14 oz each day.
In the third case, any apple weight will su ce, so Steve will buy the lightest one possible.
In the fourth case, no matter what weight apple Steve attempts to buy, it is impossible for him to
achieve his goal.
Please note, as demonstrated in the seventh case, that it's possible for the answer to exceed 109 .
Copy Sample Input to Clipboard
7 Case #1: 4
3 Case #2: 7
6 3 1 2 5 Case #3: 1
2 Case #4: -1
7 7 7 Case #5: 6
1 Case #6: -1
1 Case #7: 1000000002
3
1 9 1 1 4
4
1 9 1 1 4 9 9
4
1 9 10 1 4 6 9
3
1000000000 2 10 4 999999994