PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000139. Giá trị khoảng cách giữa hai mảng (Find the Distance Value Between Two Arrays)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Giá trị khoảng cách giữa hai mảng (Find the Distance Value Between Two Arrays)
Find the Distance Value Between Two Arrays
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given integer arrays (length ) and (length ), and a nonnegative integer , an element is considered far if for every . Count the positions of containing far elements. Equal elements at different positions count separately.
Input
The first line contains . The second line contains integers of , and the third line contains integers of .
Output
Print one integer, the number of far positions in .
Subtasks
- Subtask 1 (20 points): ; ; ; for every ; for every .
- Subtask 2 (30 points): ; ; ; for every ; for every .
- Subtask 3 (50 points): ; ; ; for every ; for every .
Examples
Input
3 4 2
4 5 8
10 9 1 8
Output
2
Explanation
For , the nearest element of is and the distance is . For , the nearest is with distance . For , there is a value in at distance . Thus two positions are far.