Description
给定M及一列数,每个数在0到100,000之间。
(为了方便描述,设共N个数,1< N < = 2500000) 输出每M个数中的最大数,即1~M中的最大数,
2~M+1中的最大数……N-M+1~N中的最大数,共N-M+1个。
Format
Input
第一行是一个数M,接下来是N个数,每个数一行,以-1作为结尾
Output
输出N-M+1个最大数,每个数一行。
Samples
输入数据 1
3
10
11
10
0
0
0
1
2
3
2
-1
Copy
输出数据 1
11
11
10
0
1
2
3
3
#include<bits/stdc++.h>
using namespace std;
int n,lk,m,f[2432588];
struct op{
int a,b;
};
bool operator<(op a,op b){
return a.a<b.a;
}
priority_queue<op> q;
int main(){
cin>>m;
for(int i=1;i<=m;i++){
cin>>lk;
q.push({lk,i});
}
cout<<q.top().a<<endl;
for(int i=m+1;;i++){
cin>>lk;
if(lk==-1){
break;
}
q.push({lk,i});
f[i-m]=1;
while(1){
if(f[q.top().b]==1){
f[q.top().b]=0;
q.pop();
}
else break;
}
cout<<q.top().a<<endl;
}
return 0;
}