Cod sursa(job #3165968)

Utilizator Beverita2345Bretan Alexandru Beverita2345 Data 7 noiembrie 2023 11:49:22
Problema Nivele Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMAX = 50003;
int st[NMAX], top;

int main() {

    int t;
    fin >> t;
    while (t--) {
        int n;
        fin >> n;
        top = 0;
        for (int i = 1; i <= n; i++) {
            int x;
            fin >> x;
            while (top > 0 && x == st[top]) {
                x--;
                top--;
            }
            st[++top] = x;
        }
        if (top > 1 || st[top] != 1) {
            fout << "NU\n";
        } else {
            fout << "DA\n";
        }
    }


    return 0;
}