-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Solution.java
40 lines (35 loc) · 1.15 KB
/
Solution.java
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
// github.com/RodneyShag
import java.util.Scanner;
// Time Complexity: O(m + n)
// Space Complexity: O(1)
public class Solution {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int s = scan.nextInt();
int t = scan.nextInt();
int a = scan.nextInt();
int b = scan.nextInt();
int m = scan.nextInt();
int n = scan.nextInt();
/* Calculate # of apples that fall on house */
int applesOnHouse = 0;
for (int i = 0; i < m; i++) {
int applePosition = a + scan.nextInt();
if (applePosition >= s && applePosition <= t) {
applesOnHouse++;
}
}
System.out.println(applesOnHouse);
/* Calculate # of oranges that fall on house */
int orangesOnHouse = 0;
for (int i = 0; i < n; i++) {
int orangePosition = b + scan.nextInt();
if (orangePosition >= s && orangePosition <= t) {
orangesOnHouse++;
}
}
System.out.println(orangesOnHouse);
scan.close();
}
}