 # RUNCOMPARE - Editorial

Author: iceknight1093
Testers: wuhudsm, satyam_343
Editorialist: iceknight1093

TBD

None

# PROBLEM:

Alice and Bob ran for N days each, with distances A_i and B_i on the i-th day, respectively.
On a given day, each person is unhappy if the other one ran more than twice their distance; and happy otherwise.

On how many of the days were both Alice and Bob happy?

# EXPLANATION:

On the i-th day,

• Alice is happy if B_i \leq 2\cdot A_i
• Bob is happy if A_i \leq 2\cdot B_i

So, they’re both happy only when both conditions are true simultaneously.

This leads to a rather simple solution: using a loop and a conditional statement, simply count the number of i such that (A_i \leq 2\cdot B_i) and (B_i \leq 2\cdot A_i).

# TIME COMPLEXITY

\mathcal{O}(N) per test case.

# CODE:

Editorialist's code (Python)
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
if a[i] <= 2*b[i] and b[i] <= 2*a[i]: ans += 1
print(ans)