Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    priority_queue<int> p1;
    priority_queue<int> p2;
    int s1=0,s2=0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        p1.push(a[i]);
        s1+=a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        p2.push(b[i]);
        s2+=b[i];
    }
    // cout<<s1<<" "<<s2<<endl;
    if(s1!=s2){
        cout<<"No"<<endl;
        return;
    }
    bool flag=false;
    bool ans=false;
    while (!p2.empty()) {
        int x = p2.top();
        if(x==1){
            if(p1.top()==1 && p2.size()==p1.size()){
                flag=true;
                ans=true;   
            }else{
                flag=true;
            }
        }
        // while(p2.top()/2>p1.top()){
        //     p2.pop();
        //     p2.push(floor(p2.top()/2.0));
        //     p2.push(ceil(p2.top()/2.0));
        // }
        if(flag) break;
        p2.pop();
        if(p1.top()==x){
            // cout<<p1.top()<<endl;
            p1.pop();
        }else{
            int a = floor(x / 2.0);
            int b = ceil(x / 2.0);
            if (!p1.empty() && p1.top() == b) {
                // cout<<p1.top()<<endl;
                p1.pop();
            }
            else p2.push(b);
            p2.push(a);
        }
        // if(flag) break;
    }
    // cout << p1.size() << endl;
    // cout << p2.size() << endl;
    // cout << ans << endl;
    // cout << flag << endl;
    // cout << p1.top() << endl;
    // cout << p2.top() << endl;
    if ((p1.empty() && p2.empty() ) || ans) cout << "Yes" << endl;
    // while (p1.size() > 0){
    //     cout<<p1.top()<<" ";
    //     p1.pop();
    // }
    // cout<<endl;
    // while (p2.size() > 0){
    //     cout<<p2.top()<<"";
    //     p2.pop();
    // }
    // {
    //     /* code */
    // }
    
    else cout << "No" << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

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

void solve(){
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    priority_queue<int> p1;
    priority_queue<int> p2;
    int s1=0,s2=0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        p1.push(a[i]);
        s1+=a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        p2.push(b[i]);
        s2+=b[i];
    }
    // cout<<s1<<" "<<s2<<endl;
    if(s1!=s2){
        cout<<"No"<<endl;
        return;
    }
    bool flag=false;
    bool ans=false;
    while (!p2.empty()) {
        if(p2.size()>p1.size()){
            flag=true;
            break;
        }
        int x = p2.top();
        if(x==1){
            if(p1.top()==1 && p2.size()==p1.size()){
                flag=true;
                ans=true;   
            }else{
                flag=true;
            }
        }
        // while(p2.top()/2>p1.top()){
        //     p2.pop();
        //     p2.push(floor(p2.top()/2.0));
        //     p2.push(ceil(p2.top()/2.0));
        // }
        if(flag) break;
        p2.pop();
        if(p1.top()==x){
            // cout<<p1.top()<<endl;
            p1.pop();
        }else{
            int a = floor(x / 2.0);
            int b = ceil(x / 2.0);
            if (!p1.empty() && p1.top() == b) {
                // cout<<p1.top()<<endl;
                p1.pop();
            }
            else p2.push(b);
            p2.push(a);
        }
        // if(flag) break;
    }
    // cout << p1.size() << endl;
    // cout << p2.size() << endl;
    // cout << ans << endl;
    // cout << flag << endl;
    // cout << p1.top() << endl;
    // cout << p2.top() << endl;
    if ((p1.empty() && p2.empty() ) || ans) cout << "Yes" << endl;
    // while (p1.size() > 0){
    //     cout<<p1.top()<<" ";
    //     p1.pop();
    // }
    // cout<<endl;
    // while (p2.size() > 0){
    //     cout<<p2.top()<<"";
    //     p2.pop();
    // }
    // {
    //     /* code */
    // }
    
    else cout << "No" << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}