Gym-100712J-Candy

直接维护两个优先队列,然后拿出来比较久好了

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

map<int, int> age, candy;
map<int, int>::iterator ita, itc;
int n, m;

int main(){
    int t;
    scanf("%d", &t);
    while (t--){
        scanf("%d%d", &n, &m);
        int x;
        age.clear();
        candy.clear();
        while (n--){
            scanf("%d", &x);
            ++age[x];
        }
        while (m--){
            scanf("%d", &x);
            ++candy[x];
        }
        ita = age.begin();
        itc = candy.begin();
        while (ita!=age.end() && itc!=candy.end()){
            while (itc!=candy.end() && ita->second>itc->second)
                candy.erase(itc++);
            if (itc == candy.end())
                break;
            age.erase(ita++);
            candy.erase(itc++);
        }
        printf(age.empty() ? "YES\n" : "NO\n");
    }
    return 0;
}

你可能感兴趣的:(Gym-100712J-Candy)