#K77577. Equal Sum Reordering
Equal Sum Reordering
Equal Sum Reordering
You are given two arrays \(A\) and \(B\) each containing \(n\) integers. Your task is to determine whether it is possible to reorder array \(B\) so that for each index \(i\) (with \(0 \le i < n\)), the sum \(A[i] + B[i]\) is the same constant.
Formally, find if there exists a permutation \(\pi\) of \(\{0, 1, \ldots, n-1\}\) such that:
[ A[i] + B[\pi(i)] = S \quad \text{for all } i \quad (0 \le i < n), ]
where \(S\) is a constant. If such a reordering exists, output "YES"; otherwise, output "NO".
inputFormat
The input is read from standard input and consists of three lines:
- The first line contains an integer \(n\), representing the number of elements in each array.
- The second line contains \(n\) space-separated integers representing the elements of array \(A\).
- The third line contains \(n\) space-separated integers representing the elements of array \(B\).
outputFormat
Output a single line containing either "YES" if it is possible to reorder \(B\) such that all \(A[i] + B[i]\) are equal, or "NO" otherwise.
## sample4
1 2 3 4
5 6 7 8
YES