题目来源:https://www.luogu.com.cn/problem/P1801
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <set>
#define ll long long
//小根堆
#define PQ1 std::priority_queue<ll,std::vector<ll>,std::greater<ll>>
//大根堆
#define PQ2 std::priority_queue<ll,std::vector<ll>>
//加速
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
const ll N = 1e7;
ll res = 0;
ll n,m;
void solve(){
PQ1 op;
PQ2 dp;
std::cin >> n >> m;
std::vector<ll> op1(n + 1),op2(m + 1);
for(ll i = 1; i <= n; i ++) std::cin >> op1[i];
for(ll i = 1; i <= m; i ++) std::cin >> op2[i];
ll ans = 0;
for(ll i = 1; i <= m; i ++){
while(ans < op2[i]){
ans ++;
dp.push(op1[ans]);
op.push(dp.top());
dp.pop();
}
std::cout << op.top() << "\n";
dp.push(op.top());
op.pop();
}
return ;
}
int main(){
IOS
ll t = 1;
// std::cin >> t;
while(t --)
solve();
return 0;
}