luogu#P14978. [USACO26JAN1] Mooclear Reactor S
[USACO26JAN1] Mooclear Reactor S
Problem Description
Bessie is designing a nuclear reactor to power Farmer John's lucrative new AI data center business, CowWeave!
The reactor core consists of () fuel rods, numbered through . The -th rod has a "stable operating range" (), meaning it can only generate power if its energy (chosen by Bessie) satisfies ; otherwise, it sits idle and does not generate power. Moreover, must always be an integer. Note that can be any integer, not limited to .
However, quantum interactions between the rods mean that there are constraints of the form where Bessie must satisfy ( and ) to prevent the reactor from melting down.
Help Bessie find the maximum number of power-generating rods she can achieve in her design without it melting down!
Input Format
The first line contains (), the number of independent tests. Each test is specified in the following format:
- The first line contains the two integers and .
- The second line contains the integers .
- The third line contains the integers .
- The next lines each contain three integers , , and , each representing a constraint.
It is guaranteed that neither the sum of nor the sum of over all tests exceeds .
Output Format
If no choice of rod energies exists that satisfies all constraints, output . Otherwise, output the maximum number of power-generating rods Bessie can achieve.
2
3 3
1 2 3
1 2 3
1 1 2
2 2 10
1 1 4
3 2
1 2 3
1 2 3
1 1 2
2 2 10
-1
2
1
3 2
10 -10 10
10 -10 10
1 2 0
2 3 0
3
5
3 3
1 -1 0
2 1 2
1 2 1
1 3 4
2 3 3
1 1
-100
100
1 1 3
1 1
-100
100
1 1 2
1 2
-100
100
1 1 2
1 1 4
1 2
-100
100
1 1 2
1 1 2
2
-1
1
-1
1
Hint
In the second test, the constraints require that:
Choosing energies results in power-generating rods because:
and satisfies all required constraints.
Choosing rod energies results in power-generating rods.
- Input 4: for all constraints.
- Inputs 5-7: for all constraints.
- Inputs 8-10: for all constraints.
- Inputs 11-13: No additional conditions.