Help to solve the error in code

i don’t know what’s wrong in this implementation. can anyone help to resolve it?
https://www.codechef.com/viewsolution/45070029

5
7 11 6 1 9
5
4 12
1 20
4 2
2 12
2 10

Check this test-case