title: Adding max elements from each row in 2D vector such that row element $A_i$ is less that $A_(i+1)$
body: <p>So, I what I want is to collect maximum element from each row(in a 2D vector) and push it into a new vector. And if the new vector is sorted I want the sum of all vector elements.</p>
  
  <p>I tried it but the code is showing error : 
  "cannot convert 'std::vector to 'int' assignment"</p>
  
  <p>also, is my code correct?</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;algorithm&gt;
  #include&lt;vector&gt;
  using namespace std;
  int main()
  {
  int t,n,v1;
  vector &lt; vector&lt;int&gt; &gt; vec;
  vector&lt;int&gt; max;
  cin&gt;&gt;t;
  while(t--)
  {
   cin&gt;&gt;n;
   for(int i=0; i&lt;n; i++)
   {  vector&lt;int&gt; row;
      for(int j=0; j&lt;n; j++)
      {
       int val;
        cin&gt;&gt;val;
        row.push_back(val);   
       }
       vec.push_back(row);
         }    
  
  for (int i=0; i&lt;n; i++)
  {
      for(int j=0; j&lt;n; j++)
      {
          v1=*max_element(vec.begin(), vec.end());
          max.push_back(v1);
      }
  }
  
  if(is_sorted(max.begin(),max.end()))
  {
      cout&lt;&lt;accumulate(max.begin(), max.end(),0)&lt;&lt;endl;
  
  }
  
  else
  cout&lt;&lt;"-1"&lt;&lt;endl;
  
  }
  return 0;
   }
  </code></pre>