Advertisement
jules0707

dot_product

Jun 21st, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. # Uses python3
  2. import sys
  3.  
  4.  
  5. def max_dot_product(p, q):
  6.     # we just sort the two lists
  7.     p.sort()
  8.     q.sort()
  9.     res = 0
  10.     # and multiply them dot for dot
  11.     for i in range(len(p)):
  12.         res += p[i] * q[i]
  13.     return res
  14.  
  15.  
  16. if __name__ == '__main__':
  17.     user_input = sys.stdin.read()
  18.     data = list(map(int, user_input.split()))
  19.     n = data[0]
  20.     a = data[1:(n + 1)]
  21.     b = data[(n + 1):]
  22.     print(max_dot_product(a, b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement