Pankaj8433's blog

By Pankaj8433, history, 10 months ago, In English

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();
}

}

Full text and comments »

  • Vote: I like it
  • -16
  • Vote: I do not like it