ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fi first
#define se second
#define ld long double
ll n,m,k;
vector<ll> arr;
ll mod=pow(10,9)+7;
void Haggag(){
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  cin>>n>>k;
  arr.resize(n);
  for (int i = 0; i < n; i++)
  {
    cin>>arr[i];
  }
  sort(arr.begin(),arr.end());
  ll ans=1;
  for (int i = k+1; i < n; i++)
  {
    if(arr[i]!=arr[i-1])ans++;
    
  }
  cout<<ans<<endl;
}
int main(){
  Haggag(); 
  int t=1;
  cin>>t;
  for (int i = 1; i <= t; i++)
  { 
    // cout<<"Case #"<<i<<": "<<endl;
    solve();
  }
  return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fi first
#define se second
#define ld long double
ll n,m,k;
vector<ll> arr;
ll mod=pow(10,9)+7;
void Haggag(){
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  cin>>n>>k;
  arr.resize(n);
  for (int i = 0; i < n; i++)
  {
    cin>>arr[i];
  }
  sort(arr.begin(),arr.end());
  vector<pair<ll,ll>> sarr;
  sarr.push_back(make_pair(1,arr[0]));
  for (int i = 1; i < n; i++)
  {
    if(arr[i]!=arr[i-1]){
      sarr.push_back(make_pair(1,arr[i]));
    }
    else{
      sarr.back().first++;
    }
  }
  sort(sarr.begin(),sarr.end());
  ll i=0;
  while (k>0)
  {
    if(k<sarr[i].first)break;
    k-=sarr[i].first;
    i++;
  }
  cout<<max(int(sarr.size()-i),1)<<endl;
  
  
  
  
}
int main(){
  Haggag(); 
  int t=1;
  cin>>t;
  for (int i = 1; i <= t; i++)
  { 
    // cout<<"Case #"<<i<<": "<<endl;
    solve();
  }
  return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 4):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fi first
#define se second
#define ld long double
ll n,m,k;
vector<pair<ll,ll> > arr;
ll mod=pow(10,9)+7;
void Haggag(){
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  cin>>n>>k;
  arr.clear();
  multiset<ll> st;
  for (int i = 0; i < n; i++)
  {
    ll num;cin>>num;
    if(st.count(num)==0){
      arr.push_back(make_pair(0,num));
    }
    st.insert(num);
  }
  for (int i = 0; i < arr.size(); i++)
  {
    arr[i].first=st.count(arr[i].second);
    // cout<<arr[i].se<<' ';
  }
  // cout<<endl;
  sort(arr.begin(),arr.end());
  ll i=0;
  while (k>0)
  {
    if(arr[i].first>k)break;
    k-=arr[i].first;
    i++;
  }
  cout<<max(int(arr.size()-i),1)<<endl;
  // cout<<arr.size()<<endl;
}
int main(){
  Haggag(); 
  int t=1;
  cin>>t;
  for (int i = 1; i <= t; i++)
  { 
    // cout<<"Case #"<<i<<": "<<endl;
    solve();
  }
  return 0;
}


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fi first
#define se second
#define ld long double
ll n,m,k;
vector<ll> arr;
ll mod=pow(10,9)+7;
void Haggag(){
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  cin>>n>>k;
  arr.resize(n);
  for (int i = 0; i < n; i++)
  {
    cin>>arr[i];
  }
  sort(arr.begin(),arr.end());
  ll ans=1;
  for (int i = k+1; i < n; i++)
  {
    if(arr[i]!=arr[i-1])ans++;
    
  }
  cout<<ans<<endl;
}
int main(){
  Haggag(); 
  int t=1;
  cin>>t;
  for (int i = 1; i <= t; i++)
  { 
    // cout<<"Case #"<<i<<": "<<endl;
    solve();
  }
  return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 4):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define fi first
#define se second
#define ld long double
ll n,m,k;
vector<pair<ll,ll> > arr;
ll mod=pow(10,9)+7;
void Haggag(){
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  cin>>n>>k;
  arr.clear();
  multiset<ll> st;
  for (int i = 0; i < n; i++)
  {
    ll num;cin>>num;
    if(st.count(num)==0){
      arr.push_back(make_pair(0,num));
    }
    st.insert(num);
  }
  for (int i = 0; i < arr.size(); i++)
  {
    arr[i].first=st.count(arr[i].second);
    // cout<<arr[i].se<<' ';
  }
  // cout<<endl;
  sort(arr.begin(),arr.end());
  ll i=0;
  while (k>0)
  {
    if(arr[i].first>k)break;
    k-=arr[i].first;
    i++;
  }
  cout<<max(int(arr.size()-i),1)<<endl;
  // cout<<arr.size()<<endl;
}
int main(){
  Haggag(); 
  int t=1;
  cin>>t;
  for (int i = 1; i <= t; i++)
  { 
    // cout<<"Case #"<<i<<": "<<endl;
    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>
using namespace std;

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for(int i = 0; i < n-2; i++)
    {
        if(a[i] > a[i+1] && a[i+1] > a[i+2])
        {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

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

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}



//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ / 
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//
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;

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for(int i = 0; i < n-2; i++)
    {
        if(a[i] > a[i+1] && a[i+1] > a[i+2])
        {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

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

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}



//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ / 
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//



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

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    if(n == 2 && a[0] > a[1])
    {
        cout << "NO" << endl;
        return;
    }
    for(int i = 0; i < n-2; i++)
    {
        if(a[i] > a[i+1] && a[i+1] > a[i+2])
        {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

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

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}



//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ / 
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//
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;

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    if(n == 2 && a[0] > a[1])
    {
        cout << "NO" << endl;
        return;
    }
    for(int i = 0; i < n-2; i++)
    {
        if(a[i] > a[i+1] && a[i+1] > a[i+2])
        {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

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

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}



//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ / 
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//


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

#define X first
#define Y second
#define pb push_back
#define pii pair<int,int>
#define spacce cerr << "====" << endl
const int maxn = 2e5 + 5;
const int INF = 1e9;
const int MOD = 998244353;
void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for(int i = 0; i < n-1; i++)
    {
        if(a[i] > a[i+1])
        {
            cout << "NO" << endl;
            return;
        }
        a[i+1] -= a[i];
        a[i] = 0;
    }
    cout << "YES" << endl;
}

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

    bool tc = 1;
    int ttt = tc ? (cin >> ttt, ttt) : 1;

    while(ttt--)
        solve(), spacce;

    return 0;
}



//    _  __   ________   _      _____
//   / |/ /__/_  __/ /  (_)__  / ___/
//  /    / _ \/ / / _ \/ / _ \/ (_ / 
// /_/|_/\___/_/ /_//_/_/_//_/\___/   is real.
//
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 endl '\n'


int getSum(vector<long long int> arr){
    long long int res = 0;
    for(long long int el: arr) res+= el;
    return res;
}
void calc(vector<long long int>& arr){
    vector<long long int> res;
    for(int i = 1; i<arr.size(); i++){
        res.push_back(arr[i]-arr[i-1]);
    }
    arr.clear();
    arr = res;
}
void solve(){
    long long int n,e; cin>>n;
    vector<long long int> arr; while(arr.size()<n){cin>>e; arr.push_back(e);}
    
    long long int res = getSum(arr);
    long long int maxsum;
    while(arr.size()>1){
        calc(arr);
        maxsum = max(getSum(arr), -getSum(arr));
        res = max(res, maxsum);
    }
    maxsum = max(getSum(arr), -getSum(arr));
    if(n > 1) res = max(res, maxsum); 

    cout<<res<<endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tc; cin>>tc;
    while(tc--) solve();
}

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

using namespace std;
#define endl '\n'


long long int getSum(vector<long long int> arr){
    long long int res = 0;
    for(long long int el: arr) res+= el;
    return res;
}
void calc(vector<long long int>& arr){
    vector<long long int> res;
    for(int i = 1; i<arr.size(); i++){
        res.push_back(arr[i]-arr[i-1]);
    }
    arr.clear();
    arr = res;
}
void solve(){
    long long int n,e; cin>>n;
    vector<long long int> arr; while(arr.size()<n){cin>>e; arr.push_back(e);}
    
    long long int res = getSum(arr);
    long long int maxsum;
    while(arr.size()>1){
        calc(arr);
        maxsum = max(getSum(arr), -getSum(arr));
        res = max(res, maxsum);
    }
    maxsum = max(getSum(arr), -getSum(arr));
    if(n > 1) res = max(res, maxsum); 

    cout<<res<<endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tc; cin>>tc;
    while(tc--) solve();
}
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 endl '\n'


int getSum(vector<int> arr){
    int res = 0;
    for(int el: arr) res+= el;
    return res;
}
void calc(vector<int>& arr){
    vector<int> res;
    for(int i = 1; i<arr.size(); i++){
        res.push_back(arr[i]-arr[i-1]);
    }
    arr.clear();
    arr = res;
}
void solve(){
    int n,e; cin>>n;
    vector<int> arr; while(arr.size()<n){cin>>e; arr.push_back(e);}
    
    int res = getSum(arr);
    int maxsum;
    while(arr.size()>1){
        calc(arr);
        maxsum = max(getSum(arr), -getSum(arr));
        res = max(res, maxsum);
    }
    maxsum = max(getSum(arr), -getSum(arr));
    if(n > 1) res = max(res, maxsum); 

    cout<<res<<endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tc; cin>>tc;
    while(tc--) solve();
}

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

using namespace std;
#define endl '\n'


int getSum(vector<long long int> arr){
    long long int res = 0;
    for(long long int el: arr) res+= el;
    return res;
}
void calc(vector<long long int>& arr){
    vector<long long int> res;
    for(int i = 1; i<arr.size(); i++){
        res.push_back(arr[i]-arr[i-1]);
    }
    arr.clear();
    arr = res;
}
void solve(){
    long long int n,e; cin>>n;
    vector<long long int> arr; while(arr.size()<n){cin>>e; arr.push_back(e);}
    
    long long int res = getSum(arr);
    long long int maxsum;
    while(arr.size()>1){
        calc(arr);
        maxsum = max(getSum(arr), -getSum(arr));
        res = max(res, maxsum);
    }
    maxsum = max(getSum(arr), -getSum(arr));
    if(n > 1) res = max(res, maxsum); 

    cout<<res<<endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tc; cin>>tc;
    while(tc--) solve();
}
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 endl '\n'


int getSum(vector<int> arr){
    int res = 0;
    for(int el: arr) res+= el;
    return res;
}
void calc(vector<int>& arr){
    vector<int> res;
    for(int i = 1; i<arr.size(); i++){
        res.push_back(arr[i]-arr[i-1]);
    }
    arr.clear();
    arr = res;
}
void solve(){
    int n,e; cin>>n;
    vector<int> arr; while(arr.size()<n){cin>>e; arr.push_back(e);}
    
    int res = getSum(arr);

    while(arr.size()>1){
        calc(arr);
        res = max(res, abs(getSum(arr)));
    }

    if(n > 1) res = max(res, abs(getSum(arr))); 

    cout<<res<<endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tc; cin>>tc;
    while(tc--) solve();
}
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 endl '\n'


int getSum(vector<int> arr){
    int res = 0;
    for(int el: arr) res+= el;
    return res;
}
void calc(vector<int>& arr){
    vector<int> res;
    for(int i = 1; i<arr.size(); i++){
        res.push_back(arr[i]-arr[i-1]);
    }
    arr.clear();
    arr = res;
}
void solve(){
    int n,e; cin>>n;
    vector<int> arr; while(arr.size()<n){cin>>e; arr.push_back(e);}
    
    int res = getSum(arr);

    while(arr.size()>1){
        calc(arr);
        res = max(res, abs(getSum(arr)));
    }

    if(n > 1) res = max(res, abs(getSum(arr))); 

    cout<<res<<endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tc; cin>>tc;
    while(tc--) solve();
}

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

using namespace std;
#define endl '\n'


int getSum(vector<int> arr){
    int res = 0;
    for(int el: arr) res+= el;
    return res;
}
void calc(vector<int>& arr){
    vector<int> res;
    for(int i = 1; i<arr.size(); i++){
        res.push_back(arr[i]-arr[i-1]);
    }
    arr.clear();
    arr = res;
}
void solve(){
    int n,e; cin>>n;
    vector<int> arr; while(arr.size()<n){cin>>e; arr.push_back(e);}
    
    int res = getSum(arr);
    int maxsum;
    while(arr.size()>1){
        calc(arr);
        maxsum = max(getSum(arr), -getSum(arr));
        res = max(res, maxsum);
    }
    maxsum = max(getSum(arr), -getSum(arr));
    if(n > 1) res = max(res, maxsum); 

    cout<<res<<endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int tc; cin>>tc;
    while(tc--) solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

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

    return 0;
}

Submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int sum=0;
        int idif=0;
        
        for(int i=0;i<n-1;i++){
            if(a[i]<a[i+1])sum++;
            else sum--;
            if(i==0){
                idif=(a[i]>=a[i+1])?-1:1;
            }
        }
        if(sum>=0 && idif>=0)cout<<"YES";
        else cout<<"NO";
        cout<<endl;
        
    }

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

Previous submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

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

    return 0;
}

Submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

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

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


Submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

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

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

Previous submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int f=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            
        }
        for(int i=0;i<n;i++){
            if(a[i]>a[i+1])f=1;
        }
        
        if(f==1){
            
        int mini=0;
        for(int i=0;i<n;i++){
            
            mini=min(a[i],a[i+1]);
            a[i]-=mini;
            a[i+1]-=mini;
        }
         f=1;
        for(int i=0;i<n;i++){
            if(a[i]>a[i+1])
            {
                f=0;
                break;
            }
            //cout<<a[i]<<" ";
            
        }
        (f==1)?cout<<"YES":cout<<"NO";
        
        }
        else cout<<"YES";
        cout<<endl;
        
    }

    return 0;
}

Submission (verdict: Accepted):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int f=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            
        }
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1])f=1;
        }
        
        if(f==1){
            
        int mini=0;
        for(int i=0;i<n-1;i++){
            
            mini=min(a[i],a[i+1]);
            a[i]-=mini;
            a[i+1]-=mini;
        }
         f=1;
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1])
            {
                f=0;
                break;
            }
            //cout<<a[i]<<" ";
            
        }
        (f==1)?cout<<"YES":cout<<"NO";
        
        }
        else cout<<"YES";
        cout<<endl;
        
    }

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

Previous submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int sum=0;
        int idif=0;
        
        for(int i=0;i<n-1;i++){
            if(a[i]<a[i+1])sum++;
            else sum--;
            if(i==0){
                idif=(a[i]>=a[i+1])?-1:1;
            }
        }
        if(sum>=0 && idif>=0)cout<<"YES";
        else cout<<"NO";
        cout<<endl;
        
    }

    return 0;
}

Submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int f=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            
        }
        for(int i=0;i<n;i++){
            if(a[i]>a[i+1])f=1;
        }
        
        if(f==1){
            
        int mini=0;
        for(int i=0;i<n;i++){
            
            mini=min(a[i],a[i+1]);
            a[i]-=mini;
            a[i+1]-=mini;
        }
         f=1;
        for(int i=0;i<n;i++){
            if(a[i]>a[i+1])
            {
                f=0;
                break;
            }
            //cout<<a[i]<<" ";
            
        }
        (f==1)?cout<<"YES":cout<<"NO";
        
        }
        else cout<<"YES";
        cout<<endl;
        
    }

    return 0;
}