Advertisement
Doktorkrab

Untitled

Apr 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. n, k, s = map(int, input().split())
  2. arr = []
  3. arr.append(list(map(int, input().split())))
  4. arr.append(list(map(int, input().split())))
  5. x, y = map(int, input().split())
  6. arr1 = []
  7. for i in range(1, k + 1):
  8.     arr1.append([])
  9.     for j in range(n):
  10.         arr1[-1].append(arr[0][j] * i + arr[1][j])
  11. max_chet = 0
  12. for i in range(n):
  13.     new_i = i
  14.     chet = arr1[k-1][new_i]
  15.     for j in range(k - 1, -1, -1):
  16.         if y + new_i < n and j > 0:
  17.             if new_i - x > 0:
  18.                 if arr1[j - 1][new_i] >= arr1[j - 1][new_i + y] and arr1[j - 1][new_i] >= arr1[j - 1][new_i - x]:
  19.                     chet +=arr1[j-1][new_i]
  20.                 elif arr1[j - 1][new_i + y] > arr1[j - 1][new_i] and arr1[j - 1][new_i + y] > arr1[j - 1][new_i - x]:
  21.                     chet +=arr1[j-1][new_i+y]
  22.                     new_i += y
  23.                 else:
  24.                     chet +=arr1[j-1][new_i-x]
  25.                     new_i -= x
  26.             else:
  27.                 if arr1[j - 1][new_i] > arr1[j - 1][new_i + y]:
  28.                     chet += arr1[j-1][new_i]
  29.                 else:
  30.                     chet += arr1[j-1][new_i+y]
  31.                     new_i += y
  32.         elif new_i - x > 0 and j > 0:
  33.             if arr1[j - 1][new_i] > arr1[j - 1][new_i - x]:
  34.                 chet += arr1[j-1][new_i]
  35.             else:
  36.                 chet += arr1[j-1][new_i-x]
  37.                 new_i -= x
  38.         elif j > 0 and new_i - x <= 0 and new_i + y >= n:
  39.             chet +=arr1[j-1][new_i]
  40.     max_chet = max(max_chet,chet)
  41. print(max_chet+arr[0][s-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement