#K72177. Taco Contest Participation
Taco Contest Participation
Taco Contest Participation
You are given the wake-up and sleep times of n friends over a 24-hour day. Each friend is awake during a specific time interval. Note that some intervals might wrap around midnight. Your task is to determine if there exists at least one hour in the day during which all friends are simultaneously awake.
For each friend, the awake interval is described by two integers:
- If \(w < s\), the friend is awake during the interval \([w, s)\).
- If \(w \ge s\), the friend is awake during \([w, 24) \cup [0, s)\), meaning the period crosses midnight.
If there exists at least one hour where every friend is awake, output YES
. Otherwise, output NO
.
inputFormat
The input is given via standard input (stdin) and consists of three lines:
- The first line contains an integer (n) ((1 \le n \le 100)), representing the number of friends.
- The second line contains (n) space-separated integers representing the wake-up times.
- The third line contains (n) space-separated integers representing the sleep times.
outputFormat
Output a single line to standard output (stdout):
Print YES
if there exists at least one hour during which all friends are awake; otherwise, print NO
.## sample
3
6 9 12
18 22 21
YES