Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. n, m = map(int, input().split())
  2. h = list(map(int, input().split()))
  3. a = list(map(int, input().split()))
  4. if n == m:
  5.   nowmin = min(h)
  6.   ans = 0
  7.   for i in range(n):
  8.     ans += (h[i] - nowmin) * a[i]
  9.   print(ans)
  10.   exit()
  11. ans = 1000000000000000000000
  12. for i in range(n - m):
  13.   nowmin = 100000000
  14.   for j in range(m):
  15.     nowmin = min(nowmin, h[i + j])
  16.   nowans = 0
  17.   for j in range(m):
  18.     nowans += (h[i + j] - nowmin) * a[i + j]
  19.   ans = min(ans, nowans)
  20. if ans == 1000000000000000000000:
  21.   print(0)
  22. else:
  23.   print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement