runtime error

Revision en1, by Pankaj8433, 2024-01-07 16:28:46

I AM GETTING RUNTIME ERROR FOR INPUT 1 3 3 2 1 BUT NOT FOR 2 3 1 2 3 3 3 2 1 WHY??? PROBLEM NAME-Grouping Increases CONTEST NAME-Hello 2024

include <bits/stdc++.h>

using namespace std; int t;vectora;vectorv;

define ll long long

int main(){ cin>>t; while(t--){ ll sum=0; int n,b; cin>>n;

for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(v.empty()&&a.empty()) v.push_back(x);
        else if(a.empty()&&v.back()<x) a.push_back(x);
        else if(a.back()>=x&&v.back()>=x){
            if(a.back()>v.back()) v.push_back(x);
            else a.push_back(x);
        }
        else if(v.back()>=x)v.push_back(x);
        else if(a.back()<x && v.back()<x){
            sum++;
            if(a.back()>v.back()) v.push_back(x);
            else a.push_back(x);
        }
        else a.push_back(x);
    }
    cout<<sum<<endl;
    // for(auto x:v) cout<<x<<" ";cout<<endl;
    a.clear();
    v.clear();
}

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Pankaj8433 2024-01-07 16:28:46 1121 Initial revision (published)