g310:pD. 甜甜圈大對決(Donut)
Code
可AC的
n=int(input())
shop1=list(map(int,input().split()))
shop2=list(map(int,input().split()))
d1=d2=win=0
while 1:
if shop1[d1]>=shop2[d2]:
d2+=1
if d2==n:
break
else:
win+=1
d1+=1
if d1==n:
break
d2+=1
if d2==n:
break
print(win)
會TLE的
因為每個都要重頭跑,很浪費時間,所以會TLE
#n=3
#shop1=[60,80,100]
#shop2=[50,70,90]
n=int(input())
shop1=list(map(int,input().split()))
shop2=list(map(int,input().split()))
win=0
#取shop2最小可超過「shop1的d1」的d2
for d1 in range(len(shop1)):
for d2 in range(len(shop2)):
if shop2[d2]>shop1[d1]:
win+=1
shop2[d2]=-1
#print("win=",win)
#print(shop1,shop2)
break
#print("final win=",win)
print(win)