Three Arrays
Time limit2sMemory limit256 MB
Given three sorted arrays and a distance d, count triples of elements (one from each array) whose pairwise differences all stay within d.
- Level
Medium6 of 10
- Topics
- Two pointers, Sorting, Brute force, Array
- Solved
- No attempts yet
Problem
You are given three arrays: with elements, with elements, and with elements. All three arrays are sorted in non-decreasing order. That is, for every with , for every with , and for every with .
Count the triples that satisfy , , and .
Input
The input contains one or more test cases. Each test case consists of four lines.
The first line of each test case contains four integers: , , , and (, ).
The second line contains integers : the array ().
The third line contains integers : the array ().
The fourth line contains integers : the array ().
All arrays are sorted in non-decreasing order. The total sum of over all test cases does not exceed . The total sum of over all test cases does not exceed . The total sum of over all test cases does not exceed . The test cases follow one another without any special separators.
Output
For each test case, print a single integer: the number of triples such that , , and .