ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

vector<vector<int>> adj; 
vector<int> degree;

void dfs(int node, int par) {
    for (auto v : adj[node]) {
        if (v != par) {
            degree[node]++;
            dfs(v,node);
        }
    }
}


signed main() {
    int t;
    cin>>t;
    while (t--)
    {
        
        int n;
        cin>>n;
        adj.clear();
        adj.resize(n + 1);
        degree.assign(n+1,1);
        
        degree[1]=0;

        for (int i = 1; i < n; i++) {
            int a,b;
            cin >> a>>b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        dfs(1, -1);

        int element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }
        //cout<<deg<<" "<<element<<endl;
        

        if(deg==n-1) {
            cout<<n-2<<endl;
            continue;
        }


        int ans=0;
        ans+=deg;
        degree[element]=0;

        for(auto v:adj[element]) degree[v]--;

        element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }

        ans+=deg-1;
        cout<<ans<<endl;



       
    }



    return 0;
}

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

vector<vector<int>> adj; 
vector<int> degree;

void dfs(int node, int par) {
    for (auto v : adj[node]) {
        if (v != par) {
            degree[node]++;
            dfs(v,node);
        }
    }
}


signed main() {
    int t;
    cin>>t;
    while (t--)
    {
        
        int n;
        cin>>n;
        adj.clear();
        adj.resize(n + 1);
        degree.assign(n+1,1);
        
        degree[1]=0;

        for (int i = 1; i < n; i++) {
            int a,b;
            cin >> a>>b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        dfs(1, -1);

        int element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }
        //cout<<deg<<" "<<element<<endl;
        

        if(deg==n-1) {
            cout<<n-2<<endl;
            continue;
        }


        int ans=0;
        ans+=deg;
        degree[element]=0;

        for(auto v:adj[element]) degree[v]--;

        element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }

        if(deg==1)  ans+=1;
        else ans+=deg-1;
        cout<<ans<<endl;



       
    }



    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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

vector<vector<int>> adj; 
vector<int> degree;

void dfs(int node, int par) {
    for (auto v : adj[node]) {
        if (v != par) {
            degree[node]++;
            dfs(v,node);
        }
    }
}


signed main() {
    int t;
    cin>>t;
    while (t--)
    {
        
        int n;
        cin>>n;
        adj.clear();
        adj.resize(n + 1);
        degree.assign(n+1,1);
        
        degree[1]=0;

        for (int i = 1; i < n; i++) {
            int a,b;
            cin >> a>>b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        dfs(1, -1);

        int element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }
        //cout<<deg<<" "<<element<<endl;
        

        if(deg==n-1) {
            cout<<n-2<<endl;
            continue;
        }


        int ans=0;
        ans+=deg;
        degree[element]=0;

        for(auto v:adj[element]) degree[v]--;

        element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }

        ans+=deg-1;
        cout<<ans<<endl;



       
    }



    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

vector<vector<int>> adj; 
vector<int> degree;

void dfs(int node, int par) {
    for (auto v : adj[node]) {
        if (v != par) {
            degree[node]++;
            dfs(v,node);
        }
    }
}


signed main() {
    int t;
    cin>>t;
    while (t--)
    {
        
        int n;
        cin>>n;
        adj.clear();
        adj.resize(n + 1);
        degree.assign(n+1,1);
        
        degree[1]=0;

        for (int i = 1; i < n; i++) {
            int a,b;
            cin >> a>>b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        dfs(1, -1);

        int element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }
        //cout<<deg<<" "<<element<<endl;
        

        if(deg==n-1) {
            cout<<n-2<<endl;
            continue;
        }


        int ans=0;
        ans+=deg;
        degree[element]=0;

        for(auto v:adj[element]) degree[v]--;

        element=0,deg=0;

        for(int i=1;i<=n;i++){
            if(degree[i]>deg) element=i,deg=degree[i];
        }

        if(deg==1)  ans+=1;
        else ans+=deg-1;
        cout<<ans<<endl;



       
    }



    return 0;
}

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

vector<vector<int>> adj; 
vector<int> degree;

// void dfs(int node, int par) {
//     for (auto v : adj[node]) {
//         if (v != par) {
//             degree[node]++;
//             dfs(v,node);
//         }
//     }
// }


signed main() {
    int t;
    cin>>t;
    while (t--)
    {
        
        int n;
        cin>>n;
        // adj.clear();
        // adj.resize(n + 1);
        degree.assign(n+1,0);
        set<pair<int,int>> s;
        

        for (int i = 1; i < n; i++) {
            int a,b;
            cin >> a>>b;
            degree[a]++;
            degree[b]++;
            // adj[a].push_back(b);
            // adj[b].push_back(a);
            s.insert({a,b});
            s.insert({b,a});
        }

        vector<pair<int,int>> arr;

        for(int i=1;i<=n;i++) arr.push_back({degree[i],i});
        sort(arr.rbegin(),arr.rend());
        int ans=0;

        for(int i=0;i<arr.size();i++){
            for(int j=i+1;j<arr.size();j++){

                if(s.find({arr[i].second,arr[j].second})==s.end()){
                    ans=max(ans,arr[i].first+arr[j].first-1);
                    break;
                }
            }
        }

        for(auto it:s){
            ans=max(ans,degree[it.first]+degree[it.second]-2);
        }
        cout<<ans<<endl;

        //dfs(1, -1);
        
       
       
    }



    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

#include <cstring>

#include <algorithm>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <unordered_map>

#include <set>

#define ff first

#define se second

#define endl '\n'

#define int long long

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int N = 2e5 + 10, INF = 0x3f3f3f3f;



signed main()

{

	cin.tie(0) -> sync_with_stdio(false);



	int T; cin >>T;

	while(T --)

	{

		int n, l, r; cin >>n >>l >>r;

		int a[n + 1];

		for(int i = 1; i <= n; i ++) cin >>a[i];



		multiset <int> s1, s2;

		for(int i = 1; i < l; i ++) s1.insert(a[i]);

		for(int i = r + 1; i <= n; i ++) s2.insert(a[i]);



		priority_queue <int> q;

		for(int i = l; i <= r; i ++) q.push(a[i]);



		int ans1 = 0, ans2 = 0;

		while(q.size())

		{

			auto t = q.top(); q.pop();

			if(s1.size())

			{

				int x = *s1.begin();

				ans1 += x;

				s1.erase(x);

			}

			else ans1 += t;

		}



		for(int i = l; i <= r; i ++) q.push(a[i]);

		while(q.size())

		{

			auto t = q.top(); q.pop();

			if(s2.size())

			{

				int x = *s2.begin();

				if(x >= t)

				{

					ans2 += t;

					continue;

				}

				ans2 += x;

				s2.erase(x);

			}

			else ans2 += t;

		}

		cout <<min(ans1, ans2) <<endl;

	}

	return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#define ff first
#define se second
#define endl '\n'
#define int long long
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

signed main()
{
	cin.tie(0) -> sync_with_stdio(false);

	int T; cin >>T;
	while(T --)
	{
		int n, l, r; cin >>n >>l >>r;
		int a[n + 1];
		for(int i = 1; i <= n; i ++) cin >>a[i];

		multiset <int> s1, s2;
		for(int i = 1; i < l; i ++) s1.insert(a[i]);
		for(int i = r + 1; i <= n; i ++) s2.insert(a[i]);

		priority_queue <int> q;
		for(int i = l; i <= r; i ++) q.push(a[i]);

		int ans1 = 0, ans2 = 0;
		while(q.size())
		{
			auto t = q.top(); q.pop();
			if(s1.size())
			{
				int x = *s1.begin();
				if(x >= t)
				{
					ans1 += t;
					continue;
				}
				ans1 += x;
				s1.erase(x);
			}
			else ans1 += t;
		}

		for(int i = l; i <= r; i ++) q.push(a[i]);
		while(q.size())
		{
			auto t = q.top(); q.pop();
			if(s2.size())
			{
				int x = *s2.begin();
				if(x >= t)
				{
					ans2 += t;
					continue;
				}
				ans2 += x;
				s2.erase(x);
			}
			else ans2 += t;
		}
		cout <<min(ans1, ans2) <<endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#define ff first
#define se second
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

signed main()
{
	cin.tie(0) -> sync_with_stdio(false);

	int T; cin >>T;
	while(T --)
	{
		int n, l, r; cin >>n >>l >>r;
		int a[n + 1];
		for(int i = 1; i <= n; i ++) cin >>a[i];

		sort(a + 1, a + 1 + n);

		ll sum = 0;
		for(int i = 1; i <= r - l + 1; i ++)
			sum += a[i];
		cout <<sum <<endl;
	}
	return 0;
}

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

#include <cstring>

#include <algorithm>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <unordered_map>

#include <set>

#define ff first

#define se second

#define endl '\n'

#define int long long

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int N = 2e5 + 10, INF = 0x3f3f3f3f;



signed main()

{

	cin.tie(0) -> sync_with_stdio(false);



	int T; cin >>T;

	while(T --)

	{

		int n, l, r; cin >>n >>l >>r;

		int a[n + 1];

		for(int i = 1; i <= n; i ++) cin >>a[i];



		multiset <int> s1, s2;

		for(int i = 1; i < l; i ++) s1.insert(a[i]);

		for(int i = r + 1; i <= n; i ++) s2.insert(a[i]);



		priority_queue <int> q;

		for(int i = l; i <= r; i ++) q.push(a[i]);



		int ans1 = 0, ans2 = 0;

		while(q.size())

		{

			auto t = q.top(); q.pop();

			if(s1.size())

			{

				int x = *s1.begin();

				ans1 += x;

				s1.erase(x);

			}

			else ans1 += t;

		}



		for(int i = l; i <= r; i ++) q.push(a[i]);

		while(q.size())

		{

			auto t = q.top(); q.pop();

			if(s2.size())

			{

				int x = *s2.begin();

				if(x >= t)

				{

					ans2 += t;

					continue;

				}

				ans2 += x;

				s2.erase(x);

			}

			else ans2 += t;

		}

		cout <<min(ans1, ans2) <<endl;

	}

	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#define ff first
#define se second
#define endl '\n'
#define int long long
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

signed main()
{
	cin.tie(0) -> sync_with_stdio(false);

	int T; cin >>T;
	while(T --)
	{
		int n, l, r; cin >>n >>l >>r;
		int a[n + 1];
		for(int i = 1; i <= n; i ++) cin >>a[i];

		multiset <int> s1, s2;
		for(int i = 1; i < l; i ++) s1.insert(a[i]);
		for(int i = r + 1; i <= n; i ++) s2.insert(a[i]);

		priority_queue <int> q;
		for(int i = l; i <= r; i ++) q.push(a[i]);

		int ans1 = 0, ans2 = 0;
		while(q.size())
		{
			auto t = q.top(); q.pop();
			if(s1.size())
			{
				int x = *s1.begin();
				if(x >= t)
				{
					ans1 += t;
					continue;
				}
				ans1 += x;
				s1.erase(x);
			}
			else ans1 += t;
		}

		for(int i = l; i <= r; i ++) q.push(a[i]);
		while(q.size())
		{
			auto t = q.top(); q.pop();
			if(s2.size())
			{
				int x = *s2.begin();
				if(x >= t)
				{
					ans2 += t;
					continue;
				}
				ans2 += x;
				s2.erase(x);
			}
			else ans2 += t;
		}
		cout <<min(ans1, ans2) <<endl;
	}
	return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#define ff first
#define se second
#define endl '\n'
#define int long long
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

signed main()
{
	cin.tie(0) -> sync_with_stdio(false);

	int T; cin >>T;
	while(T --)
	{
		int n, l, r; cin >>n >>l >>r;
		int a[n + 1];
		for(int i = 1; i <= n; i ++) cin >>a[i];

		vector <int> v1, v2;
		for(int i = 1; i <= r; i ++)
			v1.push_back(a[i]);
		for(int i = l; i <= n; i ++)
			v2.push_back(a[i]);
		sort(v1.begin(), v1.end()), sort(v2.begin(), v2.end());
		int ans1 = 0, ans2 = 0;
		for(int i = 0; i < r - l + 1; i ++)
			ans1 += v1[i], ans2 += v2[i];
		cout <<min(ans1, ans2) <<endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#define ff first
#define se second
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

signed main()
{
	cin.tie(0) -> sync_with_stdio(false);

	int T; cin >>T;
	while(T --)
	{
		int n, l, r; cin >>n >>l >>r;
		int a[n + 1];
		for(int i = 1; i <= n; i ++) cin >>a[i];

		sort(a + 1, a + 1 + n);

		ll sum = 0;
		for(int i = 1; i <= r - l + 1; i ++)
			sum += a[i];
		cout <<sum <<endl;
	}
	return 0;
}
Problem: 2050D - Digital string maximization
Language: PyPy 3

Previous submission (verdict: Time limit exceeded on test 5):
def solve():
    s = input()
    for i in range(len(s)):
        best = int(s[i])
        pos = i
        for j in range(i, min(i + 10, len(s))):
            if int(s[j]) - j + i > best:
                best = int(s[j]) - j + i
                pos = j
        
        s = list(s)
        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], str(int(s[pos])-1)
            pos -= 1
        s = "".join(s)
        
    return s

for _ in range(int(input())): print(solve())

Submission (verdict: Time limit exceeded on test 5):
from sys import stdin

def solve():
    s = stdin.readline()[:-1]
    for i in range(len(s)):
        best = int(s[i])
        pos = i
        for j in range(i, min(i + 10, len(s))):
            if int(s[j]) - j + i > best:
                best = int(s[j]) - j + i
                pos = j
        
        s = list(s)
        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], str(int(s[pos])-1)
            pos -= 1
        s = "".join(s)
        
    return s

for _ in range(int(stdin.readline())): print(solve())
Problem: 2050D - Digital string maximization
Language: PyPy 3


Submission (verdict: Time limit exceeded on test 5):
def solve():
    s = input()
    for i in range(len(s)):
        best = int(s[i])
        pos = i
        for j in range(i, min(i + 10, len(s))):
            if int(s[j]) - j + i > best:
                best = int(s[j]) - j + i
                pos = j
        
        s = list(s)
        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], str(int(s[pos])-1)
            pos -= 1
        s = "".join(s)
        
    return s

for _ in range(int(input())): print(solve())
Problem: 2050D - Digital string maximization
Language: PyPy 3

Previous submission (verdict: Time limit exceeded on test 5):
from sys import stdin

def solve():
    s = stdin.readline()[:-1]
    for i in range(len(s)):
        best = int(s[i])
        pos = i
        for j in range(i, min(i + 10, len(s))):
            if int(s[j]) - j + i > best:
                best = int(s[j]) - j + i
                pos = j
        
        s = list(s)
        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], str(int(s[pos])-1)
            pos -= 1
        s = "".join(s)
        
    return s

for _ in range(int(stdin.readline())): print(solve())

Submission (verdict: Accepted):
from sys import stdin

def solve():
    s = list(stdin.readline()[:-1])
    for i in range(len(s)):
        best = int(s[i])
        pos = i
        for j in range(i, min(i + 10, len(s))):
            if int(s[j]) - j + i > best:
                best = int(s[j]) - j + i
                pos = j
        
        while pos > i:
            s[pos], s[pos - 1] = s[pos - 1], str(int(s[pos])-1)
            pos -= 1
        
    return "".join(s)

for _ in range(int(stdin.readline())): print(solve())
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9 + 1;

void ckmin(int& a, int& b){
	if (a > b){
		a -= b;
		b = 0;
	} else if (a < b){
		b -= a;
		a = 0;
	} else{
		a = 0;
		b = 0;
	}
}

void solve(){
	int n; cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++){
		int num; cin >> num;
		arr[i] = num;
	}

	if (arr[0] > arr[1]){
		cout << "NO" << endl;
		return;
	}

	for (int i = 1; i < n - 1; i++){
		if (arr[i] > arr[i + 1]){
			ckmin(arr[i - 1], arr[i]);
		}
		if (arr[i] > arr[i + 1]){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(){

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

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9 + 1;

void ckmin(int& a, int& b){
	if (a > b){
		a -= b;
		b = 0;
	} else if (a < b){
		b -= a;
		a = 0;
	} else{
		a = 0;
		b = 0;
	}
}

void solve(){
	int n; cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++){
		int num; cin >> num;
		arr[i] = num;
	}

	if (arr[0] > arr[1]){
		cout << "NO" << endl;
		return;
	}

	for (int i = 1; i < n - 1; i++){
		if (arr[i] > arr[i + 1]){
			ckmin(arr[i - 1], arr[i]);
		}
		if (arr[i] > arr[i + 1]){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(){

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

	return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9 + 1;

void ckmin(int& a, int& b){
	if (a > b){
		a -= b;
		b = 0;
	} else if (a < b){
		b -= a;
		a = 0;
	} else{
		a = 0;
		b = 0;
	}
}

void solve(){
	int n; cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++){
		int num; cin >> num;
		arr[i] = num;
	}

	if (arr[0] > arr[1]){
		cout << "NO" << endl;
		return;
	}

	for (int i = 1; i < n - 1; i++){
		if (arr[i] > arr[i + 1]){
			ckmin(arr[i - 1], arr[i]);
		}
		if (arr[i] > arr[i + 1]){
			cout << "NO" << endl;
			return;
		}
		if (i > 1 && arr[i - 1] < arr[i - 2]){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(){

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

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9 + 1;

void ckmin(int& a, int& b){
	if (a > b){
		a -= b;
		b = 0;
	} else if (a < b){
		b -= a;
		a = 0;
	} else{
		a = 0;
		b = 0;
	}
}

void solve(){
	int n; cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++){
		int num; cin >> num;
		arr[i] = num;
	}

	if (arr[0] > arr[1]){
		cout << "NO" << endl;
		return;
	}

	for (int i = 1; i < n - 1; i++){
		if (arr[i] > arr[i + 1]){
			ckmin(arr[i - 1], arr[i]);
		}
		if (arr[i] > arr[i + 1]){
			cout << "NO" << endl;
			return;
		}
		if (i > 1 && arr[i - 1] < arr[i - 2]){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(){

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

	return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9 + 1;

void ckmin(int& a, int& b){
	if (a > b){
		a -= b;
		b = 0;
	} else if (a < b){
		b -= a;
		a = 0;
	} else{
		a = 0;
		b = 0;
	}
}

void solve(){
	int n; cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++){
		int num; cin >> num;
		arr[i] = num;
	}

	if (arr[0] > arr[1]){
		cout << "NO" << endl;
		return;
	}

	for (int i = 1; i < n - 1; i++){
		ckmin(arr[i - 1], arr[i]);
		if (arr[i] > arr[i + 1]){
			cout << "NO" << endl;
			return;
		}
		if (i > 1 && arr[i - 1] < arr[i - 2]){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(){

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

	return 0;
}
Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;



typedef long long       ll;

typedef vector<int>     vi;

typedef vector<vi>      vvi;

typedef vector<ll>      vll;

typedef pair<int,int>   pii;

typedef pair<ll,ll>     pll;

typedef vector<pii>     vpii;



#define rep(i,x,y)      for(int i=x; i<y; i++, i%=n)

#define rrep(i,x,y)     for(int i=x; i>=y; i--)

#define inp(arr)        for(auto &x: arr) cin >>x;

#define ninp(arr,n)     int n; cin >>n; vector<int> arr(n); for(auto &x: arr) cin >>x;

#define kinp(arr,n,k)   int n,k; cin >>n >>k; vector<int> arr(n); for(auto &x: arr) cin >>x;

#define out(arr)        for(auto &x: arr){ cout <<x <<' ';} cout <<endl; 

#define EB              emplace_back

#define F               first

#define S               second

#define all(p)          p.begin(),p.end()





int main(){

    int t; cin >>t;

    while(t--){

        int n,x,y; cin >>n >>x >>y;

        x--, y--;



        vi ans(n,0);

        ans[x]=0, ans[y]=1;



        rep(i,x+1,y){

            if(i==y-1){

                if(i%2 != x%2) ans[i]=2;

                else ans[i]=0;

                continue;

            }

            if(i%2 == x%2) ans[i]=0;

            else ans[i]=1;

        }



        rep(i,y+1,x){

            if(i==x-1){

                if(i%2 != y%2) ans[i]=2;

                else ans[i]=1;

                continue;

            }

            if(i%2 == y%2) ans[i]=1;

            else ans[i]=0;

        }



        out(ans);

    }

    return 0;

}