#P9676. [ICPC 2022 Jinan R] Skills

[ICPC 2022 Jinan R] Skills

题目描述

Prof. Pang has 33 different skills to practice, including soda drinking, fox hunting, and stock investing. We call them Skill 11, Skill 22, and Skill 33. In each of the following nn days, Prof. Pang can choose one of the three skills to practice. In the ii-th day (1in1\le i\le n), if Prof. Pang chooses Skill jj (1j31\le j\le 3) to practice, his level of Skill jj will increase by ai,ja_{i,j}. Initially, Prof. Pang's levels of all skills are 00.

Prof. Pang forgets skills if he does not practice. At the end of each day, if he has not practiced Skill jj for kk days, his level of Skill jj will decrease by kk. For example, if he practices Skill 11 on day 11 and Skill 22 on day 22, at the end of day 22, he has not practiced Skill 11 for 11 day and has not practiced Skill 33 for 22 days. Then his levels of Skill 11 and Skill 33 will decrease by 11 and 22, respectively. His level of Skill 22 does not decrease at the end of day 22 because he practices Skill 22 on that day. In this example, we also know that his levels of Skill 22 and Skill 33 both decrease by 11 at the end of day 11.

Prof. Pang's level of any skill will not decrease below 00. For example, if his level of some skill is 33 and at the end of some day, this level is decreased by 44, it will become 00 instead of 1-1.

Prof. Pang values all skills equally. Thus, he wants to maximize the sum of his three skill levels after the end of day nn.

Given ai,ja_{i,j} (1in,1j31\le i\le n, 1\le j\le 3), find the maximum sum.

输入格式

The first line contains a single integer T (1T1000)T~(1 \le T \le 1000) denoting the number of test cases.

For each test case, the first line contains an integer n (1n1000)n~(1 \le n \le 1000). The (i+1)(i+1)-th line contains three integers ai,1,ai,2,ai,3a_{i,1}, a_{i,2}, a_{i,3} (0ai,j100000\le a_{i,j}\le 10000 for any 1in,1j31\le i\le n, 1\le j\le 3).

It is guaranteed that the sum of nn over all test cases is no more than 10001000.

输出格式

For each test case, output the maximum possible sum of skill levels in one line.

2
3
1 1 10
1 10 1
10 1 1
5
1 2 3
6 5 4
7 8 9
12 11 10
13 14 15

26
41