Misunderstood Missing
Time limit1sMemory limit256 MB
Each round, aggressivity grows by the current increment, then choose to attack, raise the increment by b_i, or raise aggressivity by c_i; maximize total damage.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Warm sunshine, cool wind and a fine day, while the girl watching is pursuing in chaos. Rikka reached out her hand and got the garland on her head, finding LCR with the immortal smile. The dream ended up waking, but the doubts will never disappear. In the end, without knowing about LCR, Rikka was invited to Shuyuan Men, a street of Chinese traditional arts in Xi'an.
"Is it enough to use the stored wires?"
"No problem... Those leaders are only concerned about expanding EC Final for the school's and their 'achievements'. All chores are ours. It is fine to simply connect those wiring boards in the series for each row."
Their conversation engaged Rikka. Feeling strange, she decided to follow them. But before all, she needs to beat the devil in her heart.
Rikka has an aggressivity and an increment of it, which are both initially. There are rounds in total. For , at the beginning of -th round Rikka's aggressivity increases by the increment , and then she can do one of the following:
- Attack and cause a damage of .
- Use the Omnipotent Garland from LCR to increase the increment by .
- Use her Schwarz Sechs Prototype Mark II to increase the aggressivity by .
Rikka wonders the maximal possible damage she could cause in total. Could you help her?
Input
The first line contains a single integer , the number of test cases. Then test cases follow.
The input format of each test case is as follows:
The first line contains a single integer , the number of rounds.
The following lines contain for . The -th line among them contains three integers separated by spaces in order.
It is guaranteed that the sum of in all test cases is at most .
Output
Output lines; each line contains one integer, the answer to that test case.