#P7095. [yLOI2020] 不离
[yLOI2020] 不离
Description
This problem comes from zxy's chatting. Gugu asked Bibi to choose a song as the title, but Bibi said he had not decided yet, so Gugu picked this song for him.
Bibi is playing a game called Diablo. One day, Bibi suddenly got an idea, made a very difficult problem using the game as the background, and told it to Gugu. Gugu could not solve it, so he simplified the problem a bit. Therefore, after simplification, this problem has almost nothing to do with Diablo.
In the game, the character has two attributes, which we call "Strength" and "Spirit". Bibi has pieces of equipment. To equip the -th piece, before equipping it, the character's Strength must be at least , and Spirit must be at least . After equipping the -th piece, the character's Strength increases by , and Spirit increases by .
Bibi can choose the order of equipping freely. As long as Strength and Spirit are not less than the required values, he can equip that piece.
Now, Gugu wants to know: if Bibi wants to equip all pieces of equipment, what is the minimum initial Strength (i.e., the Strength before equipping anything)? Under the condition that the initial Strength is minimal, what is the minimum initial Spirit (i.e., the Spirit before equipping anything)?
Clearly, both the initial Strength and the initial Spirit should be non-negative integers.
Input Format
The first line contains an integer , which denotes the subtask number of this test point.
The second line contains an integer , which denotes the number of pieces of equipment Bibi has.
Lines to each contain four integers. On line , the integers are in order.
Output Format
Output one line with two integers separated by a space, representing the minimum initial Strength, and the minimum initial Spirit under the condition that the initial Strength is minimal.
0
2
1 5 0 2
1 2 3 4
1 2
Hint
Explanation for Sample 1
When the initial Strength is and the Spirit is , you can equip the -nd piece of equipment. After equipping it, Strength increases by and Spirit increases by , so the attributes become Strength and Spirit. Then you can equip the -st piece of equipment.
Constraints
This problem uses bundled testdata with multiple test points.
- Subtask ( points): guaranteed .
- Subtask ( points): guaranteed .
- Subtask ( points): guaranteed , .
- Subtask ( points): guaranteed , .
- Subtask ( points): guaranteed .
- Subtask ( points): guaranteed .
- Subtask ( points): guaranteed , .
- Subtask ( points): guaranteed .
- Subtask ( points): guaranteed .
- Subtask ( points): no special constraints.
For all test points, it is guaranteed that , .
Hint
There are sample files. Please see forever.zip in the additional files.
For the third sample, .
Translated by ChatGPT 5
京公网安备 11011102002149号