Can someone please tell me why is this code not being accepted? <b>Note:I am not asking for a solution, just tell me where this code fails.</b> : [link to problem.][1]


  [1]: https://www.codechef.com/JAN18/problems/MAXSC

#include<stdio.h>

int main()

{
    long long int n, t, k, i, j, max[701], a[701][701], sum, flag;
 
    scanf( "%lld", &t );

    for( k = 0 ; k < t ; k++ )
    { 
        scanf( "%lld", &n );

        for( i = 1 ; i <= n ; i++ )
        {  
            for( j = 1 ; j <= n ; j++ )
            { 
                scanf( "%lld", &a[i][j] );
                if( j == 1)
                    max[i] = a[i][1];
                if( a[i][j] > max[i] )
                    max[i] = a[i][j];
            }
        }

        sum = 0, flag = 0;

        for( i = 1 ; i <= n-1 ; i++ )
        { 
            if( max[i] &lt; max[i+1])
                sum = sum + max[i];
            else
            {
                flag = 1;
                break;
            }
        }

        if(flag == 1)
            printf("-1\n");
        else
        {
            sum = sum + max[n-1];
            printf("%lld\n", sum );
        }
    }
}





Compute the maximum possible value of E1 + E2 + ... + EN. If it's impossible to pick the elements E1, E2, ..., EN, print -1 instead.

and a constraint:
You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1.

does this constraint mean we have to choose max element from each line?

If you look at example given:
Example
Input:

1

3

1 2 3

4 5 6

7 8 9

Output:

18
Explanation
Example case 1: To maximise the score, pick 3 from the first row, 6 from the second row and 9 from the third row. The resulting sum is E1+E2+E3 = 3+6+9 = 18.

if you notice they have mentioned "maximize".

Though my code finds the max, it isn't being accepted.
 