PAT7-05. 魔法优惠券

#include<queue>
#include<cstdio>
#include<vector>
using namespace std;
priority_queue<int>a,c;		// maximum heap
priority_queue<int,vector<int>,greater<int> >b,d; // minimum heap
int main(){
  int n;scanf("%d",&n);
  while(n--){
    int k;scanf("%d",&k);
    if(k>0)a.push(k);
    else b.push(k);
  }
  scanf("%d",&n);
  while(n--){
    int k;scanf("%d",&k);
    if(k>0)c.push(k);
    else d.push(k);
  }
  int total(0);
  while(a.size()&&c.size()){
    total+=a.top()*c.top();
    a.pop();c.pop();}
  while(b.size()&&d.size()){
    total+=b.top()*d.top();
    b.pop();d.pop();}
  printf("%d",total);
  return 0;}


你可能感兴趣的:(PAT7-05. 魔法优惠券)