Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
747 views
in Online Assessments by Expert (46,090 points) | 747 views

1 Answer

0 like 0 dislike
Best answer

Given two arrays A and B of size n. We are given q queries of the form x y. The answer to a given query is (A[ i ]+B[ i ]) where A[ i ] >=x && B[ i ] >=y && (A[ i ] +B[ i ]) is minimum for 0=< i < n. If answer for a query is not possible then print -1 for that query.

`1=< n,q <= 10^5`
`1=< A[i],B[i] <=10^9`
`Eg-`
`n=5 q=4`             
`6 4 8 9 15`
`7 7 2 9 6`
`4 6 -> 11(4,7)`
`2 8 -> 18(9,9)`
`14 9 -> -1`
`7 1 -> 10(8,2)`
by Expert (46,090 points)
selected by