#P7095. [yLOI2020] 不离

    ID: 6132 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心2020二分二叉堆单调队列O2优化

[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 nn pieces of equipment. To equip the ii-th piece, before equipping it, the character's Strength must be at least aia_i, and Spirit must be at least bib_i. After equipping the ii-th piece, the character's Strength increases by cic_i, and Spirit increases by did_i.

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 TT, which denotes the subtask number of this test point.
The second line contains an integer nn, which denotes the number of pieces of equipment Bibi has.
Lines 33 to (n+2)(n+2) each contain four integers. On line (i+2)(i+2), the integers are ai,bi,ci,dia_i, b_i, c_i, d_i 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 11 and the Spirit is 22, you can equip the 22-nd piece of equipment. After equipping it, Strength increases by 33 and Spirit increases by 44, so the attributes become 44 Strength and 66 Spirit. Then you can equip the 11-st piece of equipment.

Constraints

This problem uses bundled testdata with multiple test points.

  • Subtask 11 (55 points): guaranteed n=0n=0.
  • Subtask 22 (55 points): guaranteed n=1n=1.
  • Subtask 33 (2020 points): guaranteed ai,bi100a_i, b_i \le 100, n6n \le 6.
  • Subtask 44 (1010 points): guaranteed ai,bi105a_i, b_i \le 10^5, n6n \le 6.
  • Subtask 55 (1010 points): guaranteed ai,bi10a_i, b_i \le 10.
  • Subtask 66 (1010 points): guaranteed ai,bi100a_i, b_i \le 100.
  • Subtask 77 (1010 points): guaranteed bi=0b_i=0, n6n \le 6.
  • Subtask 88 (1010 points): guaranteed bi=0b_i=0.
  • Subtask 99 (1010 points): guaranteed n6n \le 6.
  • Subtask 1010 (1010 points): no special constraints.

For all test points, it is guaranteed that 0n1050 \le n \le 10^5, 0ai,bi,ci,di1090 \le a_i, b_i, c_i, d_i \le 10^9.

Hint

There are 44 sample files. Please see forever.zip in the additional files.

For the third sample, bi=0b_i = 0.

Translated by ChatGPT 5