PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: sushil2006
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
There are N bowling balls, the i-th has weight A_i.
Chef can use a ball if its weight is between X and Y, inclusive.
How many of the N balls are usable by Chef?
EXPLANATION:
Simply loop through all the balls and count the number of them that satisfy the given condition on weights.
That is, initialize the answer to 0, and then for each i from 1 to N, add 1 to the answer if X \leq A_i \leq Y.
Print the answer after the loop.
TIME COMPLEXITY:
\mathcal{O}(N) per testcase.
CODE:
Editorialist's code (PyPy3)
for _ in range(int(input())):
n, x, y = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
ans += x <= a[i] <= y
print(ans)