P3658 [USACO17FEB] Why Did the Cow Cross the Road III P
Description
Farmer John is continuing to ponder the issue of cows crossing the road through his farm, introduced in the preceding two problems. He realizes now that the threshold for friendliness is a bit more subtle than he previously considered -- breeds $a$ and $b$ are now friendly if $|a - b| \leq K$, and unfriendly otherwise.
Given the orderings of fields on either side of the road through FJ's farm, please count the number of unfriendly crossing pairs of breeds, where a crossing pair of breeds is defined as in the preceding problems.
Input Format
N/A
Output Format
N/A
Explanation/Hint
In this example, breeds 1 and 4 are unfriendly and crossing, as are breeds 1 and 3.