ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


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

#include <vector>

#include <map>

using namespace std;

struct node

{

	int value=0;

	int location=0;

};

int main() {

	int n;

	cin >> n;

	map<int, int> m1, m2;

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

		//这个数在什么位置

		m1[n + 1 - i] = i;

		//存储的数

		m2[i] = n + 1 - i;

	}

	vector<int> brr(n + 1);

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

		cin >> brr[i];

	}

	int ans = n * (n - 1) / 2;

	vector<node> arr;

	for (int i = n; i > 0; i--) {

		ans += i - m1[brr[i]];

		for (int j = m1[brr[i]] + 1; j <= i; j++) {

			node temp;

			temp.value = brr[i];

			temp.location = m2[j];

			arr.push_back(temp);

		}

		int temp = m2[i];

		int temp2 = m1[brr[i]];

		m1[temp] = temp2;

		m1[brr[i]] = i;

		m2[i] = brr[i];

		m2[temp2] = temp;



	}

	cout << ans << endl;

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

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

			cout << i << " " << j << endl;

		}

	}

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

		cout << arr[i].value << " " << arr[i].location << endl;

	}

}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

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

#include <vector>

#include <map>

using namespace std;

struct node

{

	int value=0;

	int location=0;

};

int main() {

	int n;

	cin >> n;

	map<int, int> m1, m2;

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

		//这个数在什么位置

		m1[n + 1 - i] = i;

		//存储的数

		m2[i] = n + 1 - i;

	}

	vector<int> brr(n + 1);

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

		cin >> brr[i];

	}

	int ans = n * (n - 1) / 2;

	vector<node> arr;

	for (int i = n; i > 0; i--) {

		ans += i - m1[brr[i]];

		for (int j = m1[brr[i]] + 1; j <= i; j++) {

			node temp;

			temp.value = brr[i];

			temp.location = m2[j];

			arr.push_back(temp);

		}

		int temp = m2[i];

		int temp2 = m1[brr[i]];

		m1[temp] = temp2;

		m1[brr[i]] = i;

		m2[i] = brr[i];

		m2[temp2] = temp;



	}

	cout << ans << endl;

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

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

			cout << i << " " << j << endl;

		}

	}

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

		cout << arr[i].value << " " << arr[i].location << endl;

	}

}

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

#include <vector>

#include <map>

using namespace std;

struct node

{

	int value=0;

	int location=0;

};

int main() {

	int n;

	cin >> n;

	map<int, int> m1, m2;

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

		//这个数在什么位置

		m1[n + 1 - i] = i;

		//存储的数

		m2[i] = n + 1 - i;

	}

	vector<int> brr(n + 1);

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

		cin >> brr[i];

	}

	int ans = n * (n - 1) / 2;

	vector<node> arr;

	for (int i = n; i > 0; i--) {

		ans += i - m1[brr[i]];

		for (int j = m1[brr[i]] + 1; j <= i; j++) {

			node temp;

			temp.value = brr[i];

			temp.location = m2[j];

			arr.push_back(temp);

		}

		int temp = m2[i];

		int temp2 = m1[brr[i]];

		m1[temp] = temp2;

		m1[brr[i]] = i;

		m2[i] = brr[i];

		m2[temp2] = temp;



	}

	cout << ans << endl;

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

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

			cout << j << " " << i << endl;

		}

	}

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

		cout << arr[i].location << " " << arr[i].value << endl;

	}

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


Submission (verdict: Wrong answer on test 2):
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
 
#define ln              "\n" // no flush, oppos of endl
#define _flush          endl
#define stop_sync       ios::sync_with_stdio(false) // not to use c-style io
#define untie_ios       cin.tie(nullptr) // no flush
#define ll             long long int
#define vi              vector<int>
#define vii             vector<ll>
#define vch             vector<char>
#define double          long double
#define vss             vector<string>
#define vpp(T1, T2)     vector<pair<T1, T2>>
#define pq              priority_queue // high prec.
#define pqq(T)          priority_queue<T, vector<T>, greater<T>>            
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define Fi(p)           get<0>(p)
#define Sc(p)           get<1>(p)
#define sz(x)           int ((x).size())
#define all(x)          (x).begin(), (x).end()
#define bin_sc(a, x)    binary_search(all(a), x)
#define lbd(a, x)       lower_bound(all(a), x) // an iter.
#define ubd(a, x)       upper_bound(all(a), x) // an iter.
#define eq_seg(a, x)    equal_range(all(a), x) // a pair of lb, ub
#define FIXED(x)        cout << fixed << setprecision(x)
#define _print(x)       cout << (#x) << ": " << (x) << ln
#define uceil(a, b)     ((a + b - 1) / (b))
#define ff first
#define ss second

 
#include <iostream>
#include <vector>
#include <algorithm>
ll factorial(ll n) 
{ 
    // single line to find factorial 
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
} 
  const int N=1e5+10;
  vector<ll>g[N],g1[N];
  void dfs(ll v,ll p){
    for(auto child:g[v]){

      if(child==p)continue;

      dfs(child,v);
    }
    
  }
  
  //vector<ll>path(ll v){
  //  vector<ll>ans;
  //  while(v!=-1){ 
   //   ans.pb(v);
   //   v=par[v];
  //  }
  //  reverse(ans.begin(),ans.end());
   // return ans;

 // }
    


 int main(){
        ll t;
        cin>>t;
        while(t--){
          ll n;
          cin>>n;
          ll a[n];
          for(ll i=0;i<n;i++){
            cin>>a[i];
          }
          ll cnt=0;
          ll x=a[1]-a[0];
          if(x>0)cnt++;
          if(x>0){
          for(ll i=2;i<n;i++){
            if(a[i]-x>0){
              x=a[i]-x;
              cnt++;
            }
          }
          }
          if(cnt==n-1){
            cout<<"YES"<<endl;
          }
          else{
            cout<<"NO"<<endl;
          }

        
        
      }
    }
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)

#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

#define fordt(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)

#define forde(i, a, b) for (int i = (a), _b = (b); i > _b; --i)

#define trav(a, x) for (auto& a : x)

#define rep(i, a, b) for(int i = a; i < (b); ++i)

#define all(x) begin(x), end(x)

#define sz(x) (int)(x).size()



using namespace std;

using namespace __gnu_pbds;



template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};

template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};



typedef int64_t i64;

typedef pair<int,int> _ii;

typedef vector<int> vi;

typedef long long ll;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

constexpr int maxn = 2e5 + 7;

constexpr i64 oo = 1e9 + 7;



void solve() {

    int n;

    cin >> n;



    vi a(n);

    rep(i, 0, n) cin >> a[i];



    vector <_ii> ans;

    rep(i, 0, n) rep(j, i + 1, n) {

        if(a[i] < a[j]) {

            ans.push_back({_ii(a[j], a[i])});

            ans.push_back({_ii(a[i], a[j])});

        }



        else {

            ans.push_back({_ii(a[i], a[j])});

        }

    }



    cout << sz(ans) << '\n';

    trav(x, ans) cout << x.first << ' ' << x.second << '\n';

}



#define NAME "C."

int main() {

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



    if(fopen(NAME"inp", "r")) {

        freopen(NAME"inp", "r", stdin);

        freopen(NAME"out", "w", stdout);

    }



    int t=1;

    while(t--) solve();

}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
/*Dream is not what you see in sleep, dream is what can't make you sleep*/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<long long int>
#define pb push_back
#define endl '\n'
#define M_PI 3.14159265358979323846
#define test_case int tt; cin>>tt;while(tt--)
#define all(v) sort(v.begin(),v.end())
#define input_file ifstream cin("input.txt");ofstream cout("output.txt");

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*Code here*/
    int n;
    cin >> n;
    map<int, int> mp;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        mp[x] = i;
    }

    // for(auto it:mp){
    //     cout<<it.first<< ' ' <<it.second<<endl;
    // }

    vector<int> temp;
    int ans = 0;
    vector<pair<int, int>> final;

    for (int i = n; i >= 1; i--) {

        ans += i - 1;
        for (int k = i - 1; k >= 1; k--) {
            final.push_back({i, k});
        }
        for (int k = temp.size() - 1; k >= 0; k--) {
            if (mp[temp[k]] > mp[i]) {
                ans++;
                final.push_back({i, temp[k]});
            }
        }
        temp.push_back(i);

    }
    cout << ans << endl;
    for (auto x : final) {
        cout << x.first << ' ' << x.second << endl;
    }

    return 0;
}


Submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<long long int>
#define pb push_back
#define endl '\n'
#define M_PI 3.14159265358979323846
#define test_case int tt; cin>>tt;while(tt--)
#define all(v) sort(v.begin(),v.end())
#define input_file ifstream cin("input.txt");ofstream cout("output.txt");

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /* Code here */
    int n;
    cin >> n;
    map<int, int> mp;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        mp[x] = i;
    }

    vector<int> temp; 
    int ans = 0; 
    vector<pair<int, int>> final; 

    for (int i = n; i >= 1; i--) {
        ans += i - 1;
        for (int k = i - 1; k >= 1; k--) {
            final.push_back({i, k});
        }

        for (int k = temp.size() - 1; k >= 0; k--) {
            if (mp[temp[k]] > mp[i]) {
                ans++;
                final.push_back({i, temp[k]});
            }
        }

        auto pos = lower_bound(temp.begin(), temp.end(), i);
        temp.insert(pos, i);
    }
    cout << ans << endl;
    for (auto x : final) {
        cout << x.first << ' ' << x.second << endl;
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
/*Dream is not what you see in sleep, dream is what can't make you sleep*/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<long long int>
#define pb push_back
#define endl '\n'
#define M_PI 3.14159265358979323846
#define test_case int tt; cin>>tt;while(tt--)
#define all(v) sort(v.begin(),v.end())
#define input_file ifstream cin("input.txt");ofstream cout("output.txt");

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*Code here*/ 
    int n; 
    cin >> n; 
    vector<int> v(n + 1);
    map<int, int> mp;

    for (int i = 1; i <= n; i++) {
        int x; 
        cin >> x; 
        mp[x] = i;
    }

    vector<int> temp;
    int ans = 0;
    vector<pair<int, int>> final;

    for (int i = n; i >= 1; i--) {
        if (temp.empty()) {
            ans += n - 1;
            temp.push_back(i);
            for (int k = i - 1; k >= 1; k--) {
                final.push_back({i, k});
            }
        } else {
            ans += i - 1;
            for (int k = i - 1; k >= 1; k--) {
                final.push_back({i, k});
            }
            for (int k = temp.size() - 1; k >= 0; k--) {
                if (temp[k] > i && mp[temp[k]] > mp[i]) {
                    ans++;
                    final.push_back({i, temp[k]});
                }
            }
            temp.push_back(i);
        }
    }
    cout<<ans<<endl;
    for (auto x : final) {
        cout << x.first << ' ' << x.second << endl;
    }

    return 0;
}


Submission (verdict: Wrong answer on test 4):
/*Dream is not what you see in sleep, dream is what can't make you sleep*/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<long long int>
#define pb push_back
#define endl '\n'
#define M_PI 3.14159265358979323846
#define test_case int tt; cin>>tt;while(tt--)
#define all(v) sort(v.begin(),v.end())
#define input_file ifstream cin("input.txt");ofstream cout("output.txt");

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*Code here*/
    int n;
    cin >> n;
    map<int, int> mp;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        mp[x] = i;
    }

    // for(auto it:mp){
    //     cout<<it.first<< ' ' <<it.second<<endl;
    // }

    vector<int> temp;
    int ans = 0;
    vector<pair<int, int>> final;

    for (int i = n; i >= 1; i--) {

        ans += i - 1;
        for (int k = i - 1; k >= 1; k--) {
            final.push_back({i, k});
        }
        for (int k = temp.size() - 1; k >= 0; k--) {
            if (mp[temp[k]] > mp[i]) {
                ans++;
                final.push_back({i, temp[k]});
            }
        }
        temp.push_back(i);

    }
    cout << ans << endl;
    for (auto x : final) {
        cout << x.first << ' ' << x.second << endl;
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 7):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<long long int>
#define pb push_back
#define endl '\n'
#define M_PI 3.14159265358979323846
#define test_case int tt; cin>>tt;while(tt--)
#define all(v) sort(v.begin(),v.end())
#define input_file ifstream cin("input.txt");ofstream cout("output.txt");

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /* Code here */
    int n;
    cin >> n;
    map<int, int> mp;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        mp[x] = i;
    }

    vector<int> temp; 
    int ans = 0; 
    vector<pair<int, int>> final; 

    for (int i = n; i >= 1; i--) {
        ans += i - 1;
        for (int k = i - 1; k >= 1; k--) {
            final.push_back({i, k});
        }

        for (int k = temp.size() - 1; k >= 0; k--) {
            if (mp[temp[k]] > mp[i]) {
                ans++;
                final.push_back({i, temp[k]});
            }
        }

        auto pos = lower_bound(temp.begin(), temp.end(), i);
        temp.insert(pos, i);
    }
    cout << ans << endl;
    for (auto x : final) {
        cout << x.first << ' ' << x.second << endl;
    }

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<long long int>
#define pb push_back
#define endl '\n'
#define M_PI 3.14159265358979323846
#define test_case int tt; cin>>tt;while(tt--)
#define all(v) sort(v.begin(),v.end())
#define input_file ifstream cin("input.txt");ofstream cout("output.txt");

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*Code here*/
    int n;
    cin >> n;
    map<int, int> mp;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        mp[x] = i;
    }

    vector<int> temp;
    int ans = 0;
    vector<pair<int, int>> final;

    for (int i = n; i >= 1; i--) {
        ans += i - 1;
        for (int k = i - 1; k >= 1; k--) {
            final.push_back({i, k});
        }
        for (int k = temp.size() - 1; k >= 0; k--) {
            if (mp[temp[k]] > mp[i]) {
                ans++;
                final.push_back({i, temp[k]});
            }
        }

        bool inserted = false;
        for (int k = 0; k < temp.size(); k++) {
            if (mp[i] < mp[temp[k]]) {
                temp.insert(temp.begin() + k, i);
                inserted = true;
                break;
            }
        }

        if (!inserted) {
            temp.push_back(i);
        }
    }

    cout << ans << endl;
    for (auto x : final) {
        cout << x.first << ' ' << x.second << endl;
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
/*Dream is not what you see in sleep, dream is what can't make you sleep*/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<long long int>
#define pb push_back
#define endl '\n'
#define M_PI 3.14159265358979323846
#define test_case int tt; cin>>tt;while(tt--)
#define all(v) sort(v.begin(),v.end())
#define input_file ifstream cin("input.txt");ofstream cout("output.txt");

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*Code here*/ 
    int n; 
    cin >> n; 
    vector<int> v(n + 1);
    map<int, int> mp;

    for (int i = 1; i <= n; i++) {
        int x; 
        cin >> x; 
        mp[x] = i;
    }

    vector<int> temp;
    int ans = 0;
    vector<pair<int, int>> final;

    for (int i = n; i >= 1; i--) {
        if (temp.empty()) {
            ans += n - 1;
            temp.push_back(i);
            for (int k = i - 1; k >= 1; k--) {
                final.push_back({i, k});
            }
        } else {
            ans += i - 1;
            for (int k = i - 1; k >= 1; k--) {
                final.push_back({i, k});
            }
            for (int k = temp.size() - 1; k >= 0; k--) {
                if (temp[k] > i && mp[temp[k]] > mp[i]) {
                    ans++;
                    final.push_back({i, temp[k]});
                }
            }
            temp.push_back(i);
        }
    }
    cout<<ans<<endl;
    for (auto x : final) {
        cout << x.first << ' ' << x.second << endl;
    }

    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>



static void solve(void)

{

	int n;

	std::cin >> n;

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

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

		std::cin >> v[i];

	}

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

	{

		std::cout << "NO" << std::endl;

		return;

	}

	bool ok = true;

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

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

		{

			while (v[i - 1] > v[i])

			{

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

				if (d <= 0)

				{

					std::cout << "NO" << std::endl;

					return;

				}

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

			}

		}

	}

	std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::cin >> t;

	while (t--)

	{

		solve();

	}

	return 0;

}



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



static void solve(void)

{

	int n;

	std::cin >> n;

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

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

		std::cin >> v[i];

	}

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

	{

		std::cout << "NO" << std::endl;

		return;

	}

	bool ok = true;

	for (int i = 0; i < n - 2; i++) {

		while (v[i + 2] < v[i + 1])

		{

			int d = std::min(v[i + 1], v[i]);

			if (d == 0)

			{

				std::cout << "NO" << std::endl;

				return;

			}

			v[i + 1] -= d;

			v[i] -= d;

		}

	}

	if (v[n - 2] > v[n - 1])

		std::cout << "NO" << std::endl;

	else

		std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::cin >> t;

	while (t--)

	{

		solve();

	}

	return 0;

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


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



static void solve(void)

{

	int n;

	std::cin >> n;

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

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

		std::cin >> v[i];

	}

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

	{

		std::cout << "NO" << std::endl;

		return;

	}

	bool ok = true;

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

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

		{

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

			if (d <= 0)

			{

				std::cout << "NO" << std::endl;

				return;

			}

			while (v[i - 1] > v[i])

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

		}

	}

	std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::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>



static void solve(void)

{

	int n;

	std::cin >> n;

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

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

		std::cin >> v[i];

	}

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

	{

		std::cout << "NO" << std::endl;

		return;

	}

	bool ok = true;

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

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

		{

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

			if (d <= 0)

			{

				std::cout << "NO" << std::endl;

				return;

			}

			while (v[i - 1] > v[i])

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

		}

	}

	std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::cin >> t;

	while (t--)

	{

		solve();

	}

	return 0;

}



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



static void solve(void)

{

	int n;

	std::cin >> n;

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

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

		std::cin >> v[i];

	}

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

	{

		std::cout << "NO" << std::endl;

		return;

	}

	bool ok = true;

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

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

		{

			while (v[i - 1] > v[i])

			{

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

				if (d <= 0)

				{

					std::cout << "NO" << std::endl;

					return;

				}

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

			}

		}

	}

	std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::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>



static void solve(void)

{

	int n;

	std::cin >> n;

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

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

		std::cin >> v[i];

	}

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

	{

		std::cout << "NO" << std::endl;

		return;

	}

	bool ok = true;

	for (int i = 0; i < n - 2; i++) {

		while (v[i + 2] < v[i + 1])

		{

			int d = std::min(v[i + 1], v[i]);

			if (d == 0)

			{

				std::cout << "NO" << std::endl;

				return;

			}

			v[i + 1] -= d;

			v[i] -= d;

		}

	}

	if (v[n - 2] > v[n - 1])

		std::cout << "NO" << std::endl;

	else

		std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::cin >> t;

	while (t--)

	{

		solve();

	}

	return 0;

}



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



static void solve(void)

{

	int n;

	std::cin >> n;

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

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

		std::cin >> v[i];

	}

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

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

		{

			std::cout << "NO" << std::endl;

			return;

		}

		int d = std::min(v[i + 1], v[i]);

		while (d)

		{

			v[i + 1] -= d;

			v[i] -= d;

			d = std::min(v[i], v[i + 1]);

		}

	}

	std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::cin >> t;

	while (t--)

	{

		solve();

	}

	return 0;

}