Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
326 B
2
Indexable
Never
void kadanes_algo()
{
   ll t;
   cin >> t;
   vector<ll>v;
   scan(t,v);

   ll maxSum=INT_MIN,currentSum=v[0];
   for(ll i=1; i<sz(v); i++)
   {
      currentSum += v[i];
      if(currentSum < 0)
      {
        currentSum=0;
      }
      maxSum = max(currentSum,maxSum);
   }
   cout << maxSum << endl;
}