Not able to find which edge case I am missing out

//Works fine for all the test cases which i can think of,then too i am getting WA.Please help!!
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
int main()
{
ull t{},n{};
cin>>t;
while(t–>0)
{
cin>>n;
ull x{};
stack s{};
priority_queue pq{};
for(ull i=0;i<n;i++)
{
cin>>x;
s.push(x);
}
ull x1{},x2{};
bool flag=true;
while(s.size()!=1)
{
x1=s.top();
s.pop();
if(x1>s.top())
{
flag=false;
x2=s.top();
s.pop();
pq.push(x2);
s.push(x1);
if(pq.size()==1)
{
s.push(pq.top());
}
else
{
stack temp{};
while(!pq.empty())
{
ull t1=pq.top();
pq.pop();
temp.push(t1);
}
while(!temp.empty())
{
ull t1=temp.top();
temp.pop();
s.push(t1);
}
}
break;
}
else
{
pq.push(x1);
}
}
if(flag==true)
{
cout<<"-1"<<endl;
}
else
{
string str;
string ts;
while(!s.empty())
{
ts=to_string(s.top());
str+=ts;
s.pop();
}
reverse(str.begin(),str.end());
cout<<str<<endl;
}
}
return 0;
}

Mind giving more details? Like the problem link?

1 Like

This might help you

1 Like

Try this:
1
5
1 3 0 5 4

Your Output: 13504
Actual Output: 13405

3 Likes

thanks bro!!!

2 Likes