TORONTO KIDS COMPUTER CLUB | Monday 20:00 Python Practice 21.04.05.
19262
post-template-default,single,single-post,postid-19262,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Monday 20:00 Python Practice 21.04.05.

11 Apr Monday 20:00 Python Practice 21.04.05.

Question:

You are given an array A of Q integers and Q queries. In each query, you are given an integer i (1≤i≤N).
Your task is to find the minimum index greater than i (1≤i≤N) such that:
Sum of digits of Ai is greater than the sum of digits of Aj
Ai < Aj
If there is no answer, then print -1.

Input format
The first line contains two numbers N and Q.
The next line contains N numbers.
Next Q lines contain Q queries.

Output format
Print the answer as described in the problem

Constraints
(1≤N, Q≤105)(1≤Ai≤109)(1≤Qi≤N)

Sample Input
5 5
62 70 28 62 92
1
5
3
4
2

Sample Output
2
-1
4
-1
-1

Explanation
In the first quary 70 grater than 62 
and sum of digits of 62 = 8 grater than sum f digits of 70=7 (8>7)

No Comments

Post A Comment