-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12-Apple_and_Orange.py
76 lines (60 loc) · 2.06 KB
/
12-Apple_and_Orange.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 21 2023
@author Carlos Páez
"""
import math
#
# Complete the `countApplesAndOranges` function below.
#
# The function accepts following parameters:
# 1. INTEGER s
# 2. INTEGER t
# 3. INTEGER a
# 4. INTEGER b
# 5. INTEGER_ARRAY apples
# 6. INTEGER_ARRAY oranges
#
def countApplesAndOranges(s: int, t: int, a: int, b: int, apples: list[int], oranges: list[int]):
"""
It takes in a bunch of numbers, checks if they're valid, and then prints out the number of valid
apples and oranges.
:param s: starting point of Sam's house location
:type s: int
:param t: integer, the point where the house ends
:type t: int
:param a: starting point of Sam's house location
:type a: int
:param b: the location of the tree from which the oranges are thrown
:type b: int
:param apples: an array of integers representing the distances that each apple falls from point a
:type apples: list[int]
:param oranges: list[int]
:type oranges: list[int]
:return: The number of apples and oranges that fall on Sam's house.
"""
if not all(1 <= param <= 10**5 for param in (s, t, a, b)):
return 'Error'
valid_apples = [
apple for apple in apples
if -10 ** 5 <= apple <= 10**5 and s <= apple + a <= t
]
valid_oranges = [
orange for orange in oranges
if - 10**5 <= orange <= 10**5 and s <= orange + b <= t
]
print(len(valid_apples))
print(len(valid_oranges))
if __name__ == '__main__':
first_multiple_input = input().rstrip().split()
s = int(first_multiple_input[0])
t = int(first_multiple_input[1])
second_multiple_input = input().rstrip().split()
a = int(second_multiple_input[0])
b = int(second_multiple_input[1])
third_multiple_input = input().rstrip().split()
m = int(third_multiple_input[0])
n = int(third_multiple_input[1])
apples = list(map(int, input().rstrip().split()))
oranges = list(map(int, input().rstrip().split()))
countApplesAndOranges(s, t, a, b, apples, oranges)