问题 2146 --A Huge Wave Of Professors Is Approaching!

2146: A Huge Wave Of Professors Is Approaching!

时间限制: 1 Sec  内存限制: 32 MB
提交: 30  解决: 12
[提交][状态][讨论版][数据上传:][下载FPS1元][下载测试数据1元][44kb]

题目描述

Welcome to apply for Zhejiang University.Each ZJU's professor's only admiss one student.And professors' recruitment criteria are different.Professor only recruit the student whoes exam result is between A and B,including A and B.And then professor will choose the student with the highest exam result in these students.Please output this lucky student's exam result.And then the next professor will continue to recruit student from the rest of the students.

输入

The input consists one test case.The first line contains an integer n(n<=300),which means the number of students.The second line contains n integers means the exam results of these n students.As you know,full mark is 500.The third line contains an integer m,which means the number of professors.Then follows m lines,each line contains two integer,A and B(0<=A,B<=500),which means professor's recruitment criteria.

输出

For each test case, you should output m lines with the recruited student's exam result.If no student meet professor's requirement,you should output -1.

样例输入

7
306 304 389 342 343 355 302
4
350 390
380 400
307 303
500 400

样例输出

389
-1
306
-1

提示

来源

[提交][状态]