建立最小堆
#define MAXN 1001
#define MIXH -10001
int H[MAXN], size;
void creat()//最小堆
{
size = 0;
H[0] = MIXH;//设置岗哨;
}
void Insert(int X)
{
int i;
for (i = ++size; H[i / 2] > X; i /= 2)
H[i] = H[i / 2];
H[i] = X;
}
int main()
{
int n, m, x, i, j;
scanf("%d%d", &n, &m);
creat();//初始化;
for (i = 0; i < n; i++)//挨个插入堆
{
scanf("%d", &x);
Insert(x);
}
for (i = 0; i < m; i++)
{
scanf("%d", &j);
printf("%d", H[j]);
while (j > 1)
{
j /= 2;
printf("%d", H[j]);
}
printf("\n");
}
return 0;
}