Two teammates each publish a roster of busy windows. Within one roster the windows are given sorted by start and never overlap each other. A window from the first roster and a window from the second overlap if they share a stretch of positive length (touching at a single endpoint does not count). Count the number of pairs (one window from each roster) that overlap.
Line 1: two integers n and m.
Next n lines: two integers start end for roster A (sorted, non-overlapping).
Next m lines: two integers start end for roster B (sorted, non-overlapping).
A single integer: the number of overlapping window pairs.
Example 1
Input
2 2 0 3 5 8 1 2 6 9
Expected
2
Explanation
[0,3) overlaps [1,2); [5,8) overlaps [6,9). The other two pairings share no positive-length stretch, so 2 pairs overlap.
Example 2
Input
2 1 0 2 4 6 2 4
Expected
0
Explanation
The window [2,4) only touches [0,2) at 2 and [4,6) at 4, with no positive-length overlap, so the count is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →