Doubt regarding my solution

why is this solution partially correct??
#include <bits/stdc++.h>

using namespace std;

int main()
{

int t;
cin>>t;
while(t–)
{

      int n;
      cin>>n;
      long long int mat[n][n],i,j,max=0;
      vector<long long int > v(n);
      
      
      long long int sum=0;
      int flag=0;
      
      for(i=0;i<n;++i)
        {
            for(j=0;j<n;++j)
              {
                  cin>>mat[i][j];
              }
        }
        
      for(j=0;j<n;++j)
       {
           if(max<mat[n-1][j])
              max=mat[n-1][j];
       }
       
      v.push_back(max);
      
      for(i=n-2;i>=0;--i)
        {
            max=0;
            flag=0;
            for(j=0;j<n;++j)
              {
                  if(mat[i][j]<v[v.size()-1])
                    {
                        if(max<mat[i][j])
                           max=mat[i][j];
                           
                         flag=1;  
                    }
              }
            
            if(flag==0)
               break;
               
            else
              v.push_back(max);
              
        }
        
      
       if(flag==0)
          cout<<"-1"<<endl;
          
      else
       {
           for(i=0;i<v.size();++i)
               sum+=v[i];
               
            cout<<sum<<endl;   
       }

}

return 0;    

}

Format your code and give link to your question. For formatting use ``` symbol at the start and the end of code.

Can you share a link to the question or tell the question’s code plese

1 Like

this is the question