样例都没问题!!!但是全WA了!!!求助!!
#include <bits/stdc++.h>
using namespace std;
int n,a,ans,x,y;
priority_queue<int>q;
priority_queue<int,vector<int>,greater<int> >p;
int main(){
scanf("%d%d",&n,&a);
ans=a;
printf("%d\n",ans);
for(int i=1;i<=n/2;i++){
scanf("%d%d",&x,&y);
if(x>y) swap(x,y);
if(x<ans&&y<ans){
p.push(ans);
q.push(x);
q.push(y);
ans=q.top();
q.pop();
}
else if(x>ans&&y>ans){
q.push(ans);
p.push(x);
p.push(y);
ans=p.top();
p.pop();
}
else{
q.push(x);
p.push(y);
}
printf("%d\n",ans);
}
return 0;
}
这个做题思路有问题吗?
就是分两个堆