cswork / OAOpen practice workspace

AmazonOA #325

Predict Answer

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & Heaps

For each 1-based query day i, find among the other days the nearest day j whose price is strictly lower than that day's; if two days are equally near, choose the smaller day number. If there is no strictly cheaper day, output −1. Each query is independent and does not change the prices.

Input

The first line contains n q, the second line contains n stockData values, and the third line contains q 1-based days. The original bounds are 1≤n,q≤100000, 1≤stockData[i]≤10^9, 1≤query≤n. The raw restores the conditions stockData[j]<stockData[i] and j≠i, which the HTML had swallowed.

Output

Output the q answers in query order, separated by spaces.

Example 1

Input:

10 3
5 6 8 4 9 10 8 3 6 4
6 5 4

Output:

5 4 8

Example 2

Input:

3 2
1 2 1
2 1

Output:

1 -1

Example 3

Input:

2 2
3 3
1 2

Output:

-1 -1

Example notes

The answers are 5 4 8; 1 −1; and −1 −1. An equal price is not lower, and at equal distance the left day wins.

Editorial

Loading solution…