CF BUDDY
← Problems·

1250L · Divide The Students

1500 · binary search, greedy, math

Problem: A group of students has recently been admitted to the Faculty of Computer Sciences at the Berland State University. Now the programming teacher wants to divide them into three subgroups for practice sessions.

The teacher knows that a lot of programmers argue which language is the best. The teacher doesn't want to hear any arguments in the subgroups, so she wants to divide the students into three subgroups so that no pair of students belonging to the same subgroup want to argue.

To perform this division, the teacher asked each student which programming language he likes. There are aa students who answered that they enjoy Assembler, bb students stated that their favourite language is Basic, and cc remaining students claimed that C++ is the best programming language — and there was a large argument between Assembler fans and C++ fans.

Now, knowing that Assembler programmers and C++ programmers can start an argument every minute, the teacher wants to divide the students into three subgroups so that every student belongs to exactly one subgroup, and there is no subgroup that contains at least one Assembler fan and at least one C++ fan. Since teaching a lot of students can be difficult, the teacher wants the size of the largest subgroup to be minimum possible.

Please help the teacher to calculate the minimum possible size of the largest subgroup!

Input Format: The first line contains one integer tt (1t51 \le t \le 5) — the number of test cases in the input. Then test cases follow.

Each test case consists of one line containing three integers aa, bb and cc (1a,b,c10001 \le a, b, c \le 1000) — the number of Assembler fans, Basic fans and C++ fans, respectively.

Output Format: For each test case print one integer — the minimum size of the largest subgroup if the students are divided in such a way that there is no subgroup that contains at least one Assembler fan and at least one C++ fan simultaneously.

Note: Explanation of the answers for the example 11:

  1. The first subgroup contains 33 Assembler fans and 22 Basic fans, the second subgroup — 55 C++ fans, the third subgroup — 22 C++ fans and 33 Basic fans.
  2. The first subgroup contains 44 Assembler fans, the second subgroup — 66 Basic fans, the third subgroup — 22 Basic fans and 44 C++ fans.
  3. The first subgroup contains all Assembler fans, the second subgroup — all Basic fans, the third subgroup — all C++ fans.
  4. The first subgroup contains all Assembler fans, the second subgroup — all Basic fans, the third subgroup — all C++ fans.
  5. The first subgroup contains 1212 Assembler fans and 22 Basic fans, the second subgroup — 11 Assembler fan and 1313 Basic fans, the third subgroup — 77 Basic fans and 77 C++ fans.

Sample Cases

Case 1

Input

5
3 5 7
4 8 4
13 10 13
1000 1000 1000
13 22 7

Output

5
6
13
1000
14

Case 2

Input

5
1 3 4
1000 1000 1
4 1 2
325 226 999
939 861 505

Output

3
667
3
517
769

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback