#P3658. Unfriendly Crossing Pairs
Unfriendly Crossing Pairs
Unfriendly Crossing Pairs
Farmer John is rethinking the issue of cows crossing the road in his farm. In the previous problems, cows were considered friendly under a stricter criterion. Now, two breeds a and b are defined to be friendly if and only if \(|a - b| \leq K\) and unfriendly otherwise. The farm consists of N fields on each side of the road, with each side having an ordering of fields identified by cow breed numbers. A crossing pair is defined in the same manner as in the previous problems, that is, if the cows appear in one order on one side of the road and in the reverse order on the other side. Your task is to count the number of unfriendly crossing pairs of breeds, i.e. crossing pairs for which \(|a - b| > K\>.
inputFormat
The input begins with a line containing two integers N and K (the number of fields on each side of the road and the friendliness threshold, respectively). The second line contains N integers representing the ordering of fields (by breed number) on one side of the road. The third line contains a permutation of these N integers, representing the ordering on the opposite side of the road.
outputFormat
Output a single integer that denotes the number of unfriendly crossing pairs of breeds.
sample
4 1
1 2 3 4
1 3 2 4
0