bounslay

Untitled

May 14th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # Output
  2. # 11
  3. # Explanation
  4. #  2 -> temp sum = 2     | max sum = 2;
  5. #  3 -> temp sum = 2 + 3 | max sum = 5;
  6. # -6 -> temp sum = 5 - 6 | max sum = 5;
  7. # -1 -> temp sum = 0 - 1 | max sum = 5;
  8. #  2 -> temp sum = 0 + 2 | max sum = 5;
  9. # -1 -> temp sum = 2 - 1 | max sum = 5;
  10. #  6 -> temp sum = 6 + 1 | max sum = 7;
  11. #  4 -> temp sum = 7 + 4 | max sum = 11;
  12. # -8 -> temp sum = 11 - 8| max sum = 11;
  13. #  8 -> temp sum = 3 + 8 | max sum = 11;
  14.  
  15. n = int(input())
  16.  
  17. max_sum = 0
  18. temp_sum = 0
  19. for i in range(n):
  20.  
  21.     number = int(input())
  22.  
  23.     if temp_sum < 0:
  24.         temp_sum = 0
  25.         temp_sum += number
  26.        
  27.     else:
  28.         temp_sum += number
  29.        
  30.    
  31.     if temp_sum > max_sum:
  32.         max_sum = temp_sum
  33.    
  34.  
  35.  
  36. print(max_sum)
Advertisement
Add Comment
Please, Sign In to add comment