Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
      
      int n,m;
      cin>>n>>m;
      vector<int> a(n), b(m);
      for(auto &x:a)cin>>x;
      for(auto &x:b)cin>>x;
      multiset<int> s1,s2;
      priority_queue<int> pq;
      for(auto &x:a)s1.insert(x);
      for(auto &x:b)pq.push(x);
      s2=s1;
      sort(b.rbegin(),b.rend());
      int sum1 = accumulate(a.begin(),a.end(),0);
      int sum2 = accumulate(b.begin(),b.end(),0);
      // cout<<sum1<<" "<<sum2<<endl;
      if(sum1!=sum2){
            // cout<<"lu"<<endl;
            cout<<"No"<<endl;
            return;
      }
      int cnt=0;
      multiset<int> s3;
      while(!pq.empty()){
            if(cnt==n-m+1)break;
            if(s1.empty())break;
            int tp = pq.top();
            // cout<<tp<<endl;
            pq.pop();
            auto it = s1.find(tp);
            if(it!=s1.end()){
                  s1.erase(s1.find(tp));
                  s3.insert(tp);
                  // s2.erase(s2.find(tp));
                  // for(auto &x:s1)cout<<x<<" ";
                  // cout<<endl;
                  continue;
            }
            int f1 = floor(tp/2.0);
            int f2 = tp-f1;
            if(s1.find(f1)==s1.end()||s1.find(f2)==s1.end()){
                  pq.push(f1);
                  pq.push(f2);
                  cnt++;
                  // cout<<cnt<<endl;
                  continue;
            }
            s1.erase(s1.find(f1));
            s1.erase(s1.find(f2));
            s3.insert(f1);
            s3.insert(f2);
      }
      // while(!pq.empty()){
      //       cout<<pq.top()<<endl;
      //       s3.insert(pq.top());
      //       pq.pop();
      // }
      // for(auto &x:s3)cout<<x<<" ";
      // cout<<endl;
      if(s2==s3)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      
      
}

int32_t main() {
      ios::sync_with_stdio(false);
      cin.tie(nullptr);

      int t;
      cin >> t;

      while (t--) {
            solve();
      }

      return 0;
}

Submission (verdict: Time limit exceeded on test 15):
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
      
      int n,m;
      cin>>n>>m;
      vector<int> a(n), b(m);
      for(auto &x:a)cin>>x;
      for(auto &x:b)cin>>x;
      multiset<int> s1,s2;
      priority_queue<int> pq;
      for(auto &x:a)s1.insert(x);
      for(auto &x:b)pq.push(x);
      s2=s1;
      sort(b.rbegin(),b.rend());
      int sum1 = accumulate(a.begin(),a.end(),0);
      int sum2 = accumulate(b.begin(),b.end(),0);
      // cout<<sum1<<" "<<sum2<<endl;
      if(sum1!=sum2){
            // cout<<"lu"<<endl;
            cout<<"No"<<endl;
            return;
      }
      int cnt=0;
      multiset<int> s3;
      while(!pq.empty()){
            if(cnt==n-m+1)break;
            if(s1.empty())break;
            int tp = pq.top();
            // cout<<tp<<endl;
            pq.pop();
            auto it = s1.find(tp);
            if(it!=s1.end()){
                  s1.erase(s1.find(tp));
                  s3.insert(tp);
                  // s2.erase(s2.find(tp));
                  // for(auto &x:s1)cout<<x<<" ";
                  // cout<<endl;
                  continue;
            }
            int f1 = floor(tp/2.0);
            int f2 = tp-f1;
            if(s1.find(f1)==s1.end()||s1.find(f2)==s1.end()){
                  pq.push(f1);
                  pq.push(f2);
                  cnt++;
                  // cout<<cnt<<endl;
                  continue;
            }
            if (f1 == f2) {
                  if (s1.count(f1) < 2) {
                        pq.push(f1);
                        pq.push(f2);
                        cnt++;
                        continue;
                  }
                  auto it = s1.find(f1);
                  s1.erase(it);
                  it = s1.find(f1);
                  s1.erase(it);
                  s3.insert(f1);
                  s3.insert(f1);
            } 
            else{
                  s1.erase(s1.find(f1));
                  s1.erase(s1.find(f2));
                  s3.insert(f1);
                  s3.insert(f2);
            }
      }
      // while(!pq.empty()){
      //       cout<<pq.top()<<endl;
      //       s3.insert(pq.top());
      //       pq.pop();
      // }
      // for(auto &x:s3)cout<<x<<" ";
      // cout<<endl;
      if(s2==s3)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      
      
}

int32_t main() {
      ios::sync_with_stdio(false);
      cin.tie(nullptr);

      int t;
      cin >> t;

      while (t--) {
            solve();
      }

      return 0;
}