Given two arrays of integers a and b of the same length, find the number of pairs (i, i)…
- User
Given two arrays of integers a and b of the same length, find the number of pairs (i, i) such that i ≤jand a[il - b[il = ali] - b[i]. main.cp 1 HISTORY Example RULES • For a = [2, -2, 5, 3] and b = [1, 5, -1, 1], the output should be solution (a, b) = 6 . For (i, i) = (o, 0) equality holds: a[0] - b[0] =2-1=1 and a[0] - b [0] = 2 - 1 = 1, For (i, i) = (0, 1) equality holds: a[0] - b [1] = 2 - 5 = -3 and a [1] b [0] = (-2) - 1 = -3 . For (i, i) = (0, 2) equality doesn't hold: a [0] - b[2] = 2 - (-1) = 3 and a [2] - b[0] = 5 - 1 = 4. For (i, i) = (0, 3) §[quality doesn't hold: a [0] - b [3] = 2 - 1 = 1 and a [3] - b [0] = 3 - 1 = 2 , For (i, j) = (1, 1) equality holds: a [1] - b[1] = (-2) - 5 = -7 and а [1] - b[1] = (-2) - 5 = -7 , For (i, i) = (1, 2) equality doesn't hold: a [1] - b [2] = (-2) - (-1) = 1 and a [2] - b [1] = 5 - 5 = 0 , For (i, i) = (1, 3) equality doesn't hold: a [1] - b [3] = -2 - 1 = -3 and a[3] - b[1] = 3 - 5 = -2, For (i, j) = (2, 2) equality holds: a [2] - b[2] = 5 - (-1) = 6 and a [2] - b[2] = 5 - (-1) = 6 , For (i, j) = (2, 3) equality holds:
a [2] - b [3] = 5 - 1 = 4 and a[3] -
b [2] = 3 - (-1) = 4, • For (i, j) = (3, 3) equality holds: a [3] - b [3] = 3 - 1 = 2 and a[3] - b [3] = 3 - 1 = 2. • For a = [25, 0] and b = [0, 25], the output should be solution (a, b) = 3 . IGS
• For (i, j) = (0, 0) equality holds:
a [0] - b [0] = 25 - 0 = 25 and a [0]
- b [0] = 25 - 0 = 25 ,
• For (i, j) = (0, 1) equality holds:
a [0] - b [1] = 25 - 25 = 0 and a [1]
- b[0] = 0- 0= 0.
• For (i, j) = (1, 1) equality holds:
a [1] - b[1] = 0 - 25 = -25 and
a [1] - b [1] = 0 - 25 = -25 •
Answer this in c++ and ensure that the end user is able to run the test cases
- Assistant