Alex_tz307

Secventa de suma maxima(+indici)

Sep 14th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. int st , dr, Smax = -2000000000 , S = -1, start;
  2. for(int i = 1 ; i <= n ; ++ i)
  3. {
  4.     if(S < 0)
  5.         S = 0, start = i;
  6.     S += A[i];
  7.     if(S > Smax)
  8.         Smax = S, st = start, dr = i;
  9. }
  10. cout << Smax << endl;
  11. cout << st << " " << dr;
Add Comment
Please, Sign In to add comment