Martian Volleyball
InterviewTime limit2sMemory limit512 MB
Given a volleyball score k x y, find the fewest remaining balls until one team wins by reaching k with a 2-point lead.
- Level
Medium4 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
A volleyball match on Mars is played by two teams until one team reaches k points and leads the other team by at least 2 points. For each ball played, exactly one of the teams scores 1 point.
The first team currently has x points and the second team has y points. What is the minimum number of balls that must still be played until one of the teams wins the match?
Input
The input contains several test cases. The first line contains the integer t, the number of test cases (1 ≤ t ≤ 5000).
Each test case is given on one line containing three integers separated by spaces: k, x, and y (1 ≤ k ≤ 100; 0 ≤ x, y ≤ 100).
The score is guaranteed to be reachable in a valid unfinished game.
Output
For each test case, print one line with the minimum number of balls that must be played until the match is finished.