Cod sursa(job #2045114)

Utilizator LeVladzCiuperceanu Vlad LeVladz Data 21 octombrie 2017 20:41:43
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>

using namespace std;

ifstream fin("nivele.in");
ofstream fout("nivele.out");

int T,n,a[50001],stiv[50001],k,i;

int main()
{
    fin >> T;
    for (;T--;)
    {
        fin >> n;
        for (i=1; i<=n; i++)
            fin >> a[i];
        stiv[1] = a[1];
        k = 1;
        for (i=2; i<=n; i++)
        {
            stiv[++k] = a[i];
            while (k > 1 && stiv[k] == stiv[k-1])
                stiv[--k]--;
        }
        if (k == 1 && stiv[1] == 1)
            fout << "DA" << "\n";
        else
            fout << "NU" << "\n";
    }
    return 0;
}