Two sensors A and B each emit a non-decreasing stream of timestamps. To audit ordering, count how many pairs (i, j) — one index into stream A and one into stream B — have A[i] > B[j].
Line 1: two integers n and m, the lengths of streams A and B.
Line 2: n non-decreasing integers, stream A.
Line 3: m non-decreasing integers, stream B.
A single integer: the number of pairs with A[i] > B[j].
Example 1
Input
3 3 2 5 8 1 5 6
Expected
5
Explanation
Counting A[i] > B[j]: 2 beats 1 (1 pair); 5 beats 1 (1); 8 beats 1, 5, 6 (3). Total 5.
Example 2
Input
2 2 1 2 5 9
Expected
0
Explanation
No value in A exceeds any value in B, 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 →