ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
t = int(input())



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+j-1:

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1

            print("".join([str(digit) for digit in s]))



    print("".join([str(digit) for digit in s]))

Submission (verdict: Wrong answer on test 2):
t = int(input())



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+j-1:

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1



    print("".join([str(digit) for digit in s]))
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e6 + 10;

int a[N];

void solve() {
    int n;
    cin>>n;
    map<int,int>pos;
    vector<PII>ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=pos[i];j<n;j++){
            swap(a[j],a[j+1]);
            pos[a[j]]=j;
            pos[a[j+1]]=j+1;
            ans.push_back({j,j+1});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
        for(int j=n;j>=i+1;j--){
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
            ans.push_back({j,j-1});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
    }
    // for(int i=0;i<ans.size();i++){
    //     cout<<ans[i].first<<' '<<ans[i].second<<endl;
    // }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e6 + 10;

int a[N];

void solve() {
    int n;
    cin>>n;
    map<int,int>pos;
    vector<PII>ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=pos[i];j<n;j++){
            swap(a[j],a[j+1]);
            pos[a[j]]=j;
            pos[a[j+1]]=j+1;
            ans.push_back({j,j+1});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
        for(int j=n;j>=i+1;j--){
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
            ans.push_back({j,j-1});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
    }
    // for(int i=0;i<ans.size();i++){
    //     cout<<ans[i].first<<' '<<ans[i].second<<endl;
    // }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e6 + 10;

int a[N];

void solve() {
    int n;
    cin>>n;
    map<int,int>pos;
    vector<PII>ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=pos[i];j<n;j++){
            swap(a[j],a[j+1]);
            pos[a[j]]=j;
            pos[a[j+1]]=j+1;
            ans.push_back({a[j],a[j+1]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
        for(int j=n;j>=i+1;j--){
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
            ans.push_back({a[j-1],a[j]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
    }
    // for(int i=0;i<ans.size();i++){
    //     cout<<ans[i].first<<' '<<ans[i].second<<endl;
    // }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e6 + 10;

int a[N];

void solve() {
    int n;
    cin>>n;
    map<int,int>pos;
    vector<PII>ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=pos[i];j<n;j++){
            swap(a[j],a[j+1]);
            pos[a[j]]=j;
            pos[a[j+1]]=j+1;
            ans.push_back({a[j],a[j+1]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
        for(int j=n;j>=i+1;j--){
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
            ans.push_back({a[j-1],a[j]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
    }
    // for(int i=0;i<ans.size();i++){
    //     cout<<ans[i].first<<' '<<ans[i].second<<endl;
    // }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e6 + 10;

int a[N];

void solve() {
    int n;
    cin>>n;
    map<int,int>pos;
    vector<PII>ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=pos[i];j<n;j++){
            swap(a[j],a[j+1]);
            pos[a[j]]=j;
            pos[a[j+1]]=j+1;
            ans.push_back({a[j+1],a[j]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
        for(int j=n;j>=i+1;j--){
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
            ans.push_back({a[j],a[j-1]});
            // for(int i=1;i<=n;i++){
            //     cout<<a[i]<<' ';
            // }
            // cout<<endl;
        }
    }
    // for(int i=0;i<ans.size();i++){
    //     cout<<ans[i].first<<' '<<ans[i].second<<endl;
    // }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int N=2e5+10;
int a[N];
void solve(){
    int l,r;
    cin>>l>>r;
    //cout<<(l^r)<<' '<<(bitset<6>(l^r))<<endl;
    int k= 63-__builtin_clzll(l^r);
    int a=1|((1<<k)-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<' '<<b<<' '<<c<<endl;

}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int N=2e5+10;
int a[N];
void solve(){
    int l,r;
    cin>>l>>r;
    //cout<<(l^r)<<' '<<(bitset<6>(l^r))<<endl;
    int k= 63-__builtin_clzll(l^r);
    int a=l|((1<<k)-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<' '<<b<<' '<<c<<endl;

}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int N=2e5+10;
int a[N];
void solve(){
    int l,r;
    cin>>l>>r;
    //cout<<(l^r)<<' '<<(bitset<6>(l^r))<<endl;
    int k= 63-__builtin_clzll(l^r);
    int a=1<<(k-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<' '<<b<<' '<<c<<endl;

}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int N=2e5+10;
int a[N];
void solve(){
    int l,r;
    cin>>l>>r;
    //cout<<(l^r)<<' '<<(bitset<6>(l^r))<<endl;
    int k= 63-__builtin_clzll(l^r);
    int a=1<<(k-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<' '<<b<<' '<<c<<endl;

}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int N=2e5+10;
int a[N];
void solve(){
    int l,r;
    cin>>l>>r;
    //cout<<(l^r)<<' '<<(bitset<6>(l^r))<<endl;
    int k= 63-__builtin_clzll(l^r);
    int a=1|(1<<k-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<' '<<b<<' '<<c<<endl;

}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int N=2e5+10;
int a[N];
void solve(){
    int l,r;
    cin>>l>>r;
    //cout<<(l^r)<<' '<<(bitset<6>(l^r))<<endl;
    int k= 63-__builtin_clzll(l^r);
    int a=1|(1<<k-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<' '<<b<<' '<<c<<endl;

}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int N=2e5+10;
int a[N];
void solve(){
    int l,r;
    cin>>l>>r;
    //cout<<(l^r)<<' '<<(bitset<6>(l^r))<<endl;
    int k= 63-__builtin_clzll(l^r);
    int a=1|((1<<k)-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<' '<<b<<' '<<c<<endl;

}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int>s1;
    multiset<int>s2;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        s1.insert(x);
    }
    for(int i=1;i<=m;i++){
        int x;
        cin>>x;
        s2.insert(x);
    }
    while(!s1.empty()&&!s2.empty()){
        int x=*s1.rbegin();
        int y=*s2.rbegin();
        if(x>y){
            cout<<"NO"<<endl;
            return;
        }
        if(x==y){
            s1.erase(s1.find(x));
            s2.erase(s2.find(y));
        }
        else{
            s2.erase(s2.find(y));
            s2.insert(y/2);
            s2.insert((y+1)/2);
        }
        cout<<x<<' '<<y<<endl;
    }
    if(s1.empty()&&s2.empty()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}


Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int>s1;
    multiset<int>s2;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        s1.insert(x);
    }
    for(int i=1;i<=m;i++){
        int x;
        cin>>x;
        s2.insert(x);
    }
    while(!s1.empty()&&!s2.empty()){
        int x=*s1.rbegin();
        int y=*s2.rbegin();
        if(x>y){
            cout<<"NO"<<endl;
            return;
        }
        if(x==y){
            s1.erase(s1.find(x));
            s2.erase(s2.find(y));
        }
        else{
            s2.erase(s2.find(y));
            s2.insert(y/2);
            s2.insert((y+1)/2);
        }
        //cout<<x<<' '<<y<<endl;
    }
    if(s1.empty()&&s2.empty()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int>s1;
    multiset<int>s2;
    while(!s1.empty()&&!s2.empty()){
        int x=*s1.rbegin();
        int y=*s2.rbegin();
        if(x>y){
            cout<<"NO"<<endl;
            return;
        }
        if(x==y){
            s1.erase(s1.find(x));
            s2.erase(s2.find(y));
        }
        if(x<y){
            s2.erase(s2.find(y));
            s2.insert(y/2);
            s2.insert((y+1)/2);
        }
    }
    if(s1.empty()&&s2.empty()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}


Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int>s1;
    multiset<int>s2;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        s1.insert(x);
    }
    for(int i=1;i<=m;i++){
        int x;
        cin>>x;
        s2.insert(x);
    }
    while(!s1.empty()&&!s2.empty()){
        int x=*s1.rbegin();
        int y=*s2.rbegin();
        if(x>y){
            cout<<"NO"<<endl;
            return;
        }
        if(x==y){
            s1.erase(s1.find(x));
            s2.erase(s2.find(y));
        }
        else{
            s2.erase(s2.find(y));
            s2.insert(y/2);
            s2.insert((y+1)/2);
        }
        cout<<x<<' '<<y<<endl;
    }
    if(s1.empty()&&s2.empty()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    priority_queue<int,vector<int>,greater<int>>q;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        q.push(a[i]);
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }
    sort(b+1,b+1+m);
    int temp=0;
    for(int i=1;i<=m;i++){
        
        while(q.top()<b[i]&&q.size()>=2){
            int num1=q.top();
            q.pop();
            int num2=q.top();
            q.pop();
            if(num2-num1<=1) q.push(num1+num2);
            // int num=q.top();
            // q.pop();
            // if(abs(num-temp)<=1) q.push(num+temp),temp=0;
            // else{
            //     cout<<num<<' '<<temp<<endl;
            //     cout<<"NO"<<endl;
            //     return;
            // }
        }
        //cout<<q.top()<<' '<<b[i]<<endl;
        if(q.empty()||q.top()!=b[i]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            q.pop();
        }
    }
    if(!q.empty()) cout<<"NO"<<endl;
    else
    cout<<"YES"<<endl;

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    priority_queue<int,vector<int>,greater<int>>q;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        q.push(a[i]);
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }
    sort(b+1,b+1+m);
    int temp=0;
    for(int i=1;i<=m;i++){
        
        while(q.top()<b[i]&&q.size()>=2){
            int num1=q.top();
            q.pop();
            int num2=q.top();
            q.pop();
            if(num2-num1<=1) q.push(num1+num2);
            // int num=q.top();
            // q.pop();
            // if(abs(num-temp)<=1) q.push(num+temp),temp=0;
            // else{
            //     cout<<num<<' '<<temp<<endl;
            //     cout<<"NO"<<endl;
            //     return;
            // }
        }
        //cout<<q.top()<<' '<<b[i]<<endl;
        if(q.empty()||q.top()!=b[i]){
            cout<<"NO"<<endl;
            return;
        }
        else{
            q.pop();
        }
    }
    if(!q.empty()) cout<<"NO"<<endl;
    else
    cout<<"YES"<<endl;

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int>s1;
    multiset<int>s2;
    while(!s1.empty()&&!s2.empty()){
        int x=*s1.rbegin();
        int y=*s2.rbegin();
        if(x>y){
            cout<<"NO"<<endl;
            return;
        }
        if(x==y){
            s1.erase(s1.find(x));
            s2.erase(s2.find(y));
        }
        if(x<y){
            s2.erase(s2.find(y));
            s2.insert(y/2);
            s2.insert((y+1)/2);
        }
    }
    if(s1.empty()&&s2.empty()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int>s1;
    multiset<int>s2;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        s1.insert(x);
    }
    for(int i=1;i<=m;i++){
        int x;
        cin>>x;
        s2.insert(x);
    }
    while(!s1.empty()&&!s2.empty()){
        int x=*s1.rbegin();
        int y=*s2.rbegin();
        if(x>y){
            cout<<"NO"<<endl;
            return;
        }
        if(x==y){
            s1.erase(s1.find(x));
            s2.erase(s2.find(y));
        }
        else{
            s2.erase(s2.find(y));
            s2.insert(y/2);
            s2.insert((y+1)/2);
        }
        //cout<<x<<' '<<y<<endl;
    }
    if(s1.empty()&&s2.empty()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
typedef pair<int, int> PII;
const int N = 2e5 + 10;
//PII mex[N];
int dp[N][2];
vector<int>e[N];
int a[N],b[N];
int st[N];
const int mod = 998244353;
void solve() {
    int n,m;
    cin>>n>>m;
    multiset<int>s1;
    multiset<int>s2;
    int sum=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        sum+=x;
        s1.insert(x);
    }
    for(int i=1;i<=m;i++){
        int x;
        cin>>x;
        sum-=x;
        s2.insert(x);
    }
    if(sum) {
        cout<<"NO"<<endl;
        return;
    }
    while(!s1.empty()&&!s2.empty()){
        int x=*s1.rbegin();
        int y=*s2.rbegin();
        if(x>y){
            cout<<"NO"<<endl;
            return;
        }
        if(x==y){
            s1.erase(s1.find(x));
            s2.erase(s2.find(y));
        }
        else{
            s2.erase(s2.find(y));
            s2.insert(y/2);
            s2.insert((y+1)/2);
        }
        //cout<<x<<' '<<y<<endl;
    }
    if(s1.empty()&&s2.empty()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}