Round-Robin League
Time limit2sMemory limit1024 MB
Given points for a win, draw, and loss, find the maximum and minimum points the kth-ranked team can finish with in an n-team round-robin.
- Level
Medium7 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
In a round-robin league, teams 1 through play each other exactly once. Each match ends in a win, a loss, or a draw. A win earns points, a draw earns points, and a loss earns points. Unlike the usual scoring in round-robin leagues, the relative order of , , and is not fixed in this problem. For example, a win may earn fewer points than a loss.
Teams are ranked by points, highest first. If two teams have the same points, the team with the smaller number ranks higher. After all matches end, find the maximum and minimum points that the team ranked th can have.
Input
The first line contains the number of test cases . Each of the next lines contains , , , , and , separated by spaces.
Output
For each test case, print on one line the maximum and minimum points that the team ranked th can have, in that order.
Constraints
Hint
