Skip to content

Instantly share code, notes, and snippets.

@kanghyojun
Created May 7, 2017 14:55
Show Gist options
  • Save kanghyojun/60656cd62f9ec22c017d40dd0f26260d to your computer and use it in GitHub Desktop.
Save kanghyojun/60656cd62f9ec22c017d40dd0f26260d to your computer and use it in GitHub Desktop.
n = int(input())
a = [
int(x)
for x in input().split(" ")
]
b = [
int(x)
for x in input().split(" ")
]
#a = [1, 1, 1, 6, 0]
#b = [2, 7, 8, 3, 1]
assert len(a) == len(b) == n
sorted_a = sorted([(x, i) for i, x in enumerate(a)])
sorted_b = sorted([(x, i) for i, x in enumerate(b)], reverse=True)
print(
sum(
x * sorted_a[sorted_b.index((x, i))][0]
for i, x in enumerate(b)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment