Help me in lostmax

LOSTMAX :Code Chef is saying the code is wrong even though it works fine when I run it. Please tell why is this happening.(BTW I am new to programming)

#include<iostream>
#include<string>
#include<sstream>

int main()
{
    int N=0,T,w=0,l,i=0,cnt;
    long A[51]={0},res[101]={0};
    std::string line;
    std::cin>>T;
    do
    {
        getline(std::cin,line);
        std::stringstream s (line);
        l=0;
        while(l<=51)
            {
                s>>A[l];
                l++;
            }
        for(cnt=0;;)
            if(A[cnt]!='\0')
                cnt++;
            else
                break;
        N=cnt;
        if(A[0]!=N-1)
            res[i]=A[0];
        for(int j=0;j<N-1;j++)
            if(A[j]<A[j+1]&&A[j+1]!=(N-1))
                res[i]=A[j+1];
        i++;
    }while(i<=T);
    for(int k=1;k<=T;k++)
        std::cout<<res[k]<<"\n";
    return 0;
}

Your code fails this test case-

Input
1
3 3 2 2
Your Output
0
Expected Output
3

The box has 3 numbers, which are {2,2,3}. The largest one is 3. Yes, Numbers can repeat, and box can contain N (in this case, 3) as well.