#K58032. Count Pairs With Sum
Count Pairs With Sum
Count Pairs With Sum
You are given two arrays A and B, each containing N integers, and a target integer X. Your task is to count the number of ordered pairs (i, j) (with 0-based indexing) such that:
\( A_i + B_j = X \)
The problem tests your ability to implement simple nested iterations (or more efficient methods) to determine the count of all valid pairs. Note that the arrays can contain duplicate values and each occurrence is considered distinct.
inputFormat
The input is read from stdin and has the following format:
- First line: an integer
N
, the number of elements in each array. - Second line:
N
space-separated integers representing arrayA
. - Third line:
N
space-separated integers representing arrayB
. - Fourth line: an integer
X
, the target sum.
outputFormat
Output a single integer to stdout representing the number of pairs (i, j) such that \( A_i + B_j = X \).
## sample4
1 2 3 4
5 2 2 1
6
3