There are N items in a grocery store, the i-th of which has freshness A_i and cost B_i. What is the cost of buying all items with a freshness of at least X?
EXPLANATION:
It is enough to do what is asked for:
Iterate i from 1 to N, and if A_i \geq X, add B_i to the answer.
This can be done with the help of a for loop and an if statement.
TIME COMPLEXITY:
\mathcal{O}(N) per testcase.
CODE:
Code (Python)
for _ in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
if a[i] >= x: ans += b[i]
print(ans)
Hi, thanks for your guidance, I was actually not familiar with the concept that i can take the input of the limit and then use that variable to define my array size. Therefore i tried to predefine my array size. I think that was what giving me the error at that time.
\