help me to understand this error in this code for the above question?
my code is:
t = int(input())
for i in range(t):
n = int(input())
p = list(map(int,input().split()))
w = list(map(int,input().split()))
p.sort()
w.sort()
l=[]
for i in range(len(p)):
for j in range(len(w)):
if p[i]<w[j]:
l.append(l[i])
print(len(l))
my error is:
Traceback (most recent call last):
File “./prog.py”, line 1, in
EOFError: EOF when reading a line
problem link:COOLING Problem - CodeChef
Just paste the testcases in the input section and run the program; this will resolve the issue.
Also your program is trying to access empty list (named as l).
Try below solution
t = int(input())
for i in range(t):
n = int(input())
p = list(map(int,input().split()))
w = list(map(int,input().split()))
p.sort()
w.sort()
l=[]
for i in range(len(p)):
for j in range(len(w)):
if p[i] <= w[j]:
l.append(p[i])
w.remove(w[j])
break
print(len(l))
(or)
t = int(input())
for i in range(t):
n = int(input())
p = list(map(int,input().split()))
w = list(map(int,input().split()))
p.sort()
w.sort()
ans = 0
for i in range(len(p)):
for j in range(len(w)):
if p[i] <= w[j]:
ans += 1
w.remove(w[j])
break
print(ans)