ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector<int> a(n);
        int ans=0;
        for(int i=0; i<n; i++){
            cin >> a[i];
            ans+= a[i];
        }
        int s=a.size();
        while(s>1){
            ans = max(ans, abs(a[s-1] - a[0]));
            for(int i=0; i<s-1; i++){
                a[i] = a[i+1] - a[i];
            }
            a.pop_back();
            s-=1;
        }
        cout << ans << "\n";
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

// #include <unordered_map> // NEVER USE THOSE IN CP
// #include <unordered_set> // NEVER USE THOSE IN CP

#define int long long  // Because i'm so done with integer overflow mistakes

using namespace std;

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

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        set<int> adj[n];
        for (int i = 0; i < n - 1; i++) {
            int u, v;
            cin >> u >> v;
            u--;
            v--;
            adj[u].insert(v);
            adj[v].insert(u);
        }
        map<int, vector<int>, greater<int>> largests;
        for (int i = 0; i < n; i++) {
            largests[adj[i].size()].push_back(i);
        }
        int ans = largests.begin()->first;  // we always greedily take the first largest node

        vector<int> firsts;
        vector<int> seconds;
        if (largests.begin()->second.size() == 1) {  // get the second largest
            auto p = largests.begin();
            firsts.push_back(p->second[0]);
            p++;  // second largest size
            seconds = p->second;
        } else {
            // 2 values is enough
            firsts.push_back(largests.begin()->second[0]);
            firsts.push_back(largests.begin()->second[1]);
            seconds = largests.begin()->second;
        }
        int second_size = 0;

        for (auto first : firsts) {
            for (auto second : seconds) {
                if (first == second) {
                    continue;
                }
                if (adj[first].count(second)) {
                    second_size = adj[second].size() - 2;
                } else {
                    second_size = adj[second].size() - 1;
                    break;
                }
            }
        }
        ans += second_size;

        cout << ans << endl;
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <vector>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
using ll = long long;


std::vector<std::vector<int>> graph;
std::vector<int> degree;
std::vector<bool> visited;

void dfs(int node, int a, int b)
{
    visited[node] = true;
    for (int neighbor : graph[node])
    {
        if (neighbor == a || neighbor == b) continue;
        if (!visited[neighbor]) dfs(neighbor, a, b);
    }
}

void solve()
{
    int n, u, v;
    std::cin >> n;

    graph.clear();
    degree.clear();
    visited.clear();
    graph.resize(n+1);
    degree.resize(n+1);
    visited.resize(n+1, false);

    for (int i = 0; i < n-1; i++)
    {
        std::cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    // get the two nodes with the largest degree value
    // remove those nodes. use dfs to find how many separated graphs are left.

    int a = 0, b = 0, temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp) {a = i; temp = degree[i];}
    temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp && i != a) {b = i; temp = degree[i];}

    int components = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i == a || i == b) continue;
        if (!visited[i]) {components++; dfs(i, a, b);}
    }

    std::cout << components << '\n';
}

int main()
{
    inout;
    int t;
    std::cin >> t;

    while (t--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <vector>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
using ll = long long;


std::vector<std::vector<int>> graph;
std::vector<int> degree;
std::vector<bool> visited;

void dfs(int node, int a, int b)
{
    visited[node] = true;
    for (int neighbor : graph[node])
    {
        if (neighbor == a || neighbor == b) continue;
        if (!visited[neighbor]) dfs(neighbor, a, b);
    }
}

void solve()
{
    int n, u, v;
    std::cin >> n;

    graph.clear();
    degree.clear();
    visited.clear();
    graph.resize(n+1);
    degree.resize(n+1);
    visited.resize(n+1, false);

    for (int i = 0; i < n-1; i++)
    {
        std::cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    // get the two nodes with the largest degree value
    // remove those nodes. use dfs to find how many separated graphs are left.

    int a = 0, b = 0, temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp) {a = i; temp = degree[i];}
    temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp && i != a) {b = i; temp = degree[i];}

    int components = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i == a || i == b) continue;
        if (!visited[i]) {components++; dfs(i, a, b);}
    }

    std::cout << components << '\n';
}

int main()
{
    inout;
    int t;
    std::cin >> t;

    while (t--) solve();
}



Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
using ll = long long;

std::vector<std::vector<int>> graph;
std::vector<int> degree;
std::vector<bool> visited;

void solve()
{
    int n, u, v;
    std::cin >> n;

    graph.clear();
    degree.clear();
    visited.clear();
    graph.resize(n + 1);
    degree.resize(n + 1, 0);
    visited.resize(n + 1, false);

    for (int i = 0; i < n - 1; i++)
    {
        std::cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    // get the two nodes with the largest degree value
    // remove those nodes. use dfs to find how many separated graphs are left.
    // _from the future_ it's not really correct but very close.

    int a = 0, b = 0, temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp) { a = i; temp = degree[i];}
    temp = 0;
    for (int i = 1; i <= n; i++) if (i != a && degree[i] > temp) {b = i; temp = degree[i];} 

    bool adjacent = false;
    for (int nb : graph[a]) if (nb == b) {adjacent = true;break;}
    
    int components = degree[a] + degree[b] - (adjacent ? 2 : 1);
    std::cout << components << '\n';
}

int main()
{
    inout;
    int t;
    std::cin >> t;
    while (t--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
using ll = long long;

std::vector<std::vector<int>> graph;
std::vector<int> degree;
std::vector<bool> visited;

void solve()
{
    int n, u, v;
    std::cin >> n;

    graph.clear();
    degree.clear();
    visited.clear();
    graph.resize(n + 1);
    degree.resize(n + 1, 0);
    visited.resize(n + 1, false);

    for (int i = 0; i < n - 1; i++)
    {
        std::cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    // get the two nodes with the largest degree value
    // remove those nodes. use dfs to find how many separated graphs are left.
    // _from the future_ it's not really correct but very close.

    int a = 0, b = 0, temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp) { a = i; temp = degree[i];}
    temp = 0;
    for (int i = 1; i <= n; i++) if (i != a && degree[i] > temp) {b = i; temp = degree[i];} 

    bool adjacent = false;
    for (int nb : graph[a]) if (nb == b) {adjacent = true;break;}
    
    int components = degree[a] + degree[b] - (adjacent ? 2 : 1);
    std::cout << components << '\n';
}

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



Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
using ll = long long;

std::vector<std::vector<int>> graph;
std::vector<int> degree;
std::vector<bool> visited;

void solve()
{
    int n, u, v;
    std::cin >> n;

    graph.clear();
    degree.clear();
    visited.clear();
    graph.resize(n + 1);
    degree.resize(n + 1, 0);
    visited.resize(n + 1, false);

    for (int i = 0; i < n - 1; i++)
    {
        std::cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    // get the two nodes with the largest degree value
    // remove those nodes. use dfs to find how many separated graphs are left.
    // _from the future_ it's not really correct but very close.

    int a = 0, b = -1, temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp) { a = i; temp = degree[i];}
    temp = 0;

    for (int nb : graph[a]) visited[nb] = true;
    for (int i = 1; i <= n; i++)
    {
        if (i == a) continue;
        int candidate = degree[a] + degree[i] - (visited[i] ? 2 : 1);
        if (candidate > b) b = candidate;
    }

    std::cout << b << '\n';
}

int main()
{
    inout;
    int t;
    std::cin >> t;
    while (t--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
using ll = long long;

std::vector<std::vector<int>> graph;
std::vector<int> degree;
std::vector<bool> visited;

void solve()
{
    int n, u, v;
    std::cin >> n;

    graph.clear();
    degree.clear();
    visited.clear();
    graph.resize(n + 1);
    degree.resize(n + 1, 0);
    visited.resize(n + 1, false);

    for (int i = 0; i < n - 1; i++)
    {
        std::cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    // get the two nodes with the largest degree value
    // remove those nodes. use dfs to find how many separated graphs are left.
    // _from the future_ it's not really correct but very close.

    int a = 0, b = -1, temp = 0;
    for (int i = 1; i <= n; i++) if (degree[i] > temp) { a = i; temp = degree[i];}
    temp = 0;

    for (int nb : graph[a]) visited[nb] = true;
    for (int i = 1; i <= n; i++)
    {
        if (i == a) continue;
        int candidate = degree[a] + degree[i] - (visited[i] ? 2 : 1);
        if (candidate > b) b = candidate;
    }

    std::cout << b << '\n';
}

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



Submission (verdict: Accepted):
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
using ll = long long;

std::vector<std::vector<int>> graph;
std::vector<int> degree;
std::vector<bool> visited;

void solve()
{
    int n, u, v;
    std::cin >> n;

    graph.clear();
    degree.clear();
    visited.clear();
    graph.resize(n + 1);
    degree.resize(n + 1, 0);
    visited.resize(n + 1, false);

    for (int i = 0; i < n - 1; i++)
    {
        std::cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    // get the two nodes with the largest degree value
    // remove those nodes. use dfs to find how many separated graphs are left.
    // _from the future_ it's not really correct but very close.
    // _future future_ tirili minda
    // :sob:

    std::multiset<int> set;
    for (int i = 1; i <= n; i++) 
    {
        set.insert(graph[i].size());
        set.insert(graph[i].size()-1);
    }

    int answer = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int neighbor : graph[i]) set.erase(set.find(graph[neighbor].size()));
        set.erase(set.find(graph[i].size()));
        set.erase(set.find(graph[i].size()-1));

        answer = std::max(answer, (int)graph[i].size() + *set.rbegin()-1);
        for (int neighbor : graph[i]) set.insert(graph[neighbor].size());
        set.insert(graph[i].size());
        set.insert(graph[i].size()-1);
    }

    std::cout << answer << '\n';
}

int main()
{
    inout;
    int t;
    std::cin >> t;
    while (t--) solve();
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
typedef long long ll;
typedef pair<ll,ll>PII;

void solve()
{
	ll l,r;
	cin>>l>>r;
	ll nl,nr;
	ll a,b,c;
	for(int i=32;i>=0;i--)
	{
		if((r&(1ll<<i))&&!(l&(1ll<<i))) 
		{
			nl=((1ll<<(i+1))-1)&l;
			nr=((1ll<<(i+1))-1)&r;
			l-=nl;
			r-=nr;
			a=r+(1ll<<i);
			b=r+(1ll<<i)-1;
			c=r;
			break;
		}
	}
	cout<<a<<' '<<b<<' '<<c<<endl;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	int t=1;
	cin>>t;
	while(t--)
		solve(); 
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
typedef long long ll;
typedef pair<ll,ll>PII;

void solve()
{
	ll l,r;
	cin>>l>>r;
	
	ll nl,nr;
	ll a,b,c;
	for(int i=32;i>=1;i--)
	{
		if((r&(1ll<<i))&&!(l&(1ll<<i))) 
		{
			if(i!=1)
			{
				nr=((1ll<<(i+1))-1)&r;
				r-=nr;
				a=r+(1ll<<i);
				b=r+(1ll<<i)-1;
				c=l;
				break;
			}
			else
			{
				a=r,b=r-1,c=r-2;
				break;
			}
		}
	}
	cout<<a<<' '<<b<<' '<<c<<endl;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	int t=1;
	cin>>t;
	while(t--)
		solve(); 
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
typedef long long ll;
typedef pair<ll,ll>PII;

void solve()
{
	ll l,r;
	cin>>l>>r;
	
	ll nl,nr;
	ll a,b,c;
	for(int i=32;i>=1;i--)
	{
		if((r&(1ll<<i))&&!(l&(1ll<<i))) 
		{
			if(i!=1)
			{
				nr=((1ll<<(i+1))-1)&r;
				r-=nr;
				a=r+(1ll<<i);
				b=r+(1ll<<i)-1;
				c=l;
				break;
			}
			else
			{
				a=r,b=l,c=l+1;
				break;
			}
		}
	}
	cout<<a<<' '<<b<<' '<<c<<endl;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	int t=1;
	cin>>t;
	while(t--)
		solve(); 
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
typedef long long ll;
typedef pair<ll,ll>PII;

void solve()
{
	ll l,r;
	cin>>l>>r;
	ll nl,nr;
	ll a,b,c;
	for(int i=32;i>=0;i--)
	{
		if((r&(1ll<<i))&&!(l&(1ll<<i))) 
		{
			nl=((1ll<<(i+1))-1)&l;
			nr=((1ll<<(i+1))-1)&r;
			l-=nl;
			r-=nr;
			a=r+(1ll<<i);
			b=r+(1ll<<i)-1;
			c=r;
			break;
		}
	}
	cout<<a<<' '<<b<<' '<<c<<endl;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	int t=1;
	cin>>t;
	while(t--)
		solve(); 
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
typedef long long ll;
typedef pair<ll,ll>PII;

void solve()
{
	ll l,r;
	cin>>l>>r;
	
	ll nl,nr;
	ll a,b,c;
	for(int i=32;i>=1;i--)
	{
		if((r&(1ll<<i))&&!(l&(1ll<<i))) 
		{
			if(i!=1)
			{
				nr=((1ll<<(i+1))-1)&r;
				r-=nr;
				a=r+(1ll<<i);
				b=r+(1ll<<i)-1;
				c=l;
				break;
			}
			else
			{
				a=r,b=r-1,c=r-2;
				break;
			}
		}
	}
	cout<<a<<' '<<b<<' '<<c<<endl;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	int t=1;
	cin>>t;
	while(t--)
		solve(); 
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
typedef long long ll;
typedef pair<ll,ll>PII;

void solve()
{
	ll l,r;
	cin>>l>>r;
	
	ll nl,nr;
	ll a,b,c;
	for(int i=32;i>=1;i--)
	{
		if((r&(1ll<<i))&&!(l&(1ll<<i))) 
		{
			if(i!=1)
			{
				nr=((1ll<<(i+1))-1)&r;
				r-=nr;
				a=r+(1ll<<i);
				b=r+(1ll<<i)-1;
				c=l;
				break;
			}
			else
			{
				a=r,b=l,c=l+1;
				break;
			}
		}
	}
	cout<<a<<' '<<b<<' '<<c<<endl;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	int t=1;
	cin>>t;
	while(t--)
		solve(); 
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
typedef long long ll;
typedef pair<ll,ll>PII;

void solve()
{
	ll l,r;
	cin>>l>>r;
	ll nr;
	ll a,b,c;
	for(int i=32;i>=1;i--)
	{
		if((r&(1ll<<i))&&!(l&(1ll<<i))) 
		{
			if(i!=1)
			{
				nr=((1ll<<(i+1))-1)&r;
				r-=nr;
				a=r+(1ll<<i);
				b=r+(1ll<<i)-1;
				while(l==b||l==a) l++;
				c=l;
				break;
			}
			else
			{
				a=r,b=l,c=l+1;
				break;
			}
		}
	}
	cout<<a<<' '<<b<<' '<<c<<endl;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	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<iostream>

#include<vector>

#include<unordered_set>

#include<unordered_map>

#include<algorithm>

#include<cmath>

#include<set>

#include<map>

#include<iomanip>

#include<string>

#include<numeric>

#include<queue>

#include<stdlib.h>

#include<cstring>

#include<climits>

using namespace std;

long long x;

void solve()

{

	long long n, m; cin >> n >> m;

	multiset<long long>st1;

	multiset<long long>st2;

	for (long long i = 1; i <= n; i++)cin >> x, st1.insert(x);

	for (long long i = 1; i <= m; i++)cin >> x, st2.insert(x);

	auto pos1 = st1.begin();

	auto pos2 = st2.begin();

	long long is = 1;

	while (pos1 != st1.end() && pos2 != st2.end())

	{

		if ((*pos1) == (*pos2))

		{

			pos1++;

			pos2++;

		}

		else if ((*pos1) > (*pos2))

		{

			cout << "No" << endl;

			return;

		}

		else

		{

			auto temp = pos1;

			pos1++;

			if (pos1 == st1.end() || *temp + 1 < *pos1)

			{

				cout << "NO" << endl;

				return;

			}

			st1.insert(*temp + *pos1);

			//st1.erase(temp);

			//st1.erase(pos1);

			pos1++;

		}

	}

	if (pos1 == st1.end() && pos2 == st2.end())cout << "YES" << endl;

	else cout << "NO" << endl;

}

int main()

{

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

	int tt = 1;

	cin >> tt;

	while (tt--)

	{

		solve();

	}

	return 0;

}

Submission (verdict: Wrong answer on test 3):
﻿#include<iostream>

#include<vector>

#include<unordered_set>

#include<unordered_map>

#include<algorithm>

#include<cmath>

#include<set>

#include<map>

#include<iomanip>

#include<string>

#include<numeric>

#include<queue>

#include<stdlib.h>

#include<cstring>

#include<climits>

using namespace std;

long long x;

void solve()

{

	long long n, m; cin >> n >> m;

	multiset<long long>st1;

	multiset<long long>st2;

	for (long long i = 1; i <= n; i++)cin >> x, st1.insert(x);

	for (long long i = 1; i <= m; i++)cin >> x, st2.insert(x);

	auto pos1 = st1.begin();

	auto pos2 = st2.begin();

	while (pos1 != st1.end() && pos2 != st2.end())

	{

		if ((*pos1) == (*pos2))

		{

			st1.erase(st1.begin());

			st2.erase(st2.begin());

			pos1 = st1.begin();

			pos2 = st2.begin();

		}

		else if ((*pos1) > (*pos2))

		{

			cout << "NO" << endl;

			return;

		}

		else

		{

			auto temp = pos1;

			pos1++;

			if (pos1 == st1.end() || *temp + 1 < *pos1)

			{

				cout << "NO" << endl;

				return;

			}

			st1.insert(*temp + *pos1);

			st1.erase(st1.begin());

			st1.erase(st1.begin());

			pos1 = st1.begin();

		}

	}

	if (st1.size() == 0 && st2.size() == 0)cout << "YES" << endl;

	else cout << "NO" << endl;

}

int main()

{

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

	int tt = 1;

	cin >> tt;

	while (tt--)

	{

		solve();

	}

	return 0;

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


Submission (verdict: Wrong answer on test 3):
﻿#include<iostream>

#include<vector>

#include<unordered_set>

#include<unordered_map>

#include<algorithm>

#include<cmath>

#include<set>

#include<map>

#include<iomanip>

#include<string>

#include<numeric>

#include<queue>

#include<stdlib.h>

#include<cstring>

#include<climits>

using namespace std;

long long x;

void solve()

{

	long long n, m; cin >> n >> m;

	multiset<long long>st1;

	multiset<long long>st2;

	for (long long i = 1; i <= n; i++)cin >> x, st1.insert(x);

	for (long long i = 1; i <= m; i++)cin >> x, st2.insert(x);

	auto pos1 = st1.begin();

	auto pos2 = st2.begin();

	long long is = 1;

	while (pos1 != st1.end() && pos2 != st2.end())

	{

		if ((*pos1) == (*pos2))

		{

			pos1++;

			pos2++;

		}

		else if ((*pos1) > (*pos2))

		{

			cout << "No" << endl;

			return;

		}

		else

		{

			auto temp = pos1;

			pos1++;

			if (pos1 == st1.end() || *temp + 1 < *pos1)

			{

				cout << "NO" << endl;

				return;

			}

			st1.insert(*temp + *pos1);

			//st1.erase(temp);

			//st1.erase(pos1);

			pos1++;

		}

	}

	if (pos1 == st1.end() && pos2 == st2.end())cout << "YES" << endl;

	else cout << "NO" << endl;

}

int main()

{

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

	int tt = 1;

	cin >> tt;

	while (tt--)

	{

		solve();

	}

	return 0;

}