ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

#include <bits/stdc++.h>

using namespace std;

long long min(long long a, long long b, long long c)

{

    return min(a, min(b, c));

}

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n, l, r;

        cin >> n >> l >> r;

        int a[100005] = {0};

        long long s[100005] = {0};

        for (int i = 0; i < n; i++)

            cin >> a[i];

        sort(a + r, a + n);

        sort(a, a + l - 1); // [a, b)

        sort(a + l - 1, a + r, greater<int>());

        // for (int i = 0; i < n; i++)

        //     cout << a[i] << " ";

        for (int i = 0; i < l - 1; i++)

        {

            s[i] = a[i];

            if (i > 0)

                s[i] += s[i - 1];

        }

        for (int i = l - 1; i < r; i++)

        {

            s[i] = a[i];

            if (i > l - 1)

                s[i] += s[i - 1];

        }

        for (int i = r; i < n; i++)

        {

            s[i] = a[i];

            if (i > r)

                s[i] += s[i - 1];

        }

        // cout << "\n";

        // for (int i = 0; i < n; i++)

        //     cout << s[i] << " ";

        long long ans = s[r-1];

        for (int i = l - 1; i < r; i++)

        {

            int ll = i - l + 1;

            int rr = r+ll;

            long long now = s[r - 1] - s[i];

            ans = min(ans, (ll >= l - 1? 999999999999 : now + s[ll]),(rr < n ? now + s[rr] : 999999999999));

        }

        // cout << "\n";

        cout << ans << "\n";

    }

}

Submission (verdict: Accepted):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b, long long c)
{
    return min(a, min(b, c));
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, l, r;
        cin >> n >> l >> r;
        int a[100005] = {0};
        long long s[100005] = {0};
        for (int i = 0; i < n; i++)
            cin >> a[i];
        sort(a + r, a + n);
        sort(a, a + l - 1); // [a, b)
        sort(a + l - 1, a + r, greater<int>());
        // for (int i = 0; i < n; i++)
        //     cout << a[i] << " ";
        for (int i = 0; i < l - 1; i++)
        {
            s[i] = a[i];
            if (i > 0)
                s[i] += s[i - 1];
        }
        for (int i = l - 1; i < r; i++)
        {
            s[i] = a[i];
            if (i > l - 1)
                s[i] += s[i - 1];
        }
        for (int i = r; i < n; i++)
        {
            s[i] = a[i];
            if (i > r)
                s[i] += s[i - 1];
        }
        // cout << "\n";
        // for (int i = 0; i < n; i++)
        //     cout << s[i] << " ";
        long long ans = s[r-1];
        for (int i = l - 1; i < r; i++)
        {
            int ll = i - l + 1;
            int rr = r+ll;
            long long now = s[r - 1] - s[i];
            ans = min(ans, (ll >= l - 1? LONG_LONG_MAX : now + s[ll]),(rr < n ? now + s[rr] : LONG_LONG_MAX));
        }
        // cout << "\n";
        cout << ans << "\n";
    }
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


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

#include <bits/stdc++.h>

using namespace std;

long long min(long long a, long long b, long long c)

{

    return min(a, min(b, c));

}

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n, l, r;

        cin >> n >> l >> r;

        int a[100005] = {0};

        long long s[100005] = {0};

        for (int i = 0; i < n; i++)

            cin >> a[i];

        sort(a + r, a + n);

        sort(a, a + l - 1); // [a, b)

        sort(a + l - 1, a + r, greater<int>());

        // for (int i = 0; i < n; i++)

        //     cout << a[i] << " ";

        for (int i = 0; i < l - 1; i++)

        {

            s[i] = a[i];

            if (i > 0)

                s[i] += s[i - 1];

        }

        for (int i = l - 1; i < r; i++)

        {

            s[i] = a[i];

            if (i > l - 1)

                s[i] += s[i - 1];

        }

        for (int i = r; i < n; i++)

        {

            s[i] = a[i];

            if (i > r)

                s[i] += s[i - 1];

        }

        // cout << "\n";

        // for (int i = 0; i < n; i++)

        //     cout << s[i] << " ";

        long long ans = s[r-1];

        for (int i = l - 1; i < r; i++)

        {

            int ll = i - l + 1;

            int rr = r+ll;

            long long now = s[r - 1] - s[i];

            ans = min(ans, (ll >= l - 1? 999999999 : now + s[ll]),(rr < n ? now + s[rr] : 999999999));

        }

        // cout << "\n";

        cout << ans << "\n";

    }

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int T,n,a[N];
void init()
{
}
void solve()
{
	cin>>n;
	init();
	for(int i=1;i<=n;i++)
	cin>>a[i];
	for(int i=1;i<n;i++)
	{
		if(a[i]>a[i+1])
		{
			a[i]=a[i]-min(a[i],a[i-1]);
			if(a[i]>a[i+1]) {cout<<"NO"<<endl; return ;}
		}
	}
	cout<<"YES"<<endl;	
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>T;
    while(T--) solve();
}

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

#define int long long

using namespace std;

const int N=2e5+10;

int T,n,a[N];

void init()

{

}

void solve()

{

	cin>>n;

	init();

	for(int i=1;i<=n;i++)

	cin>>a[i];

	for(int i=1;i<n;i++)

	{

		if(a[i]>a[i+1])

		{

			a[i]=a[i]-min(a[i],a[i-1]);

			a[i-1]=a[i-1]-min(a[i],a[i-1]);

		}

	}

	for(int i=1;i<n;i++)

	{

		if(a[i]>a[i+1]) {cout<<"NO"<<endl; return ;}

	}

	cout<<"YES"<<endl;

}

signed main()

{

	std::ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	cin>>T;

    while(T--) solve();

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

#define int long long

using namespace std;

const int N=2e5+10;

int T,n,a[N];

void init()

{

}

void solve()

{

	cin>>n;

	init();

	for(int i=1;i<=n;i++)

	cin>>a[i];

	for(int i=1;i<n;i++)

	{

		if(a[i]>a[i+1])

		{

			a[i]=a[i]-min(a[i],a[i-1]);

			a[i-1]=a[i-1]-min(a[i],a[i-1]);

		}

	}

	for(int i=1;i<n;i++)

	{

		if(a[i]>a[i+1]) {cout<<"NO"<<endl; return ;}

	}

	cout<<"YES"<<endl;

}

signed main()

{

	std::ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	cin>>T;

    while(T--) solve();

}

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

#define int long long

using namespace std;

const int N=2e5+10;

int T,n,a[N];

void init()

{

}

void solve()

{

	cin>>n;

	init();

	for(int i=1;i<=n;i++)

	cin>>a[i];

	for(int i=1;i<n;i++)

	{

		if(a[i]>a[i+1])

		{

			cout<<"NO"<<endl;

			return ;

		}

		else

		{

			int k=min(a[i],a[i+1]);

			a[i]-=k;

			a[i+1]-=k;

		}

	}

	cout<<"YES"<<endl;

}

signed main()

{

	std::ios::sync_with_stdio(false);

	cin.tie(0);cout.tie(0);

	cin>>T;

    while(T--) solve();

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int T,n,a[N];
void init()
{
}
void solve()
{
	cin>>n;
	init();
	for(int i=1;i<=n;i++)
	cin>>a[i];
	for(int i=1;i<n;i++)
	{
		if(a[i]>a[i+1])
		{
			a[i]=a[i]-min(a[i],a[i-1]);
			if(a[i]>a[i+1]) {cout<<"NO"<<endl; return ;}
		}
	}
	cout<<"YES"<<endl;	
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>T;
    while(T--) solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

int numFib(vector<int>& v, int i) {

    int totalFib = 0;
    totalFib = (i == v[0] + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[2] == i + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[3] == i + v[2]) ? totalFib + 1 : totalFib;

    return totalFib;

}
int main() {
    int t;
    cin>>t;

    while (t--) {
        
        int n;
        cin>>n;
        vector<int> v(n);

        for (int i = 0; i < n; i++) cin>>v[i];

        bool valid = true;
        int minNum;

        for (int i = 0; i < n - 1; i++) {
            if (i > 0 && v[i-1] > v[i]) {
                valid = false;
                break;
            } 

            minNum = min(v[i], v[i-1]);
            v[i] -= minNum;
            v[i-1] -= minNum;
        }

        if (valid && v[v.size() - 1] >= v[v.size() - 2]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

    }

    return 0;
}


Submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;

int numFib(vector<int>& v, int i) {

    int totalFib = 0;
    totalFib = (i == v[0] + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[2] == i + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[3] == i + v[2]) ? totalFib + 1 : totalFib;

    return totalFib;

}
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin>>t;

    while (t--) {
        
        int n;
        cin>>n;
        vector<int> v(n);

        for (int i = 0; i < n; i++) cin>>v[i];

        bool valid = true;
        int minNum = INT_MAX;

        for (int i = 0; i < n - 1; i++) {
            if (i > 0 && v[i-1] > v[i]) {
                valid = false;
                break;
            } 

            minNum = min(v[i], v[i-1]);
            v[i] -= minNum;
            v[i-1] -= minNum;
        }

        if (valid && v[v.size() - 1] >= v[v.size() - 2]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

int numFib(vector<int>& v, int i) {

    int totalFib = 0;
    totalFib = (i == v[0] + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[2] == i + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[3] == i + v[2]) ? totalFib + 1 : totalFib;

    return totalFib;

}
int main() {
    int t;
    cin>>t;

    while (t--) {
        
        int n;
        cin>>n;
        vector<int> v(n);

        for (int i = 0; i < n; i++) cin>>v[i];

        bool valid = true;
        int minNum;

        for (int i = 0; i < n - 1; i++) {
            if (i > 0 && v[i-1] > v[i]) {
                valid = false;
                break;
            } 

            minNum = min(v[i], v[i-1]);
            v[i] -= minNum;
            v[i-1] -= minNum;
        }

        if (valid && v[v.size() - 1] >= v[v.size() - 2]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

int numFib(vector<int>& v, int i) {

    int totalFib = 0;
    totalFib = (i == v[0] + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[2] == i + v[1]) ? totalFib + 1 : totalFib;
    totalFib = (v[3] == i + v[2]) ? totalFib + 1 : totalFib;

    return totalFib;

}
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin>>t;

    while (t--) {
        
        int n;
        cin>>n;
        vector<int> v(n);

        for (int i = 0; i < n; i++) cin>>v[i];

        bool valid = true;
        int minNum = INT_MAX;

        for (int i = 0; i < n - 1; i++) {
            if (i > 0 && v[i-1] > v[i]) {
                valid = false;
                break;
            } 

            minNum = min(v[i], v[i-1]);
            v[i] -= minNum;
            v[i-1] -= minNum;
        }

        if (valid && v[v.size() - 1] >= v[v.size() - 2]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

    }

    return 0;
}


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

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin>>t;

    while (t--) {
        
        int n;
        cin>>n;
        vector<int> v(n);

        for (int i = 0; i < n; i++) cin>>v[i];

        bool valid = true;
        int minNum = INT_MAX;

        for (int i = 1; i < n; i++) {

            if (v[i-1] > v[i]) {
                valid = false;
                break;
            }
            minNum = min(v[i], v[i-1]);
            v[i] -= minNum;
            v[i-1] -= minNum;
        }

        if (valid && v[v.size() - 1] >= v[v.size() - 2]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits>
#include <set>
#include <map>
#include <unordered_map>
#include <climits>
#include <queue>
using namespace std;

const long long MOD = 1000000007LL;

struct Node {
    int num;
    vector<Node*> edges;
    int size = 0;

    Node(int i) : num(i) {}

    void addEdge(Node* node) {
        edges.push_back(node);
        size++;

    }


};

int main() {
    int t;
    cin >> t;

    while (t--) {
        
        int n;
        cin >> n;
        vector<Node*> nodes;

        for (int i = 0; i < n; i++) {
            Node* p = new Node(i+1);
            nodes.push_back(p);
            
        }

        for (int i = 0; i < n - 1; i++) {
            int first, second;
            cin >> first >> second;
            nodes[first-1]->addEdge(nodes[second-1]);
            nodes[second-1]->addEdge(nodes[first-1]);
        }

        sort(nodes.begin(), nodes.end(), [](const Node* a, const Node* b) {
            if (a->edges.size() == b->edges.size()) return a->num < b->num;
            return a->edges.size() > b->edges.size();
        });

        // for (auto k : nodes) cout << k->num << " " << k->edges.size() << endl;

        int connected = 1;

        // cout << "Starting connected:" << connected << endl;
        connected += nodes[0]->edges.size() - 1;
        // cout << "Middle connected:" << connected << endl;

        for (Node* n : nodes[0]->edges) {
            n->size--;
        }
        nodes[0]->size = 0;

        sort(nodes.begin(), nodes.end(), [](const Node* a, const Node* b) {
            return a->size > b->size;
        });

        connected += nodes[0]->size - 1;
        // cout << "Ending connected:" << connected << endl;

        cout << connected << endl;
        // cout << endl;




    }
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define nl '\n'
#define kaka() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all v.begin(),v.end()
ll pi = acos(-1);
int t,i,a,b,x,y,z,j,k,k1,k2,l,h,r,n,tr,q,m,mul,sum,sum1,sum2,result1,c,c1,c2,c4,c3,f,mx,mn,ans;
///ll  ar[200005];
const ll mxx = 5e5+123;
const ll mo =  1e9+7;
ll ar[mxx];
///vector < ll > v,v1,v3,v5,v4;
set<ll> st;
vector<char> vv;
map<ll,ll> mp,p;
string s,s1;
char ch;
///\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/



int32_t main()
{

    cin>>t;
    while(t--)
    {

        cin>>n;
        sum=0;
        vector<int>v(n);
        for(i=0; i<n; i++ ){
            cin>>v[i];
            sum+=v[i];
        }

        while(n>1){
                mx=0;
            for( i=0; i<n-1; i++ ){
                v[i]=(v[i+1]-v[i]);

            }
            n--;
            for( i=0;i<n;i++){
                mx+=v[i];

            }
            sum=max(abs(mx),sum);

        }
        cout<<sum<<endl;

    v.clear();
}
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define nl '\n'
#define kaka() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all v.begin(),v.end()
ll pi = acos(-1);
ll t,i,a,b,x,y,z,j,k,k1,k2,l,h,r,n,tr,q,m,mul,sum,sum1,sum2,result1,c,c1,c2,c4,c3,f,mx,mn,ans;
///ll  ar[200005];
const ll mxx = 5e5+123;
const ll mo =  1e9+7;
ll ar[mxx];
///vector < ll > v,v1,v3,v5,v4;
set<ll> st;
vector<char> vv;
map<ll,ll> mp,p;
string s,s1;
char ch;
///\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/



int32_t main()
{

    cin>>t;
    while(t--)
    {

        cin>>n;
        sum=0;
        vector<int>v(n);
        for(i=0; i<n; i++ ){
            cin>>v[i];
            sum+=v[i];
        }

        while(n>1){
                mx=0;
            for( i=0; i<n-1; i++ ){
                v[i]=(v[i+1]-v[i]);

            }
            n--;
            for( i=0;i<n;i++){
                mx+=v[i];

            }
            sum=max(abs(mx),sum);

        }
        cout<<sum<<endl;

    v.clear();
}
}


Submission (verdict: Accepted):

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define nl '\n'
#define kaka() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all v.begin(),v.end()
ll pi = acos(-1);
ll t,i,a,b,x,y,z,j,k,k1,k2,l,h,r,n,tr,q,m,mul,sum,sum1,sum2,result1,c,c1,c2,c4,c3,f,mx,mn,ans;
///ll  ar[200005];
const ll mxx = 5e5+123;
const ll mo =  1e9+7;
ll ar[mxx];
///vector < ll > v,v1,v3,v5,v4;
set<ll> st;
vector<char> vv;
map<ll,ll> mp,p;
string s,s1;
char ch;
///\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/



int32_t main()
{

    cin>>t;
    while(t--)
    {

        cin>>n;
        sum=0;
        vector<ll>v(n);
        for(i=0; i<n; i++ ){
            cin>>v[i];
            sum+=v[i];
        }

        while(n>1){
                mx=0;
            for( i=0; i<n-1; i++ ){
                v[i]=(v[i+1]-v[i]);

            }
            n--;
            for( i=0;i<n;i++){
                mx+=v[i];

            }
            sum=max(abs(mx),sum);

        }
        cout<<sum<<endl;

    v.clear();
}
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define nl '\n'
#define kaka() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all v.begin(),v.end()
ll pi = acos(-1);
int t,i,a,b,x,y,z,j,k,k1,k2,l,h,r,n,tr,q,m,mul,sum,sum1,sum2,result1,c,c1,c2,c4,c3,f,mx,mn,ans;
///ll  ar[200005];
const ll mxx = 5e5+123;
const ll mo =  1e9+7;
ll ar[mxx];
///vector < ll > v,v1,v3,v5,v4;
set<ll> st;
vector<char> vv;
map<ll,ll> mp,p;
string s,s1;
char ch;
///\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/



int32_t main()
{

    cin>>t;
    while(t--)
    {

        cin>>n;
        sum=0;
        vector<int>v(n);
        for(i=0; i<n; i++ ){
            cin>>v[i];
            sum+=v[i];
        }

        while(n>1){
                mx=0;
            for( i=0; i<n-1; i++ ){
                v[i]=(v[i+1]-v[i]);

            }
            n--;
            for( i=0;i<n;i++){
                mx+=v[i];

            }
            sum=max(abs(mx),sum);

        }
        cout<<sum<<endl;

    v.clear();
}
}


Submission (verdict: Wrong answer on test 2):

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define nl '\n'
#define kaka() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all v.begin(),v.end()
ll pi = acos(-1);
ll t,i,a,b,x,y,z,j,k,k1,k2,l,h,r,n,tr,q,m,mul,sum,sum1,sum2,result1,c,c1,c2,c4,c3,f,mx,mn,ans;
///ll  ar[200005];
const ll mxx = 5e5+123;
const ll mo =  1e9+7;
ll ar[mxx];
///vector < ll > v,v1,v3,v5,v4;
set<ll> st;
vector<char> vv;
map<ll,ll> mp,p;
string s,s1;
char ch;
///\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/



int32_t main()
{

    cin>>t;
    while(t--)
    {

        cin>>n;
        sum=0;
        vector<int>v(n);
        for(i=0; i<n; i++ ){
            cin>>v[i];
            sum+=v[i];
        }

        while(n>1){
                mx=0;
            for( i=0; i<n-1; i++ ){
                v[i]=(v[i+1]-v[i]);

            }
            n--;
            for( i=0;i<n;i++){
                mx+=v[i];

            }
            sum=max(abs(mx),sum);

        }
        cout<<sum<<endl;

    v.clear();
}
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;



using ll = long long;

using i128 = __int128;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

constexpr int inf = 0x3f3f3f3f;

constexpr ll linf = 0x3f3f3f3f3f3f3f3f;





void solve() {

	// Your code here

	int N;

	cin >> N;

	std::vector<int> v(N);

	for (int i = 0; i < N; i++) {

		cin >> v[i];

	}



	int last = 0;

	//??�??

	for (int i = 1; i < N; i++) {

		if (v[i - 1] > v[i]) {

			// cout << "i-1 = " << i - 1 << '\n';

			if (i - last < 2) {

				cout << "NO" << '\n';

				return ;

			} else {

				last = i;

			}

		}

	}

	cout << "YES" << '\n';

}



int main()

{

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

	int t = 1;

	cin >> t;

	while (t--) {

		solve();

	}

	return 0;

}

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

using namespace std;



using ll = long long;

using i128 = __int128;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

constexpr int inf = 0x3f3f3f3f;

constexpr ll linf = 0x3f3f3f3f3f3f3f3f;



#define WA {cout << "NO" << '\n';return ;}

#define AC {cout << "YES" << '\n';return ;}



void solve() {

	// Your code here

	int N;

	cin >> N;

	std::vector<int> v(N);

	for (int i = 0; i < N; i++) {

		cin >> v[i];

	}

	if (N == 1) {

		AC;

	}

	if(v[0] > v[1]){

		WA;

	}

	/*

		2   3  4  1

		0   1  4  1

		0   0  3  1

	*/

	vector<int> suf(N);

	suf[N - 1] = v[N - 1];

	for (int i = N - 2; i; i--) {

		suf[i] = min(suf[i + 1], v[i]);

	}



	//5 4

	for (int i = 1; i < N - 1; i++) {

		if (v[i] > suf[i + 1]) {

			if (i == 0) {

				WA;

			}

			while (v[i] > suf[i + 1]) {

				int d = min(v[i - 1], v[i]);

				if (d <= 0) {

					WA;

				}

				v[i - 1] -= d, v[i] -= d;

			}

		}

	}



	AC;

}



int main()

{

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

	int t = 1;

	cin >> t;

	while (t--) {

		solve();

	}

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using namespace std;



using ll = long long;

using i128 = __int128;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

constexpr int inf = 0x3f3f3f3f;

constexpr ll linf = 0x3f3f3f3f3f3f3f3f;





void solve() {

	// Your code here

	int N;

	cin >> N;

	std::vector<int> v(N);

	for (int i = 0; i < N; i++) {

		cin >> v[i];

	}



	int last = 0;

	//??�??

	for (int i = 1; i < N; i++) {

		if (v[i - 1] > v[i]) {

			// cout << "i-1 = " << i - 1 << '\n';

			if (i - last < 2) {

				cout << "NO" << '\n';

				return ;

			} else {

				last = i;

			}

		}

	}

	cout << "YES" << '\n';

}



int main()

{

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

	int t = 1;

	cin >> t;

	while (t--) {

		solve();

	}

	return 0;

}