#P9818. King's Ruins
King's Ruins
King's Ruins
Problem Description
The first king of Byteland was buried with his knights a thousand years ago. In the ruins, the archaeologists have found stone tablets in a row, labeled by from left to right. Each stone tablet belongs to a knight. On the surface of the -th stone tablet, five numbers are describing the ability of the -th knight in five aspects:
- The wind ability , denoting how fast the knight is.
- The guard ability , denoting how many attacks can be defended by the knight.
- The ice ability , denoting the power of ice crystal cast by the knight.
- The flame ability , denoting the power of fire cast by the knight.
- The light ability , denoting the power of thunder cast by the knight. Little Q is visiting the stone tablets from left to right, according to the labels from to . After visiting a stone tablet, before moving right to the next one, he can choose to take a photo with it or do nothing. Little Q estimates the value of each stone tablet, he wants to maximize the total value that he takes photos with, and the knight corresponding to the next photo is always not weaker than the current one. Here the -th knight is considered not to be weaker than the -th knight if and only if , , , and . There are so many stone tablets that Little Q can not determine which to take photos with. Please write a program to help him.
Input
The first line contains a single integer (), the number of test cases. For each test case: The first line contains a single integer (), denoting the number of stone tablets. In the next lines, the -th line contains six integers , , , , and (, ), describing the -th stone tablet, denoting the value of the photo with it.
Output
For each test case, output lines, the -th () of which containing an integer, denoting the maximum total value when the last photo is taken with the -th stone tablet.
Sample Input
1
4
1 2 1 2 1 30
2 1 2 1 2 40
3 3 3 3 3 50
2 3 3 2 4 100
Sample Output
30
40
90
140
Source
2023“钉耙编程”中国大学生算法设计超级联赛(3)