luogu#P7821. 「RdOI R3」race

「RdOI R3」race

Problem Description

In a football tournament, Team A and Team B played a total of nn matches. The tournament uses a point system: the winning team gets aa points, the losing team gets bb points, and if the match is a draw then both teams get cc points each. It is known that Team A scored a total of dd goals, and Team B scored a total of ee goals. Find the maximum possible total score and the minimum possible total score for Team A.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case, input one line with six integers n,a,b,c,d,en,a,b,c,d,e.

Output Format

For each test case, output one line with two integers separated by a space, representing the maximum possible total score and the minimum possible total score.

5
5 3 0 2 5 2
5 5 2 3 0 5
3 100 1 2 6 6
5 9 0 2 3 9
4 5 0 5 1 3
13 7
14 10
201 6
29 0
15 5

Hint

Sample Explanation

To make the samples easier to understand, the sample explanations for the first three test cases are given below:

Test Case Maximum Score Plan Minimum Score Plan
11 (1,0),(0,0),(2,1),(0,0),(2,1)(1,0),(0,0),(2,1),(0,0),(2,1) (0,0),(5,0),(0,1),(0,0),(0,1)(0,0),(5,0),(0,1),(0,0),(0,1)
22 (0,0),(0,5),(0,0),(0,0),(0,0)(0,0),(0,5),(0,0),(0,0),(0,0) (0,1),(0,1),(0,1),(0,1),(0,1)(0,1),(0,1),(0,1),(0,1),(0,1)
33 (3,2),(0,2),(3,2)(3,2),(0,2),(3,2) (6,6),(0,0),(0,0)(6,6),(0,0),(0,0)

In the table, (x1,y1),(x2,y2),,(xn,yn)(x_1,y_1),(x_2,y_2),\cdots,(x_n,y_n) means the score of match 11 is x1:y1x_1:y_1, the score of match 22 is x2:y2x_2:y_2, and so on.


Constraints

This problem uses bundled testdata.

For all test cases, 1T1051\le T\le 10^5, 1n1091\le n \le 10^9, 0d,e1090\le d,e\le10^9, 0bca1090\le b\le c \le a\le10^9.

subtask Score Special Constraint Dependencies
11 1010 e=0e=0 None
22 2020 n,d,e5,T100n,d,e\le 5,T\le100
33 n5n\le 5 22
44 5050 None 1,31,3

Translated by ChatGPT 5