Implementation
# 방법1
# Complete the countApplesAndOranges function below.
def countApplesAndOranges(s, t, a, b, apples, oranges):
# Computing distance
apples = [a + apple for apple in apples]
oranges = [b + orange for orange in oranges]
# apples & oranges in the range
in_apples = [apple for apple in apples if (apple >= s) and (apple <= t)]
in_oranges = [orange for orange in oranges if (orange >= s) and (orange <= t)]
# return the number of apples and oranges
return len(in_apples), len(in_oranges)
if __name__ == '__main__':
# starting, ending point
st = input().split()
s = int(st[0])
t = int(st[1])
# location of the Apple & Orange tree
ab = input().split()
a = int(ab[0])
b = int(ab[1])
# number of apples and oranges
mn = input().split()
m = int(mn[0])
n = int(mn[1])
apples = list(map(int, input().rstrip().split()))
oranges = list(map(int, input().rstrip().split()))
result = countApplesAndOranges(s, t, a, b, apples, oranges)
print('\n'.join(map(str, result)))
'HackerRank Algorithm' 카테고리의 다른 글
[HackerRank] 25. Cats and Mouse (0) | 2020.04.07 |
---|---|
[HackerRank] 24. Electronics shop (0) | 2020.04.07 |
[HackerRank] 22. Between Two Sets (0) | 2020.04.07 |
[HackerRank] 21. Birthday cake candles (0) | 2020.04.01 |
[HackerRank] 20. Birthday chocolate (0) | 2020.04.01 |
댓글