#K531. Can Make Arrays Equal
Can Make Arrays Equal
Can Make Arrays Equal
Given two arrays a and b of length \(n\), determine if it is possible to transform array a into array b by repeatedly performing the following operation:
Select an arbitrary subarray of any length and add \(1\) to every element within that subarray.
In other words, if we define \(d_i = b_i - a_i\) for \(1 \leq i \leq n\), you need to check whether:
- \(d_i \ge 0\) for all \(i\), and
- The sequence \(d_1, d_2, \ldots, d_n\) is non-decreasing, i.e. \(d_i \le d_{i+1}\) for all \(1 \leq i < n\).
If both conditions hold, output YES; otherwise, output NO.
inputFormat
The input 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 array a.
- The third line contains \(n\) space-separated integers, representing the array b.
outputFormat
Print a single line containing YES if array a can be transformed into array b using the allowed operations; otherwise, print NO.
## sample5
1 2 3 4 5
2 3 4 5 6
YES
</p>