#P91. [CSP-S 2024] Overspeed versus cameras
[CSP-S 2024] Overspeed versus cameras
Person in Charge
Problem Description
Little D has just joined the traffic management department of a certain country. His first task is to monitor speeding vehicles on a north-south main road of length . To test Little D, his supervisor first asks him to solve a simplified scenario.
This weekend, vehicles are expected on the main road. The -th vehicle enters the road at a position from the southernmost end and drives north with an initial speed and acceleration (uniform acceleration). We only consider vehicles traveling from south to north, so , but can be positive, negative, or zero. A vehicle is considered to have left the main road when it reaches the northernmost end (i.e., at position from the southernmost end) or when its speed drops to (which can only happen if ).
The main road is equipped with speed detectors. The -th detector is located at position from the southernmost end. Each detector can be turned on or off. When a vehicle passes an active detector, if its instantaneous speed exceeds the speed limit , the vehicle is flagged for speeding. Note that if a vehicle enters or exits the main road at a position with an active detector, the detector will also check the vehicle's speed.
The supervisor first wants to know how many of the vehicles will be flagged for speeding if all detectors are turned on.
Additionally, to save energy, the department wants to turn off some detectors. However, they do not want to miss any speeding vehicles. That is, if a vehicle is flagged for speeding when all detectors are on, it must still be flagged after some detectors are turned off. The supervisor also wants to know the maximum number of detectors that can be turned off under this condition.
Given the large value of , the supervisor allows Little D to solve these problems programmatically, so Little D turns to you for help.
Definitions and formulas related to acceleration:
- Uniform acceleration means the object's acceleration remains constant during motion, i.e., the change in speed per unit time is constant.
- For a vehicle with initial speed and acceleration , its speed after time is , and its displacement (distance traveled) is .
- For a vehicle with initial speed and acceleration , when its displacement is , its instantaneous speed is .
- For a vehicle with initial speed and acceleration , when its displacement is , its instantaneous speed is .
If you use floating-point calculations, be mindful of potential precision issues.
Input Format
The first line of input contains a positive integer , the number of test cases.
This is followed by test cases, each formatted as follows:
The first line contains four integers , , , , representing the number of vehicles, the number of detectors, the length of the main road, and the speed limit, respectively.
The next lines:
The -th line contains three integers , , , describing a vehicle.
The last line contains integers , , , , describing the positions of all detectors on the road.
Output Format
For each test case: Output one line containing two integers. The first integer is the number of vehicles flagged for speeding when all detectors are on. The second integer is the maximum number of detectors that can be turned off without missing any speeding vehicles.
Samples
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 -2
6 4 -4
2 5 8 9 15
3 3
Sample 1 Explanation
In this test case, the main road length is , and the speed limit is . Detectors are located at , , , , and from the southernmost end.
- The first vehicle enters at the southernmost end and moves at a constant speed of . It does not exceed the speed limit anywhere on the road.
- The second vehicle enters at position and moves at a constant speed of . When it exits at the northernmost end, the detector at flags it for speeding.
- The third vehicle enters at position with an initial speed of and acceleration of . After traveling unit of distance (i.e., reaching position ), its speed becomes . It continues to speed afterward. Thus, it is flagged by all detectors except the one at .
- The fourth vehicle enters at position with an initial speed of and acceleration of . After traveling units of distance (i.e., reaching position ), its speed becomes . Thus, it is flagged by the detectors at and (positions in ).
- The fifth vehicle enters at position with an initial speed of and acceleration of . After traveling units of distance (i.e., reaching position ), its speed becomes . Thus, it exceeds the speed limit in , but no detectors are present in this interval, so it is not flagged.
Therefore, the second, third, and fourth vehicles are flagged for speeding, so the first output number is .
We can turn off the detectors at , , and , keeping only those at and . The three previously flagged vehicles are still flagged. This is the optimal solution, so the second output number is .
Sample 2
See the files detect/detect2.in and detect/detect2.ans in the contest directory.
This sample satisfies .
Sample 3
See the files detect/detect3.in and detect/detect3.ans in the contest directory.
This sample satisfies Special Property A, with the first 10 test cases satisfying .
Sample 4
See the files detect/detect4.in and detect/detect4.ans in the contest directory.
This sample satisfies Special Property B, with the first 10 test cases satisfying .
Sample 5
See the files detect/detect5.in and detect/detect5.ans in the contest directory.
This sample satisfies Special Property C, with the first 10 test cases satisfying .
Data Range
For all test data, the following guarantees hold:
- ;
- , , ;
- , , ;
- .
| Test Case | Special Property | |
|---|---|---|
| None | ||
| A | ||
| B | ||
| C | ||
| None | ||
Special Property A: .
Special Property B: .
Special Property C: , and no vehicle exits at the northernmost end.