Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Position Jojo is given N integers, sorted in non-descending order, A 1, A 2, ..., A n by his teacher. His teacher also give him

Position

Jojo is given N integers, sorted in non-descending order, A 1, A 2, ..., A n by his teacher. His teacher also give him M numbers, Q 1, Q 2, ..., Q m. For every number Q i that his teacher gave him, at what position does number Q i located? If there are several answers, you should print the position with the smallest number and if there is no answer, you should print -1.

Format Input

There will be 3 lines. The first line consist of two integers N and M. The second line consist of N integers A 1, A 2, ..., A n. The third line consist of M integers Q 1, Q 2, ..., Q m.

Format Output

Output M lines, the answer to the problem.

Constraints

1 N, M, A i , Q i 100000

Sample Input 1 (standard input)

3 2

1 2 3

1 2

Sample Output 1 (standard output)

1

2

Sample Input 2 (standard input)

4 2

1 3 5 5

100 5

Sample Output 2 (standard output)

-1

3

PLEASE USE C PROGRAMMING AND FOR THE HEADER USE INCLUDE STDIO.H

MAKE THE CODE AS SIMPLE AS YOU CAN

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions