Time limit: 0.5s
Memory limit: 64MB
Input:
Output:
Task
You are given , an array of integers indexed from 0, and questions:
- : What is the greatest , for which ? If there is no such , print .
- : What is the greatest , for which ? If there is no such , print .
- : What is the smallest , for which ? If there is no such , print .
- : What is the smallest , for which ? If there is no such , print .
Input data
The first line contains the integer . The second line contains the array . The third line contains the integer . The next lines contain the questions.
Because of the large input size, it is recommended to add these lines of code at the beginning of the main()
function:
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
Output data
The first lines will contain the answers, one line for each answer.
Constraints and clarifications
# | Points | Constraints |
---|---|---|
0 | 0 | Example |
1 | 40 | |
2 | 60 | No additional constraints |
Example
stdin
10
1 2 3 6 4 5 3 2 1 10
12
1 5
2 2
3 9
4 4
1 3
2 4
3 3
4 8
1 9
2 8
3 6
4 7
stdout
3
1
10
6
-1
2
9
10
-1
-1
9
8