# How to approach this?

Question
Asha has got a set of integers and he is thinking about what interesting problem statement could be formed from these integers. And Eureka! She found one!

The problem statement goes as follow:

1. You have to find the maximum integer among the set of integers and divide the integer by 2.
2. Since this is an integer division the result of division will be an integer.
3. After division if the integer is greater than 0, then we put the updated integer again in the set of integers.

Asha gives you m queries, each query q[i] means, that q[q[i]−1] number of operations has already been performed, and its time to perform q[i]th operation. Your task is to tell that for q[i]th operation which integer will get divided.

### Input Format

The first line contains 2 space-separated integers n,m
denoting the number of integers and the number of queries respectively.
The next line contains n space-separated integers followed by m lines.
In the next m lines, the ith line will contain q[i].

### Output format

Output m lines, the ith of which contains the answer for the ith query.

### Constraints

1<=n,m<=10^6
1<=n,m<=10^6

For 1<=i<=m1<=i<=m,
q[i]>q[i−1].

For 0<=i<=n0<=i<=n,
1<=a[i]<=1091<=a[i]<=109

If no integer is present at the time of the query stop the program.

### Example

4 6
8 5 3 1
1
2
3
4
6
8

#### Output

8
5
4
3
2
1

import java.io.IOException;
import java.util.Arrays;

public class Problem
{
public static void main(String[] args)throws IOException {
System.out.println(“enter number of elements”);
System.out.println(“enter number of constraints”);
int arr[]=new int[n];
int div[]=new int[m];
System.out.println(“enter elements”);
for(int i=0;i<n;i++)
{
}
System.out.println(“enter constraints”);
for(int j=0;j<m;j++)
{
}

``````    for(int k=0;k<m;k++)
{
//System.out.println(div[k]);
Arrays.sort(arr);
System.out.print(prob(arr,div[k]));
}
}
public static int prob(int a[], int b)
{
int[] arr2=new int[a.length];
for(int j=0;j<a.length;j++)
{
arr2[j]=a[j];
}
for(int i=0;i<b-1;i++)
{
arr2[arr2.length-1]= arr2[arr2.length-1]/2;
Arrays.sort(arr2);
}
return arr2[arr2.length-1];
}
``````

}

#include<bits/stdc++.h>
using namespace std;

int operation(vector&v)
{

``````   // for(int)
sort(v.begin(),v.end());
int max = v[v.size()-1];

int max1 =max/2;
v.pop_back();

if(max1>0)
{
v.push_back(max1);
}

return max;
``````

}

void print(vector&v)
{
cout<<endl<<“printing the set”<<endl;
for(auto &it:v)
{
cout<<it<<" ";
}
}

int main()
{

#ifndef ONLINE_JUDGE
freopen(“input.txt”,“r”,stdin);
freopen(“output.txt”,“w”,stdout);
#endif

int n;
cin>>n;

int m;
cin>>m;

int i=0;

vector v;

while(i<n)
{
int x;
cin>>x;
v.push_back(x);

`````` ++i;
``````

}

cin.ignore();

int z=0;

while(m–)
{

``````int q;
cin>>q;
int d;

while(z<q)
{

if(v.size()==0)
{
return 0;
}

d = operation(v);

++z;
}
cout<<d<<endl;
``````

}

}