Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 203 ms):
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;

#define ci                  cin >>
#define co                  cout <<
#define edl                 << '\n'
#define elif                else if
#define cnu                 continue
#define ll                  int64_t
#define rep(i, a, b, c)     for (ll i = a; i < b; i += c)
#define rrep(i, a, b, c)       for (ll i = b - 1; i >= a; i -= c)

#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define ull                 unsigned long long int
#define vi                  vector<int>
#define vl                  vector<ll>
#define vul                 vector<ull>
#define vpll                vector<pair<ll, ll>>
#define F                   first
#define S                   second
#define pb                  push_back
#define po                  pop_back
#define all(v)              v.begin(), v.end()
#define vs(v)               v.size()
#define mkp(x, y)           make_pair(x, y)
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define FILL(a,x)           memset(a,x,sizeof(a))
template <typename T>
T cele(T a, T b)
{
    if(b==0) {
        return -1;
    }
    if (a % b == 0)
        return a / b;
    return a / b + 1;
}
template <typename T>
void dpv(vector<T> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << " ";
    }
    cout << endl;
}
template <typename T>
void dpv(vector<pair<T,T>> v)
{
    for(auto it:v)
    {
        cout<<it.F<<" "<<it.S<<endl;
    }
}
template <typename T>
void dpv(map<T,T> v)
{
    for(auto it:v)
    {
        cout<<it.F<<" "<<it.S<<endl;
    }
}
template <typename T>
void dpv(set <T> v)
{
    for(auto i:v) {
        cout<<i<<" ";
    }
    cout<<endl;
}
template <typename T>
void gtv(vector<T> &v, ll n)
{
    T x;
    for (ll i = 0; i < n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
}

bool cmp(pll l, pll r) {
    if (l.second != r.second) {
        return l.second < r.second;
    }
    return l.first < r.first;
}

ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

ll power(ll b,ll e)
{
    if(e==0)
    return 1;
    if(e%2)
    return ((b*power((b)*(b),(e-1)/2)));
    else
    return power((b)*(b),e/2);
}
double squareroot(ll key,double eps)
{
    double left=0,right=key;
    double mid=left + (right - left) / 2;
    while(right-left>eps)               //eps is for the precision
    {
        mid=left + (right - left) / 2;
        if (mid*mid < key)
        {
            left=mid;
        }
        else
        {
            right=mid;
        }
    }
    return mid;
}
ll squareroot(ll number)
{
    ll start = 0, end = 1e9;
    ll mid;
    ll ans;
    while (start <= end) {
        mid = start+ (end-start)/2;
        if (mid * mid == number) {
            ans = mid;
            break;
        }
        if (mid * mid < number) {
            start = mid + 1;
            ans = mid;
        }
        else {
            end = mid - 1;
        }
    }
    return ans;
}

bool cmpVec(vector<char> a,vector<char> b) { // for a>b
    ll s=a.size(),t=b.size();
    ll z=min(s,t);
    rep(i,0,z,1) {
        if(a[i]<b[i]) {
            return false;
        }
        elif(a[i]>b[i]) {
            return true;
        }
    }
    if(s>t)
        return true;
    return false;
}

ll next(vl f,ll i) {
    rep(p,i+1,f.size(),1) {
        if(f[i]==0) {
            return i;
        }
    }
    if(i==f.size()-1) {
        rep(p,0,i,1) {
            if(f[i]==0) {
                return i;
            }
        }        
    }
    return -1;
}
ll prev(vl f,ll i) {
    rrep(p,0,i,1) {
        if(f[i]==0) {
            return i;
        }
    }
    if(i==0) {
        rrep(p,i+1,f.size(),1) {
            if(f[i]==0) {
                return i;
            }
        }        
    }
    return -1;
}

ll modd(ll i,ll n) {
    if(i>=0) {
        return i%n;
    }
    return (i+(abs(i/n)+1)*n)%n;
}

vector<ll> primeFactors(ll n)
{
    int c=2;
    set<ll> r;
    vl rest;
    while(n>1)
    {
        if(n%c==0){
        r.insert(c);
        n/=c;
        }
        else c++;
    }
    for(auto it:r) {
        rest.pb(it);
    }
    return rest;
}

void findXorSum(ull s, ull x) {
    ull A = (s - x)/2;
    ll t1 = s,t2=x;
    ll ans=0;
    ll a = 0;
    ll b = 0;
    ans++;
    for (int i=0; i<8*sizeof(s); i++)
    {
        ans=0;
        ull xi = (x & (1 << i));
        ull ai = (A & (1 << i));
        if (xi == 0 && ai == 0){
            ans++;
        }
        else if (xi == 0 && ai > 0)
        {
            ans=ans&1;
            a = ((1 << i) | a);
            b = ((1 << i) | b);
        }
        else if (xi > 0 && ai == 0) {
            ans=ans&0;
            a = ((1 << i) | a);
        }
        else {
            ans=0;
            co -1 edl;
            return;
        }
    }
    if((a+b)!=t1) {
        co -1 edl;
        return;
    }
    co a<<" "<<b edl;
}

ll getSumDigit(ll a)
{
    ll x = 0;
    while (a != 0)
    {
        x += a % 10;
        a /= 10;
    }
    return x;
}

bool isPalindrome(string S)
{
    for (int i = 0; i < S.length() / 2; i++) {
        if (S[i] != S[S.length() - i - 1]) {
            return false;
        }
    }
    return true;
}

vector<vl> rotate(vector<vl>& a,ll n) {
    vector<vl> ans;
    vl tmp;
    for (int i = n - 1; i >= 0; i--) {
        tmp.clear();
        for (int j = n - 1; j >= 0; j--)
            tmp.pb(a[i][j]);
 
        ans.pb(tmp);
    }
    return ans;
}

void sieve()
{
    ll spf[(ll)(1e7+20)]; //make it global
    spf[1] = 1;
    for (ll i = 2; i < 1e7+20; i++)
        spf[i] = i;
    for (ll i = 4; i < 1e7+20; i += 2)
        spf[i] = 2;
    for (ll i = 3; i * i < 1e7+20; i++) {
        if (spf[i] == i) {
            for (ll j = i * i; j < 1e7+20; j += i)
                if (spf[j] == j)
                    spf[j] = i;
        }
    }
}

bool checkRBS(string s) {
    stack<ll> st;
    ll n = s.size();
    if(s[0]==')') {
        return false;
    }
    st.push(0);
    rep(i,1,n,1) {
        if(s[i]=='(') {
            st.push(i);
            cnu;
        }
        if(st.empty()) {
            return false;
        }
        st.pop();
    }
    return true;
}

ll leftClosest(vl& v,ll x) {
    ll n = v.size();
    ll low=-1,hi=n,mid,ind=-1,maxi=-1e5;
    while(low+1<hi) {
        mid = low+(hi-low)/2;
        if(v[mid]>=x) {
            hi = mid;
        }
        else {
            low = mid;
        }
    }
    return hi;
}

ll rightClosest(vl& v,ll x) {
    ll n = v.size();
    ll low=-1,hi=n,mid,ind=-1,maxi=-1e5;
    while(low+1<hi) {
        mid = low+(hi-low)/2;
        if(v[mid]>x) {
            hi = mid;
        }
        else {
            low = mid;
        }
    }
    return low;
}

void SieveOfEratosthenes(ll n) {
    vl t;
    bool prime[(ll)(1e7) + 3];
    memset(prime, true, sizeof(prime));  
    for (ll p = 2; p * p <= n; p++) {
        if (prime[p] == true) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
            t.pb(p);
        }
    }
}

ll dfs(ll r, vl& leaf, vector<vl>& adj, vl& vis) {
    ll ret = 0;
    if(adj[r].size() == 1 && r!=0) {
        return leaf[r] =1;
    }
    for(auto it: adj[r]) {
        if(!vis[it]) {
            vis[it] = 1;
            ret += dfs(it,leaf,adj,vis);
        }
    }
    return leaf[r] = ret;
}

class Trie {
    vector<Trie*> links;
    int val;
    bool end;
public:
    Trie() {
        links.resize(2,NULL);
        val = 0;
        end = false;
    }
    void insert(int x) {
        auto cur = this;
        rrep(i,0,31,1) {
            int b = (x>>i)&1;
            if(!cur->links[b]) {
                cur->links[b] = new Trie();
                end = false;
            }
            cur = cur->links[b];
            cur->end = false;
        }
        cur->val = x;
        cur->end = true;
    }
    int search(int x) {
        auto cur = this;
        rrep(i,0,31,1) {
            int b = (x>>i)&1;
            if(cur->links[1^b]) {
                cur = cur->links[1^b];
                cur->end = false;
            }
            else {
                cur = cur->links[b];
                cur->end = false;
            }
        }
        cur->end = true;
        return (x^(cur->val));
    }
};

void help(vl& a, int i, ll cur, ll& mini, ll tot) {
    // co mini edl;
    if(cur >= tot) {
        mini = min(mini,cur);
        return;
    }
    if(i == a.size()) {
        return;
    }
    help(a,i+1,cur+a[i],mini,tot);
    help(a,i+1,cur,mini,tot);
}

bool checkNQueen(vl& f, ll p) {
    ll y = f.size();
    if(!y) {
        return true;
    }
    rep(i,0,f.size(),1) {
        if(p == f[i] || abs(f[i]-p) == abs(y-i)) {
            return false;
        }
    }
    return true;
}

vector<vector<int>> findPrefixCount(vector<int>& arr, int n)
{
    vector<vector<int>> prefix_count(32,vector<int>(100000));
    for (int i = 0; i < 32; i++) {
        prefix_count[i][0] = ((arr[0] >> i) & 1);
        for (int j = 1; j < n; j++) {
            prefix_count[i][j] = ((arr[j] >> i) & 1);
            prefix_count[i][j] += prefix_count[i][j - 1];
        }
    }
    return prefix_count;
}

bool isSubsequence(string& s, string& subS) {
    int i=0, j=0;
    while(i<s.size() && j<subS.size()) {
        if(s[i]==subS[j]) {
            j++;
        }
        i++;
    }
    return j==subS.size();
}

int ceil_log2(long long int a, bool c=true) {
    long long int res = 1;
    int ans = 0;
    while(res<a) {
        res *= 2ll;
        ans++;
    }
    if(!c && res!=a) {
        ans--;
    } 
    return ans;
}

class dsu {
    public:
    vector<int> rank, parent;
    dsu(int n) {
        for(int i=0; i<n; i++) {
            rank.push_back(0);
            parent.push_back(i);
        }
    }
    int par(int n) {
        if(parent[n]==n) {
            return n;
        }
        return parent[n]=par(parent[n]);
    }
    void unionByRank(int a, int b) {
        if(par(a) == par(b)) {
            return;
        }
        a = par(a), b = par(b);
        if(rank[a]>rank[b]) {
            parent[b] = a;
            return;
        }
        if(rank[a] == rank[b]) {
            rank[b]++;
        }
        parent[a] = b;
    }
};

void kanhaiya()
{
    ll n, m;
    ci n>>m;
    vl a, b;
    gtv(a,n);
    gtv(b,m);
    ll s1 = accumulate(all(a),0), s2 = accumulate(all(b),0);
    if(s1!=s2) {
        co "NO" edl;
        return;
    }
    priority_queue<ll> pqa, pqb;
    rep(i,0,n,1) {
        pqa.push(a[i]);
    }
    rep(i,0,m,1) {
        pqb.push(b[i]);
    }
    while(!pqb.empty()) {
        while(!pqb.empty() && pqb.top()==pqa.top()) {
            pqb.pop();
            pqa.pop();
        }
        if(pqb.empty()) {
            cnu;
        }
        if(pqb.top() < pqa.top()) {
            co "NO" edl;
            return;
        }
        ll t = pqb.top();
        pqb.pop();
        pqb.push(t/2);
        pqb.push(t-t/2);
    }
    if(pqa.empty()) {
        co "YES" edl;
        return;
    }
    co "NO" edl;
} 

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    fast_cin();
    ll t = 1;
    cin >> t;
    for (int it = 1; it <= t; it++)
    {
        // cout << "Case #" << it << ": ";
        // cout << "Case " << it << ": ";
        kanhaiya();
    }
    return 0;
}

Solution 2 (runtime: 406 ms):
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#define ll long long
#define N 200005
using namespace std;
ll i,j,k,m,n,o,p,l,s,t,sum1,sum2,ans,times,bz;
multiset<ll> f,g;
ll a[N],b[N];
int main()
{
   // freopen("a.in","r",stdin);
 //   freopen("a.out","w",stdout);
    scanf("%lld",&times);
    while (times--)
    {
        scanf("%lld%lld",&n,&m);
        bz=1;
        f.clear(),g.clear();
        sum1=sum2=0;
        for (i=1;i<=n;i++) scanf("%lld",&a[i]),sum1+=a[i],f.insert(a[i]);
        for (i=1;i<=m;i++) scanf("%lld",&b[i]),sum2+=b[i],g.insert(b[i]);
        if (sum1!=sum2)
        {
            puts("No");
            continue;
        }
        while ((!f.empty())||(!g.empty()))
        {
            ll x=*f.rbegin(),y=*g.rbegin();
            auto posx=f.find(x),posy=g.find(y);
            if (x==y) 
            {
                f.erase(posx),g.erase(posy);
            }
            else if (x>y)
            {
                bz=0;break;
            } else {
                g.erase(posy);
                g.insert(y/2),g.insert((y+1)/2);
            }
        }
        if (bz) puts("Yes");
        else puts("No");
    }
    return 0;
}