Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given an array of N integers, A1, A2, . . . , AN , and M integers, X1, X2, . . . ,

You are given an array of N integers, A1, A2, . . . , AN , and M integers, X1, X2, . . . , XM. For each Xi where i is an integer from 1 to M, you are asked to find the minimum index Y , such that the minimum value of (A1, A2, . . . , AY ) <= Xi .

Format Input

The first line consist of two integers, N and M. The second line consist of N integers, A1, A2, . . . , AN . The third line consist of M integers, X1, X2, . . . , XM.

Format Output

Output M lines, each consist of an integer which is the minimum index Y , such that the minimum value of (A1, A2, . . . , AY ) <= Xi . If no such Y is found, output -1.

Constraints

1 N, M 105

1 Ai , Xi 109

Sample Input 1 (standard input)

7 4

3 3 3 3 2 2 2

1 3 2 8

Sample Output 1 (standard output)

-1

1

5

1

NOTE: USE C LANGUAGE, USE stdio.h library (MUST) or string.h if needed. (DONT USE stdlib.h and algorithm library)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions