Traffic Volume
InterviewTime limit1sMemory limit256 MB
Count how many cars came from the left from the unordered times in two boxes with offsets of 500, 1000, and 1500.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Simulation
- Solved
- No attempts yet
Problem
Seungmin measures the traffic on the Mapo Bridge. He hung two strings across the road, parallel and a fixed distance apart. Every time a car wheel rolls over a string, a small box at the end of that string records the time. Records from the left string go into the left box, records from the right string go into the right box.
One car coming from the left leaves four records.
- time , when the front wheels cross the left string
- time , when the rear wheels cross the left string
- time , when the front wheels cross the right string
- time , when the rear wheels cross the right string
A car coming from the right follows the same rule with left and right swapped. The right box gets and , the left box gets and .
At most one car is on a string at any moment. Given the recorded times in the two boxes, find how many cars came from the left.
Input
The first line has the number of test cases ().
The first line of each test case has (), the number of times recorded in one box. Each car leaves two records in each box, so is even. The second line has the times from the left box, and the third line has the times from the right box. Every time is a non-negative integer smaller than , and the times come in no particular order. When , both lines are empty.
The input can always be explained by a set of cars that obey the rules above.
Output
For each test case, print the number of cars that came from the left, one per line.