Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Output
- # 11
- # Explanation
- # 2 -> temp sum = 2 | max sum = 2;
- # 3 -> temp sum = 2 + 3 | max sum = 5;
- # -6 -> temp sum = 5 - 6 | max sum = 5;
- # -1 -> temp sum = 0 - 1 | max sum = 5;
- # 2 -> temp sum = 0 + 2 | max sum = 5;
- # -1 -> temp sum = 2 - 1 | max sum = 5;
- # 6 -> temp sum = 6 + 1 | max sum = 7;
- # 4 -> temp sum = 7 + 4 | max sum = 11;
- # -8 -> temp sum = 11 - 8| max sum = 11;
- # 8 -> temp sum = 3 + 8 | max sum = 11;
- n = int(input())
- max_sum = 0
- temp_sum = 0
- for i in range(n):
- number = int(input())
- if temp_sum < 0:
- temp_sum = 0
- temp_sum += number
- else:
- temp_sum += number
- if temp_sum > max_sum:
- max_sum = temp_sum
- print(max_sum)
Advertisement
Add Comment
Please, Sign In to add comment