Skip to main content
Back to problems
Codeforces
Easy
Arrays
Greedy
Sorting
Barrels

Choose one barrel to maximize the total amount of liquid obtained after an initial fill and additional fill-up steps.

Acceptance 0%
Problem Statement

You are given a set of barrels, each with some initial amount of liquid. In one operation, you may choose a barrel and increase its amount according to the problem's rules so that the final result is maximized by focusing resources on the most beneficial barrel.

Your task is to determine the maximum possible amount you can obtain after applying the allowed process exactly as described by the problem.

Input Format

  • The first line contains an integer tt — the number of test cases.
  • Each test case consists of:
    • one line with an integer nn;
    • one line with nn integers describing the barrels.

Output Format

For each test case, print a single integer — the maximum achievable value according to the allowed operation.

Constraints

  • 1t1041 \le t \le 10^4
  • 1n1051 \le n \le 10^5 across all test cases
  • Values fit in 64-bit signed integers
Examples
Sample cases returned by the problem API.

Example 1

Input

2
3
1 2 3
4
10 1 1 1

Output

6
13

Explanation

In each case, the best choice is the barrel that gives the largest resulting value under the stated rule. The sample illustrates that the solution is driven by a greedy comparison of candidates.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.