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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;

int main() {
    
    int tt;
    cin >> tt;
    while(tt--) {
        
        long long n, m;
        cin >> n >> m;
        
        vector<long long>v(n), t(m);
        for(auto &x : v) cin >> x;
        for(auto &x : t) cin >> x;
        
        multiset<long long>st;
        deque<long long>dq;
        
        //sort(t.begin(), t.end());
        for(auto i : t) {
            dq.push_back(i);
        }
        
        for(auto i : v) {
            st.insert(i);
        }
        
        bool exist = true;
        
        while(true) {
            
            long long el = dq.front();
            // cout << "el : " << el << endl;
            
            // cout << "Before :- " << endl;
            // cout << "st : ";
            // for(auto j : st) {
            //     cout << j << " ";
            // } cout << endl;
            
            // cout << "dq : ";
            // for(auto j : dq) {
            //     cout << j << " ";
            // } cout << endl;
            
            if(st.find(el) != st.end()) {
                // cout << "hitted here at el : " << el << endl;
                dq.pop_front();
                auto it = st.find(el);
                st.erase(it);
            }
            
            else if(el%2 == 0) {
                
                auto it = st.find(el/2);
                
                if(it != st.end()) {
                    dq.pop_front();
                    st.erase(it);
                    dq.push_back(el/2);
                }
                
                else {
                    exist = false;
                    break;
                }
            }
            else if(el == 1) {
                auto it = st.find(el);
                
                if(it == st.end()) {
                    exist = false;
                    break;
                }
                else {
                    st.erase(it);
                    dq.pop_front();
                }
            }
            else {
                long long left = el/2;
                long long right = el-left;
                
                // cout << "left : " << left << " right : " << right << endl;
                
                if(st.find(left) != st.end()) {
                    st.erase(st.find(left));
                    dq.pop_front();
                    dq.push_back(right);
                }
                else if(st.find(right) != st.end()) {
                    st.erase(st.find(right));
                    dq.pop_front();
                    dq.push_back(left);
                }
                else {
                    exist = false;
                    break;
                }
            }
            
            // cout << "st.size() : " << st.size() << " dq.size() : " << dq.size() << endl;
            
            if((int)st.size() == 0) {
                break;
            }
            if((int)dq.size() == 0) {
                break;
            }
            
            // cout << "After :- " << endl;
            // cout << "st : ";
            // for(auto j : st) {
            //     cout << j << " ";
            // } cout << endl;
            
            // cout << "dq : ";
            // for(auto j : dq) {
            //     cout << j << " ";
            // } cout << endl;
        }
        
        if(exist == true && (int)st.size() == 0 && (int)dq.size() == 0) {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

int main() {
    
    int tt;
    cin >> tt;
    while(tt--) {
        
        long long n, m;
        cin >> n >> m;
        
        vector<long long>v(n), t(m);
        for(auto &x : v) cin >> x;
        for(auto &x : t) cin >> x;
        
        multiset<long long>st;
        deque<long long>dq;
        
        //sort(t.begin(), t.end());
        for(auto i : t) {
            dq.push_back(i);
        }
        
        for(auto i : v) {
            st.insert(i);
        }
        
        bool exist = true;
        
        while(true) {
            
            long long el = dq.front();
            // cout << "el : " << el << endl;
            
            // cout << "Before :- " << endl;
            // cout << "st : ";
            // for(auto j : st) {
            //     cout << j << " ";
            // } cout << endl;
            
            // cout << "dq : ";
            // for(auto j : dq) {
            //     cout << j << " ";
            // } cout << endl;
            
            if(el == 1 && st.find(el) == st.end()) {
                exist = false;
                break;
            }
            
            dq.pop_front();
            
            if(st.find(el) != st.end()) {
                st.erase(st.find(el));
            }
            else {
                long long left = el/2;
                long long right = el-left;
                
                if(st.find(left) == st.end() && st.find(right) == st.end()) {
                    dq.push_front(left);
                    dq.push_front(right);
                }
                else if(st.find(left) != st.end()) {
                    dq.push_front(right);
                    st.erase(st.find(left));
                }
                else {
                    dq.push_front(left);
                    st.erase(st.find(right));
                }
            }
            
            if((int)st.size() == 0) {
                break;
            }
            if((int)dq.size() == 0) {
                break;
            }
            
            // cout << "After :- " << endl;
            // cout << "st : ";
            // for(auto j : st) {
            //     cout << j << " ";
            // } cout << endl;
            
            // cout << "dq : ";
            // for(auto j : dq) {
            //     cout << j << " ";
            // } cout << endl;
        }
        
        if(exist == true && (int)st.size() == 0 && (int)dq.size() == 0) {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
}