ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
#define mod 1000000007 
#define loop(i, n) for(int i = 0; i < n; i++)
#define rloop(i, n) for(int i = n-1; i >= 0; i--)
#define range(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define full(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sqr(x) ((x) * (x))
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long
#define vfill(v, n) fill(all(v), n)
#define floor_div(a, b) std::floor(static_cast<double>(a) / (b))
#define ceil_div(a, b) std::ceil(static_cast<double>(a) / (b))

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n,k,a,res=0;
    cin >> n >> k;
    unordered_map<int,int> mep;
    loop(i,n){
        cin >> a;
        mep[a]++;
    }
    vi v;
    for(auto it:mep){
        v.push_back(it.second);
    }
    sort(v.begin(),v.end());
    loop(i,v.size()){
        if(v[i]<=k) k-=v[i];
        else    res++;
    }
    if(!res)    res++;
    cout << res << endl;
}
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#define mod 1000000007 
#define loop(i, n) for(int i = 0; i < n; i++)
#define rloop(i, n) for(int i = n-1; i >= 0; i--)
#define range(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define full(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sqr(x) ((x) * (x))
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long
#define vfill(v, n) fill(all(v), n)
#define floor_div(a, b) std::floor(static_cast<double>(a) / (b))
#define ceil_div(a, b) std::ceil(static_cast<double>(a) / (b))

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n,k,a,res=0;
    cin >> n >> k;
    unordered_map<int,int> mep;
    loop(i,n){
        cin >> a;
        mep[a]++;
    }
    vi v;
    for(auto it:mep){
        v.push_back(it.second);
    }
    sort(v.begin(),v.end());
    loop(i,v.size()){
        if(v[i]<=k) k-=v[i];
        else    res++;
    }
    if(!res)    res++;
    cout << res << endl;
}
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
#define mod 1000000007 
#define loop(i, n) for(int i = 0; i < n; i++)
#define rloop(i, n) for(int i = n-1; i >= 0; i--)
#define range(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define full(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sqr(x) ((x) * (x))
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long
#define vfill(v, n) fill(all(v), n)
#define floor_div(a, b) std::floor(static_cast<double>(a) / (b))
#define ceil_div(a, b) std::ceil(static_cast<double>(a) / (b))

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n,k,a;
    cin >> n >> k;
    unordered_map<int,int> mep;
    loop(i,n){
        cin >> a;
        mep[a]++;
    }
    vi v;
    for(auto it:mep){
        v.push_back(it.second);
    }
    int m=v.size();
    sort(v.begin(),v.end());
    loop(i,m){
        if(v[i]<=k) k-=v[i];
        else{
            cout << m-i << endl;
            return;
        }
    }
    cout << 1 << endl;
}
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#define mod 1000000007 
#define loop(i, n) for(int i = 0; i < n; i++)
#define rloop(i, n) for(int i = n-1; i >= 0; i--)
#define range(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define full(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sqr(x) ((x) * (x))
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long
#define vfill(v, n) fill(all(v), n)
#define floor_div(a, b) std::floor(static_cast<double>(a) / (b))
#define ceil_div(a, b) std::ceil(static_cast<double>(a) / (b))

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n,k,a;
    cin >> n >> k;
    unordered_map<int,int> mep;
    loop(i,n){
        cin >> a;
        mep[a]++;
    }
    vi v;
    for(auto it:mep){
        v.push_back(it.second);
    }
    int m=v.size();
    sort(v.begin(),v.end());
    loop(i,m){
        if(v[i]<=k) k-=v[i];
        else{
            cout << m-i << endl;
            return;
        }
    }
    cout << 1 << endl;
}
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    return 0;
}

Submission (verdict: Accepted):
#define mod 1000000007 
#define loop(i, n) for(int i = 0; i < n; i++)
#define rloop(i, n) for(int i = n-1; i >= 0; i--)
#define range(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define full(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sqr(x) ((x) * (x))
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long
#define vfill(v, n) fill(all(v), n)
#define floor_div(a, b) std::floor(static_cast<double>(a) / (b))
#define ceil_div(a, b) std::ceil(static_cast<double>(a) / (b))

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n,k;
    cin >> n >> k;

    vi a(n);
    loop(i,n){
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    vector<int> v = {1};
    range(i,1,n-1) {
        if (a[i] == a[i - 1])   v.back()++;
        else    v.emplace_back(1);
    }

    sort(v.begin(),v.end());
    int m=v.size();

    loop(i,m){
        if(v[i]<=k) k-=v[i];
        else{
            cout << m-i << endl;
            return;
        }
    }
    cout << 1 << endl;
}
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    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 maxn 500005
#define int long long

void solve(){
    int n;cin>>n;
    vector<int>a(n+2),b(n+2);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=i;
    }
    set<array<int,2> >st;
    vector<array<int,2> >vt;
    for(int i=n;i>=1;i--){
        for(int j=1;j<=n;j++){
            if(b[j]==a[i]){
                for(int k=j+1;k<=i;k++){
                    st.insert({b[k],b[k-1]});
                    vt.push_back({b[k],b[k-1]});
                    swap(b[k],b[k-1]);
                }
                break;
            }
        }
    }
    for(int i=1;i<n;i++){
        if(!st.count({a[i],a[i+1]})&&!st.count({a[i+1],a[i]})){
            st.insert({a[i],a[i+1]});
            st.insert({a[i+1],a[i]});
            vt.push_back({a[i],a[i+1]});
            vt.push_back({a[i+1],a[i]});
        }
    }
    cout<<st.size()<<'\n';
    for(auto [x,y]:vt){
        cout<<x<<' '<<y<<'\n';
    }
}

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 4):
#include <bits/stdc++.h>
using namespace std;
#define maxn 500005
#define int long long

void solve(){
    int n;cin>>n;
    vector<int>a(n+2),b(n+2);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=i;
    }
    set<array<int,2> >st;
    vector<array<int,2> >vt;
    for(int i=n;i>=1;i--){
        for(int j=1;j<=n;j++){
            if(b[j]==a[i]){
                for(int k=j+1;k<=i;k++){
                    st.insert({b[k],b[k-1]});
                    vt.push_back({b[k],b[k-1]});
                    swap(b[k],b[k-1]);
                }
                break;
            }
        }
    }
    for(int i=1;i<n;i++){
        if(!st.count({a[i],a[i+1]})&&!st.count({a[i+1],a[i]})){
            st.insert({a[i],a[i+1]});
            st.insert({a[i+1],a[i]});
            vt.push_back({a[i+1],a[i]});
            vt.push_back({a[i],a[i+1]});
        }
    }
    cout<<st.size()<<'\n';
    for(auto [x,y]:vt){
        cout<<x<<' '<<y<<'\n';
    }
}

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 4):
#include <bits/stdc++.h>
using namespace std;
#define maxn 500005
#define int long long

void solve(){
    int n;cin>>n;
    vector<int>a(n+2),b(n+2);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=i;
    }
    set<array<int,2> >st;
    vector<array<int,2> >vt;
    for(int i=n;i>=1;i--){
        for(int j=1;j<=n;j++){
            if(b[j]==a[i]){
                for(int k=j+1;k<=i;k++){
                    st.insert({b[k],b[k-1]});
                    vt.push_back({b[k],b[k-1]});
                    swap(b[k],b[k-1]);
                }
                break;
            }
        }
    }
    for(int i=1;i<n;i++){
        if(!st.count({a[i],a[i+1]})&&!st.count({a[i+1],a[i]})){
            st.insert({a[i],a[i+1]});
            st.insert({a[i+1],a[i]});
            vt.push_back({a[i+1],a[i]});
            vt.push_back({a[i],a[i+1]});
        }
    }
    cout<<st.size()<<'\n';
    for(auto [x,y]:vt){
        cout<<x<<' '<<y<<'\n';
    }
}

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 maxn 500005
#define int long long

void solve(){
    int n;cin>>n;
    vector<int>a(n+2),b(n+2);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=i;
    }

    vector<array<int,2> >vt;
    for(int i=n;i>=1;i--){
        for(int j=1;j<=n;j++){
            if(b[j]==a[i]){
                for(int k=j;k>=2;k--){
                    vt.push_back({b[k],b[k-1]});
                    swap(b[k],b[k-1]);
                    // cout<<"pb:"<<b[j]<<' '<<b[k]<<'\n';
                }
                for(int k=2;k<=j;k++){
                    vt.push_back({b[k],b[k-1]});
                    swap(b[k],b[k-1]);
                    // cout<<"pb:"<<b[k]<<' '<<b[j]<<'\n';
                }
                for(int k=j+1;k<=i;k++){
                    vt.push_back({b[k],b[k-1]});
                    // cout<<"pb2:"<<b[k]<<' '<<b[k-1]<<'\n';
                    swap(b[k],b[k-1]);
                }
                break;
            }
        }
    }
    
    cout<<vt.size()<<'\n';
    for(auto [x,y]:vt){
        cout<<x<<' '<<y<<'\n';
    }
}

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)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define maxn 500005
#define int long long

void solve(){
    int n;cin>>n;
    vector<int>a(n+2),b(n+2);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=i;
    }
    set<array<int,2> >st;
    vector<array<int,2> >vt;
    for(int i=n;i>=1;i--){
        for(int j=1;j<=n;j++){
            if(b[j]==a[i]){
                for(int k=j+1;k<=i;k++){
                    st.insert({b[k],b[k-1]});
                    vt.push_back({b[k],b[k-1]});
                    swap(b[k],b[k-1]);
                }
                break;
            }
        }
    }
    for(int i=1;i<n;i++){
        if(!st.count({a[i],a[i+1]})&&!st.count({a[i+1],a[i]})){
            st.insert({a[i],a[i+1]});
            st.insert({a[i+1],a[i]});
            vt.push_back({a[i],a[i+1]});
            vt.push_back({a[i+1],a[i]});
        }
    }
    cout<<st.size()<<'\n';
    for(auto [x,y]:vt){
        cout<<x<<' '<<y<<'\n';
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, 99));

    dp[0][0] = 0;
    // for(int i=0, j=0; i<n ; i++){
    //     if(j<m && b[j]==c[i])
    //         j++;
    //     dp[0][i+1] = i-j+1;
    // }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            if(j<=i+m){
                val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            }
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, 99));

    dp[0][0] = 0;
    // for(int i=0, j=0; i<n ; i++){
    //     if(j<m && b[j]==c[i])
    //         j++;
    //     dp[0][i+1] = i-j+1;
    // }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            if(j<=i+m){
                val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            }
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

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

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, 99));

    dp[0][0] = 0;
    for(int i=0, j=0; i<n ; i++){
        if(j<m && b[j]==c[i])
            j++;
        dp[0][i+1] = i-j+1;
    }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            if(j<=i+m){
                val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            }
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, 99));

    dp[0][0] = 0;
    for(int i=0, j=0; i<n ; i++){
        if(j<m && b[j]==c[i])
            j++;
        dp[0][i+1] = i-j+1;
    }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            if(j<=i+m){
                val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            }
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

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

Submission (verdict: Wrong answer on test 17):
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, 99));

    dp[0][0] = 0;
    for(int i=1, j=0; i<=n ; i++){
        if(i<=m && b[i-1]!=c[i-1])
            j++;
        dp[0][i] = j;
    }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

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

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, 99));

    dp[0][0] = 0;
    for(int i=1, j=0; i<=n ; i++){
        if(i<=m && b[i-1]!=c[i-1])
            j++;
        dp[0][i] = j;
    }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

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

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

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, INT_MAX));

    dp[0][0] = 0;
    for(int i=1, j=0; i<=n ; i++){
        if(i<=m && b[i-1]!=c[i-1])
            j++;
        dp[0][i] = j;
    }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include "bits/stdc++.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;

#define fst first
#define snd second
#define pb push_back
#define len(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fore(i,a,b) for(auto i=a;i<b;i++)
#define forn(i, n) fore(i, 0, n)
#define dfor(i, n) for(auto i=n;i-->0;)
#define dbg(x) cerr << "LINE" $ __LINE__ <<":" $ #x << "=" << x << endl;
#define raya cerr << "\n-----------------------------------------------------------\n"
#define $ <<" "<<

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T,U> &p){
    os << '(' << p.first $ p.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
    os << "[";
    forn(i, len(v)){
        if(i) os << ", ";
        os << v[i];
    }
    os << "]";
    return os;
}

typedef long long ll;

void solve(){
    int n, m;
    cin>>n>>m;
    vector<int> a(n), b(m);
    forn(i,n) cin>>a[i];
    forn(i,m) cin>>b[i];
    sort(all(b));
    priority_queue<int,vector<int>,greater<int>> pq;
    forn(i,n) pq.push(a[i]);
    int j=0;
    vector<int> c;
    while(len(pq) > 1 && j < m){
        int x = pq.top();
        pq.pop();
        if(x == b[j]){
            c.pb(x);
            j++;
        }
        else{
            int y = pq.top();
            pq.pop();
            if(y - x > 1){
                cout<<"NO\n";
                return;
            }
            pq.push(x+y);
        }
    }
    while(len(pq)){
        c.pb(pq.top());
        pq.pop();
    }
    if(c == b) cout << "YES\n";
    else cout << "NO\n";
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tt;
    cin>>tt;
    while(tt--) solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
 
bool Order(const string& s) {
    int n = s.size();
    for (int i = 1; i < n; ++i) {
        if (s[i] > s[i - 1]) {  
            return false;
        }
    }
    return true; 
}
 
int main() {
    int t; 
    cin >> t;
    while(t--) {
        string s; 
        cin >> s;
        int n = s.size();
        
        // while(!Order(s)){
        //     int c = 0;
        //     for(int i = n - 1; i >= 1; i--) {
        //         if(s[i] > s[i - 1] + 1) {
        //             swap(s[i], s[i - 1]);
                    
        //             s[i - 1] -= 1;
        //             c = 1;
        //         }
        //     }
        //     if(!c) {
        //         break;
        //     }
        // }
        
        for(int j = 0; j < 9; j++){
            int c = 0;
            for(int i = n - 1; i >= 1; i--) {
                if(s[i] > s[i - 1] + 1) {
                    swap(s[i], s[i - 1]);
                    
                    s[i - 1] -= 1;
                    c = 1;
                }
            }
            if(!c) {
                break;
            }
        }
        
        cout << s << endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
 
bool Order(const string& s) {
    int n = s.size();
    for (int i = 1; i < n; ++i) {
        if (s[i] > s[i - 1]) {  
            return false;
        }
    }
    return true; 
}
 
int main() {
    int t; 
    cin >> t;
    while(t--) {
        string s; 
        cin >> s;
        int n = s.size();
        
        // while(!Order(s)){
        //     int c = 0;
        //     for(int i = n - 1; i >= 1; i--) {
        //         if(s[i] > s[i - 1] + 1) {
        //             swap(s[i], s[i - 1]);
                    
        //             s[i - 1] -= 1;
        //             c = 1;
        //         }
        //     }
        //     if(!c) {
        //         break;
        //     }
        // }
        
        for(int j = 0; j < 10; j++){
            int c = 0;
            for(int i = n - 1; i >= 1; i--) {
                if(s[i] > s[i - 1] + 1) {
                    swap(s[i], s[i - 1]);
                    
                    s[i - 1] -= 1;
                    c = 1;
                }
            }
            if(!c) {
                break;
            }
        }
        
        cout << s << endl;
    }
    return 0;
}