**Introduction**

This blog will discuss a problem based on Arrays. It involves a simple construction and implementation using array & loops.

**Problem Statement**

Anuj has been given an array *A[ ]* of length *N* and an integer *M*. You have given *Q* queries in an array *query[ ]*. Your task is to find for each query the number of elements greater than or equal to *query[i]* and decrease all such elements by M. Process subsequent queries on updated *array A[ ]*.

**INPUT **

N = 4, Q = 3, and M = 1

A[] = [1, 2, 3, 4];

Query[] = [4, 3, 1];

**OUTPUT**

1 2 4

**Explanation**

For *query[0]=4* : elements which are greater than or equal is {4}, and the modified array will be {1, 2, 3, 3}

For *query[1]=3* : elements which are greater than or equal are {3, 3} and the modified array will be {1, 2, 2, 2}

For *query[2]=1* : elements which are greater than or equal is {1, 2, 2, 2} and the modified array will be {0, 1, 1, 1}

**INPUT **

N = 3, Q = 2, and M = 2

A[] = [1, 2, 3];

Query[] = [3, 3];

**OUTPUT**

1 0

**Explanation**

For *query[0]=3* : elements which are greater than or equal is {3}, and the modified array will be {1, 2, 1}

For *query[1]=3* : elements which are greater than or equal are {} and the modified array will be {1, 2, 1}