ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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



using namespace std;



#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



template <class T>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;



#define TRACE(x) cerr << __LINE__ << ": " << #x << " = " << x << endl

#define _ << " _ " <<



template <class T, class U> ostream &operator<<(ostream &o, pair<T, U> x) {

  return o << "(" << x.first << ", " << x.second << ")";

}

template <class> struct is_container : false_type {};

template <class... Ts> struct is_container<vector<Ts...>> : true_type {};

template <class... Ts> struct is_container<map<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_map<Ts...>> : true_type {};

template <class... Ts> struct is_container<set<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_set<Ts...>> : true_type {};

template <class... Ts> struct is_container<multiset<Ts...>> : true_type {};

template <class... Ts>

struct is_container<unordered_multiset<Ts...>> : true_type {};

template <class T, class = typename enable_if<is_container<T>::value>::type>

ostream &operator<<(ostream &o, T x) {

  int f = 1;

  o << "{";

  for (auto y : x) {

    o << (f ? "" : ", ") << y;

    f = 0;

  }

  return o << "}";

}



typedef long long llint;



const int MAXN = 1e5 + 10;



int t, n, l, r;

int a[MAXN];



void solve() {

  scanf("%d%d%d", &n, &l, &r);

  --l;

  --r;

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

    scanf("%d", &a[i]);



  llint sum = 0;

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

    sum += (llint)a[i];



  sort(a, a + l + 1);

  sort(a + l + 1, a + r + 1);

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



  llint dl = 0, dr = 0;

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

    if (r - i < l)

      continue;

    if (a[i] < a[r - i])

      dl += (llint)a[r - i] - a[i];

  }



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

    if (r - (i - r - 1) < l)

      continue;

    if (a[i] < a[r - (i - r - 1)])

      dr += (llint)a[r - (i - r - 1)] - a[i];

  }



  printf("%lld\n", sum - max(dl, dr));

}



int main(void) {

  scanf("%d", &t);

  while (t--)

    solve();

  return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long



void solve() {

    ll n,l,r;

    cin>>n>>l>>r;

    ll a[n];

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

        cin>>a[i];

    }

    sort(a,a+n);

    ll x=r-l,s=0;

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

        s+=a[i];

    }

    cout<<s<<endl;



}



int main() {

    

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    

    return 0;

}

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

void solve() {
    ll n,l,r;
    cin>>n>>l>>r;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll x=r-l,s=0;
    for(ll i=0;i<x+1;i++){
        s+=a[i];
    }
    cout<<s<<endl;

}

int main() {
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

void solve() {
    ll n,l,r;
    cin>>n>>l>>r;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll x=r-l,s=0;
    for(ll i=0;i<x+1;i++){
        s+=a[i];
    }
    cout<<s<<endl;

}

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

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

using namespace std;

#define ll long long



void solve() {

    ll n,l,r;

    cin>>n>>l>>r;

    l--;

    r--;

    ll a[n];

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

        cin>>a[i];

    }

    vector<ll> v1,v2;

    for(int i=0;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());

    ll s1=0,s2=0;

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

        s1+=v1[i];

        s2+=v2[i];

    }

    cout<<min(s1,s2)<<endl;



}



int main() {

    

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;

#define ll long long



void solve() {

    ll n,l,r;

    cin>>n>>l>>r;

    ll a[n];

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

        cin>>a[i];

    }

    sort(a,a+n);

    ll x=r-l,s=0;

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

        s+=a[i];

    }

    cout<<s<<endl;



}



int main() {

    

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    

    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

using i64 = long long;

void solve() {
    int l, r;
    std::cin >> l >> r;

    int a = 0, b = 0, c = 0;
    for (int i = 29; i >= 0; --i) {
        if ((l ^ r) >> i & 1) {
            a |= 1 << i;
            b |= (1 << i) - 1;
            break;
        } else {
            a |= l & 1 << i;
            b |= l & 1 << i;
        }
    }

    c == l;
    while (b == c) {
        ++c;
    }

    std::cout << a << " " << b << " " << c << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;  
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}


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

using i64 = long long;

void solve() {
    int l, r;
    std::cin >> l >> r;

    int a = 0, b = 0, c = 0;
    for (int i = 29; i >= 0; --i) {
        if ((l ^ r) >> i & 1) {
            a |= 1 << i;
            b |= (1 << i) - 1;
            break;
        } else {
            a |= l & 1 << i;
            b |= l & 1 << i;
        }
    }

    c = l;
    while (b == c) {
        ++c;
    }

    std::cout << a << " " << b << " " << c << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;  
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

using i64 = long long;

void solve() {
    int l, r;
    std::cin >> l >> r;

    int a = 0, b = 0, c = 0;
    for (int i = 29; i >= 0; --i) {
        if ((l ^ r) >> i & 1) {
            a |= 1 << i;
            b |= (1 << i) - 1;
            break;
        } else {
            a |= l & 1 << i;
            b |= l & 1 << i;
        }
    }

    c = l;
    while (b == c) {
        ++c;
    }

    std::cout << a << " " << b << " " << c << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;  
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}


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

using i64 = long long;

void solve() {
    int l, r;
    std::cin >> l >> r;

    int a = 0, b = 0, c = 0;
    for (int i = 29; i >= 0; --i) {
        if ((l ^ r) >> i & 1) {
            a |= 1 << i;
            b |= (1 << i) - 1;
            break;
        } else {
            a |= l & 1 << i;
            b |= l & 1 << i;
        }
    }

    c = l;
    while (a == c || b == c) {
        ++c;
    }

    std::cout << a << " " << b << " " << c << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;  
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

using i64 = long long;

void solve() {
    int l, r;
    std::cin >> l >> r;

    int a = 0, b = 0, c = 0;
    for (int i = 29; i >= 0; --i) {
        if ((l ^ r) >> i & 1) {
            a |= 1 << i;
            b |= (1 << i) - 1;
            break;
        } else {
            a |= l & 1 << i;
            b |= l & 1 << i;
        }
    }

    c == l;
    while (b == c) {
        ++c;
    }

    std::cout << a << " " << b << " " << c << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;  
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
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;

void solve() {
    int n, max_sum = INT_MIN;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    while (a.size() >= 1) {
        if (a.size() == 1 && max_sum < a[0]) {
            max_sum = a[0];
            break;
        }
        int temp_sum = accumulate(a.begin(), a.end(), 0);
        if (abs(temp_sum) > max_sum) max_sum = abs(temp_sum);
        for (int i = 0; i < a.size() - 1; i++) a[i] = a[i + 1] - a[i];
        a.pop_back();
    }
    cout << max_sum << endl;
}

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

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

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

#define int long long
using namespace std;

void solve() {
    int n, max_sum = INT_MIN;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    while (a.size() >= 1) {
        // vector < int > temp1(a.size() - 1), temp2(a.size() - 1), reverse_a(a.size());
        // for (int i = 0; i < a.size(); i++) reverse_a[i] = a[a.size() - i - 1];
        // for (int i = 0; i < a.size() - 1; i++) temp1[i] = a[i + 1] - a[i];
        // for (int i = 0; i < a.size() - 1; i++) temp2[i] = reverse_a[i + 1] - reverse_a[i];
        // int sum1, sum2, sum3;
        // sum1 = accumulate(a.begin(), a.end(), 0);
        // sum2 = accumulate(temp1.begin(), temp1.end(), 0);
        // sum3 = accumulate(temp2.begin(), temp2.end(), 0);
        // if (max_sum < max({sum1, sum2, sum3})) max_sum = max(sum1, sum2, sum3);


        int temp_sum = accumulate(a.begin(), a.end(), 0);
        // if (abs(temp_sum) > max_sum) max_sum = abs(temp_sum);
        if (a.size() == 1) max_sum = max(temp_sum, max_sum);
        else max_sum = max(max_sum, abs(temp_sum));
        for (int i = 0; i < a.size() - 1; i++) a[i] = a[i + 1] - a[i];
        a.pop_back();
    }
    cout << max_sum << endl;
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
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;

void solve() {
    int n, max_sum = INT_MIN;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    while (a.size() >= 1) {
        if (a.size() == 1 && max_sum < a[0]) {
            max_sum = a[0];
            break;
        }
        int temp_sum = accumulate(a.begin(), a.end(), 0);
        if (abs(temp_sum) > max_sum) max_sum = abs(temp_sum);
        for (int i = 0; i < a.size() - 1; i++) a[i] = a[i + 1] - a[i];
        a.pop_back();
    }
    cout << max_sum << endl;
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
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;

void solve() {
    int n, max_sum = INT_MIN;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1) {
        cout << a[0] << endl;
        return;
    }
    while (a.size() >= 1) {
        // vector < int > temp1(a.size() - 1), temp2(a.size() - 1), reverse_a(a.size());
        // for (int i = 0; i < a.size(); i++) reverse_a[i] = a[a.size() - i - 1];
        // for (int i = 0; i < a.size() - 1; i++) temp1[i] = a[i + 1] - a[i];
        // for (int i = 0; i < a.size() - 1; i++) temp2[i] = reverse_a[i + 1] - reverse_a[i];
        // int sum1, sum2, sum3;
        // sum1 = accumulate(a.begin(), a.end(), 0);
        // sum2 = accumulate(temp1.begin(), temp1.end(), 0);
        // sum3 = accumulate(temp2.begin(), temp2.end(), 0);
        // if (max_sum < max({sum1, sum2, sum3})) max_sum = max(sum1, sum2, sum3);


        int temp_sum = accumulate(a.begin(), a.end(), 0);
        // if (abs(temp_sum) > max_sum) max_sum = abs(temp_sum);
        // if (a.size() == 1) max_sum = max(temp_sum, max_sum);
        max_sum = max(max_sum, max(temp_sum, -temp_sum));
        for (int i = 0; i < a.size() - 1; i++) a[i] = a[i + 1] - a[i];
        a.pop_back();
    }
    cout << max_sum << endl;
}

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

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

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

#define int long long
using namespace std;

void solve() {
    int n, max_sum = INT_MIN;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1) {
        cout << a[0] << endl;
        return;
    }
    while (a.size() >= 1) {
        if (a.size() == 1) {
            // Here the other operations will not be valid
            max_sum = max(max_sum, a[0]);
            break;
        }
        int sum1 = accumulate(a.begin(), a.end(), 0); // original sum
        // operation 1 has no effect on sum but operation 1 and operation 2 will have. operation 2 will also have
        int sum2 = * (a.end() - 1) - * a.begin(); // sum by performing operation 2. sum 3 = -sum2
        max_sum = max({
            max_sum,
            sum1,
            sum2,
            -sum2
        });
        for (int i = 0; i < a.size() - 1; i++) a[i] = a[i + 1] - a[i];
        a.pop_back();
    }
    cout << max_sum << endl;
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
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;

void solve() {
    int n, max_sum = INT_MIN;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    while (a.size() >= 1) {
        // vector < int > temp1(a.size() - 1), temp2(a.size() - 1), reverse_a(a.size());
        // for (int i = 0; i < a.size(); i++) reverse_a[i] = a[a.size() - i - 1];
        // for (int i = 0; i < a.size() - 1; i++) temp1[i] = a[i + 1] - a[i];
        // for (int i = 0; i < a.size() - 1; i++) temp2[i] = reverse_a[i + 1] - reverse_a[i];
        // int sum1, sum2, sum3;
        // sum1 = accumulate(a.begin(), a.end(), 0);
        // sum2 = accumulate(temp1.begin(), temp1.end(), 0);
        // sum3 = accumulate(temp2.begin(), temp2.end(), 0);
        // if (max_sum < max({sum1, sum2, sum3})) max_sum = max(sum1, sum2, sum3);


        int temp_sum = accumulate(a.begin(), a.end(), 0);
        // if (abs(temp_sum) > max_sum) max_sum = abs(temp_sum);
        if (a.size() == 1) max_sum = max(temp_sum, max_sum);
        else max_sum = max(max_sum, abs(temp_sum));
        for (int i = 0; i < a.size() - 1; i++) a[i] = a[i + 1] - a[i];
        a.pop_back();
    }
    cout << max_sum << endl;
}

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

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

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

#define int long long
using namespace std;

void solve() {
    int n, max_sum = INT_MIN;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1) {
        cout << a[0] << endl;
        return;
    }
    while (a.size() >= 1) {
        // vector < int > temp1(a.size() - 1), temp2(a.size() - 1), reverse_a(a.size());
        // for (int i = 0; i < a.size(); i++) reverse_a[i] = a[a.size() - i - 1];
        // for (int i = 0; i < a.size() - 1; i++) temp1[i] = a[i + 1] - a[i];
        // for (int i = 0; i < a.size() - 1; i++) temp2[i] = reverse_a[i + 1] - reverse_a[i];
        // int sum1, sum2, sum3;
        // sum1 = accumulate(a.begin(), a.end(), 0);
        // sum2 = accumulate(temp1.begin(), temp1.end(), 0);
        // sum3 = accumulate(temp2.begin(), temp2.end(), 0);
        // if (max_sum < max({sum1, sum2, sum3})) max_sum = max(sum1, sum2, sum3);


        int temp_sum = accumulate(a.begin(), a.end(), 0);
        // if (abs(temp_sum) > max_sum) max_sum = abs(temp_sum);
        // if (a.size() == 1) max_sum = max(temp_sum, max_sum);
        max_sum = max(max_sum, max(temp_sum, -temp_sum));
        for (int i = 0; i < a.size() - 1; i++) a[i] = a[i + 1] - a[i];
        a.pop_back();
    }
    cout << max_sum << endl;
}

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

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: GNU C11


Submission (verdict: Wrong answer on test 2):
//given a sequence of n positive integers(+ve)

//Select an index i (1??<n), and subtract min(ai,ai+1) from both ai  and ai+1

#include<stdio.h>

#include<string.h>



int min(int a, int b){

    if (a<b){

        return a;

    }

    else {

        return b;

    }

}



int main(){

    int t;

    scanf("%d",&t);

    while(t!=0){

        int n;

        scanf("%d",&n);

        int arr[n];

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

            scanf("%d",&arr[i]);

        }

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

            printf("NO\n");

            t-=1;

            continue;

        }

        int flag=1;



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

            if(arr[i]>arr[i+1]){

                int r=min(arr[i],arr[i-1]);

                arr[i]-=r;

                arr[i-1]-=r;

                if(arr[i]>arr[i+1]){

                    printf("NO\n");

                    flag=0;

                    break;

                }

            }

        }



        if(flag){

            printf("YES\n");

        }

        t-=1;

    }



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: GNU C11

Previous submission (verdict: Wrong answer on test 1):
//given a sequence of n positive integers(+ve)

//Select an index i (1??<n), and subtract min(ai,ai+1) from both ai  and ai+1

#include<stdio.h>

#include<string.h>



int min(int a, int b){

    if (a<b){

        return a;

    }

    else {

        return b;

    }

}



int main(){

    int t;

    scanf("%d",&t);

    while(t!=0){

        int n;

        scanf("%d",&n);

        int arr[n];

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

            scanf("%d",&arr[i]);

        }

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

            printf("NO\n");

            t-=1;

            continue;

        }

        int flag=1;

        int max=0;



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

            if(arr[i]>arr[i+1]){

                int r=min(arr[i],arr[i-1]);

                arr[i]-=r;

                arr[i-1]-=r;

                if(arr[i]>arr[i+1]  || arr[i-1]<max){

                    printf("NO\n");

                    flag=0;

                    break;

                }

            }

            max=arr[i-1];

        }



        if(flag){

            printf("YES\n");

        }

        t-=1;

    }



    return 0;

}

Submission (verdict: Accepted):
//given a sequence of n positive integers(+ve)

//Select an index i (1??<n), and subtract min(ai,ai+1) from both ai  and ai+1

#include<stdio.h>

#include<string.h>



int min(int a, int b){

    if (a<b){

        return a;

    }

    else {

        return b;

    }

}



int main(){

    int t;

    scanf("%d",&t);

    while(t!=0){

        int n;

        scanf("%d",&n);

        int arr[n];

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

            scanf("%d",&arr[i]);

        }

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

            printf("NO\n");

            t-=1;

            continue;

        }

        int flag=1;

        int max=0;



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

            

            int r=min(arr[i],arr[i-1]);

            arr[i]-=r;

            arr[i-1]-=r;

            if(arr[i]>arr[i+1]  || arr[i-1]<max){

                printf("NO\n");

                flag=0;

                break;

            }

            

            max=arr[i-1];

        }



        if(flag){

            printf("YES\n");

        }

        t-=1;

    }



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: GNU C11

Previous submission (verdict: Wrong answer on test 2):
//given a sequence of n positive integers(+ve)

//Select an index i (1??<n), and subtract min(ai,ai+1) from both ai  and ai+1

#include<stdio.h>

#include<string.h>



int min(int a, int b){

    if (a<b){

        return a;

    }

    else {

        return b;

    }

}



int main(){

    int t;

    scanf("%d",&t);

    while(t!=0){

        int n;

        scanf("%d",&n);

        int arr[n];

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

            scanf("%d",&arr[i]);

        }

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

            printf("NO\n");

            t-=1;

            continue;

        }

        int flag=1;

        int max=0;



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

            if(arr[i]>arr[i+1]){

                int r=min(arr[i],arr[i-1]);

                arr[i]-=r;

                arr[i-1]-=r;

                if(arr[i]>arr[i+1]  || arr[i-1]<max){

                    printf("NO\n");

                    flag=0;

                    break;

                }

                max=arr[i-1];

            }

        }



        if(flag){

            printf("YES\n");

        }

        t-=1;

    }



    return 0;

}

Submission (verdict: Wrong answer on test 1):
//given a sequence of n positive integers(+ve)

//Select an index i (1??<n), and subtract min(ai,ai+1) from both ai  and ai+1

#include<stdio.h>

#include<string.h>



int min(int a, int b){

    if (a<b){

        return a;

    }

    else {

        return b;

    }

}



int main(){

    int t;

    scanf("%d",&t);

    while(t!=0){

        int n;

        scanf("%d",&n);

        int arr[n];

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

            scanf("%d",&arr[i]);

        }

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

            printf("NO\n");

            t-=1;

            continue;

        }

        int flag=1;

        int max=0;



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

            if(arr[i]>arr[i+1]){

                int r=min(arr[i],arr[i-1]);

                arr[i]-=r;

                arr[i-1]-=r;

                if(arr[i]>arr[i+1]  || arr[i-1]<max){

                    printf("NO\n");

                    flag=0;

                    break;

                }

            }

            max=arr[i-1];

        }



        if(flag){

            printf("YES\n");

        }

        t-=1;

    }



    return 0;

}