here is the link to the problem https://www.codechef.com/JUNE20B/problems/CHFICRM I have two written two different codes both are working fine according to me but still getting wrong answer this is my second approach. https://www.codechef.com/JUNE20B/problems/CHFICRM please some can help me ou.....
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n;
k=5;
stack<int> s;
int b=1;
for(int i=0;i<n;i++)
{
int d;
cin>>d;
int y;
y=d-k;
if(y==0)
{
s.push(d);
continue;
}
if(s.empty() && d>5)
{
b--;
cout<<"NO"<<endl;
break;
}
while(!s.empty())
{
int z=y-s.top();
if(z==0)
{
s.pop();
s.push(d);
break;
}
else if(z>0){
s.pop();
if(s.empty())
{
cout<<"NO"<<endl;
b--;
break;
}
continue;
}
else if(z<0){
cout<<"NO"<<endl;
b--;
break;
}
}
if(b==0)
{
break;
}
}
if(b)
cout<<"YES"<<endl;
}
return 0;
}