Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1e9+7;

class TrieNode {
public:
    bool isEnd;
    TrieNode* nxt[26];
    TrieNode(bool b = false) {
        isEnd = b;
        memset(nxt, 0, sizeof(nxt));
    }
};

class Trie {
    TrieNode* root;
public:
    Trie() {
        root = new TrieNode();
    }
    void insert(string s) {
        TrieNode* cur = root;
        for (char c : s) {
            if (cur->nxt[c - 'a'] == NULL) {
                cur->nxt[c - 'a'] = new TrieNode();
            }
            cur = cur->nxt[c - 'a'];
        }
        cur->isEnd = true;
    }
    bool search(string s) {
        TrieNode* cur = root;
        for (char c : s) {
            if (!(cur->nxt[c - 'a'])) {
                return false;
            }
            cur = cur->nxt[c - 'a'];
        }
        return cur->isEnd;
    }
    ll countCombs(string s, ll k, ll sz, unordered_map<ll, ll>& dp) {
        if (k == sz) {
            return 1;
        }
        if (dp.find(k) != dp.end()) {
            return dp[k];
        }
        TrieNode* cur = root;
        ll res = 0;
        for (ll i = k; i < sz; i++) {
            if (!(cur->nxt[s[i] - 'a'])) {
                return res;
            }
            cur = cur->nxt[s[i] - 'a'];
            if (cur->isEnd) {
                res = (res + countCombs(s, i + 1, sz, dp)) % mod;
            }
        }
        return dp[k] = res;
    }
};


vector<int>giveLps(string s){
  int n=s.length();
    vector<int>lps(n,0);
    int len=0;
    for(int i=1;i<n;){
        if(s[i]==s[len]){
            len++;
            lps[i]=len;
            i++;
        }else{
            if(len!=0){
                len = lps[len-1];
            }else{
                lps[i]=0;
                i++;
            }
        }
    }
    return lps;
}
void prindq(deque<int>dq){
    while(dq.size()){
        cout<<dq.front()<<" ";
        dq.pop_front();
    }
    cout<<endl;
}
void prinstk(stack<int>st){
    while(st.size()){
        cout<<st.top()<<" ";
        st.pop();
    }
    cout<<endl;
}
void prinvec(vector<int>&vec){
    for(int u:vec){
        cout<<u<<" ";
    }
    cout<<endl;
}
void merge(vector<int>&curr2 , vector<int>&curr){
    vector<int>res;
    int n=curr2.size(),m=curr.size(),i=0,j=0;
    while(i<n && j<m){
        if(curr2[i]<curr[j]){
            res.push_back(curr2[i]);
            i++;
        }else{
            res.push_back(curr[j++]);
        }
    }
    while(i<n){
        res.push_back(curr2[i]);
        i++;
    }
    while(j<m){
        res.push_back(curr[j++]);
    }
    curr2=res;
}
using ppi = pair<int,int>;
void solver(){
    int n,m;
    cin>>n>>m;
    vector<ll>a,b;
    ll sma=0,smb=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        a.push_back(x);
        sma+=x;
    }
    priority_queue<int>pq;
    for(int i=0;i<m;i++){
        ll x;
        cin>>x;
        pq.push(x);
        smb+=x;
    }
    if(sma!=smb){
        cout<<"NO"<<endl;
        return;
    }else{
        sort(a.begin(),a.end());
        int i=n-1;
        while(pq.size() && i>=0){
            int curr = pq.top();
            //cout<<curr<<" "<<a[i]<<endl;
            pq.pop();
            if(curr==a[i]){
                i--;
            }else if(curr>a[i] && abs(curr-2*a[i])<=1){
                 pq.push(curr-a[i--]);
            }else{
                cout<<"NO"<<endl;
                return;
            }
        }
        if(i<0 & pq.size()==0){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }

}

int main() {
  freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   int t;
   cin>>t;
   //t=1;
   for(int i=0;i<t;i++){
     solver();
   }
}