Advertisement
PlotnikovPhilipp

Untitled

Oct 27th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. number = int(input())
  3. arr = [int(i) for i in input().split()]
  4. arr1 = []
  5. i = 0
  6. j = 1
  7. flag = True
  8. while i < len(arr):
  9.     if arr[i] < 0:
  10.         flag = False
  11.     if j % 2 == 0:
  12.         arr1.append(-arr[i])
  13.     else:
  14.         arr1.append(arr[i])
  15.     i += 1
  16.     j += 1
  17. if flag:
  18.     best1 = arr1[0]
  19.     summ = 0
  20.     for i in arr1:
  21.         summ = max(i, i + summ)
  22.         best1 = max(best1, summ)
  23.     print(best1)
  24. else:
  25.     arr2 = []
  26.     i = 1
  27.     j = 1
  28.     while i < len(arr):
  29.         if j % 2 == 0:
  30.             arr2.append(-arr[i])
  31.         else:
  32.             arr2.append(arr[i])
  33.         i += 1
  34.         j += 1
  35.     best1 = 0
  36.     best2 = 0
  37.     for i in arr1:
  38.         best1 += i
  39.     for i in arr2:
  40.         best2 += i
  41.     if best1 > best2:
  42.         print(best1)
  43.     elif 0 > best1 and 0 > best2:
  44.         print(0)
  45.     else:
  46.         print(best2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement