#3928. [CERC2014] Outer space invaders

[CERC2014] Outer space invaders

Background

The aliens from outer space have (finally!) invaded Earth. Defend yourself, or be disintegrated! Or assimilated. Or eaten. We are not yet sure.

Descriptions

The aliens follow a known attack pattern. There are nn attackers, the ii-th one appears at time aia_i, at distance did_i from you. He must be destroyed no later than at time bib_i, or else he will fire his weapon, which will definitely end the fight.

Your weapon is an area-blaster, which can be set to any given power. If fired with power RR, it momentarily destroys all aliens at distance RR or smaller. It also consumes RR fuel cells. Determine the minimal cost (measured in fuel cells) of destroying all the aliens, without being killed.

Input Format

The first line of input contains the number of test cases TT. The descriptions of the test cases follow:

Each test case starts with a line containing the number of aliens nn. Of the next nn lines, the ii-th one contains three integers ai,bi,dia_i,b_i,d_i .
The ii-th alien appears at time aia_i, is idle until bib_i, and his distance from you is did_i.

Output Format

For each test case, output one line containing the minimum number of cells needed to destroy all the aliens.

1
3
1 4 4
4 7 5
3 4 7
7

Limit and hint

For 100%100\% of testcases, 1T2501\le T\le 250, 1n3001\le n\le 300, 1ai<bi1041\le a_i< b_i\le 10^4, 1di1041\le d_i\le 10^4.

Source

ACM ICPC 2014-2015 Central European Regional Contest, Problem L