Cod sursa(job #1847279)

Utilizator Ruxandra985Nanu Ruxandra Laura Ruxandra985 Data 14 ianuarie 2017 14:32:50
Problema Nivele Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <cstdio>
#include <algorithm>

using namespace std;
int v[50001],s[50001];
int main()
{
    FILE *fin=fopen ("nivele.in","r");
    FILE *fout=fopen ("nivele.out","w");
    int t,i,n,elem,nr;
    fscanf (fin,"%d",&t);
    for (;t>0;--t){
        fscanf (fin,"%d",&n);
        for (i=1;i<=n;i++)
            fscanf (fin,"%d",&v[i]);
       // sort (v+1,v+n+1);
        elem=0;
        for (i=1;i<=n;i++){
            nr=v[i];
            while (elem>0 && nr==s[elem]){
                elem--;
                nr--;
            }
            if (nr)
                s[++elem]=nr;
        }
        if (elem>1 || s[1]!=1)
            fprintf (fout,"NU\n");
        else fprintf (fout,"DA\n");
    }
    return 0;
}