题目传送门
解题思路:
懒得写,看大佬的题解,题解传送门
AC代码:
1 #include<cstdio> 2 #include<iostream> 3 #include<queue> 4 5 using namespace std; 6 7 int m,n,a[200001],b,tot = 1,j; 8 priority_queue<int> big; 9 priority_queue<int,vector<int>,greater<int> > small; 10 11 int main() 12 { 13 scanf("%d%d",&n,&m); 14 for(int i = 1;i <= n; i++) 15 scanf("%d",&a[i]); 16 for(int i = 1;i <= m; i++) { 17 scanf("%d",&b); 18 for(j = tot;j <= b; j++){ 19 big.push(a[j]); 20 if(big.size() == i) { 21 small.push(big.top()); 22 big.pop(); 23 } 24 } 25 tot = b + 1; 26 printf("%d ",small.top()); 27 big.push(small.top()); 28 small.pop(); 29 } 30 return 0; 31 }