Pagini recente » Borderou de evaluare (job #475783) | Borderou de evaluare (job #2551011) | Borderou de evaluare (job #508236) | Borderou de evaluare (job #739572) | Cod sursa (job #2629413)
#include <fstream>
#include <stack>
using namespace std;
ifstream cin("nivele.in");
ofstream cout("nivele.out");
int tst,n,poz,v[50005];
stack<int> st;
int main()
{
cin>>tst;
for(int w=1;w<=tst;++w)
{
cin>>n;
for(int i=1;i<=n;++i)
cin>>v[i];
st.push(1);
poz=1;
while(poz<=n and !st.empty())
{
int x=st.top(); st.pop();
if(v[poz]==x) ++poz;
else if(v[poz]<x) break;
else st.push(x+1),st.push(x+1);
}
if(poz<=n or !st.empty()) cout<<"NU"<<'\n';
else cout<<"DA"<<'\n';
while(!st.empty()) st.pop();
}
return 0;
}