Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a=[0]
b=[0]

tmp_a=0
tmp_b=0
for i in A:
    tmp_a+=i
    a.append(tmp_a)

for i in B:
    tmp_b+=i
    b.append(tmp_b)
    

ans,j=0,M
for i in range(N+1):#i…A台の本数
    if a[i]>K:
        break
    while(1):
        if b[j]<=(K-a[i]):
            break
        j-=1
    ans=max(ans,i+j)
    
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())

A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]

a=0
b=0
ans=0
books=N+M
time=0


while(1):
    if a+b==books or time>=K:
        break
    
    elif (a!=N and b!=M):
        if A[a]>B[b]:
            if time+B[b]<=K:
                time+=B[b]
                b+=1
                ans+=1
            else:
                break
        
        elif B[b]>A[a]:
            if time+A[a]<=K:
                time+=A[a]
                a+=1
                ans+=1
            else:
                break
        
        else:
            if time+A[a]>K:
                break
            else:
                tmpa=a
                tmpb=b
                while(1):
                    tmpa+=1
                    tmpb+=1
                    if A[tmpa]>B[tmpb]:
                        if time+B[b]<=K:
                            time+=B[b]
                            b+=1
                            ans+=1
                            break
                        else:
                            break
                    
                    elif A[tmpa]<B[tmpb]:
                        if time+A[a]<=K:
                            time+=A[a]
                            a+=1
                            ans+=1
                            break
                        else:
                            break
            
    elif a==N and b!=M:
        if time+B[b]<=K:
            time+=B[b]
            b+=1
            ans+=1
        else:
            break
        
    elif b==M and a!=N:
        if time+A[a]<=K:
            time+=A[a]
            a+=1
            ans+=1
        else:
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())

A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]

a=0
b=0
ans=0
books=N+M
time=0


while(1):
    if a+b==books or time>=K:
        break
    
    elif (a!=N and b!=M):
        if A[a]>B[b]:
            if time+B[b]<=K:
                time+=B[b]
                b+=1
                ans+=1
            else:
                break
        
        elif B[b]>A[a]:
            if time+A[a]<=K:
                time+=A[a]
                a+=1
                ans+=1
            else:
                break
        
        else:
            if time+A[a]>K:
                break
            else:
                tmpa=a
                tmpb=b
                while(1):
                    tmpa+=1
                    tmpb+=1
                    if A[tmpa]>B[tmpb]:
                        if time+B[b]<=K:
                            time+=B[b]
                            b+=1
                            ans+=1
                        else:
                            break
                    
                    elif A[tmpa]<B[tmpb]:
                        if time+A[a]<=K:
                            time+=A[a]
                            a+=1
                            ans+=1
                        else:
                            break
            
    elif a==N and b!=M:
        if time+B[b]<=K:
            time+=B[b]
            b+=1
            ans+=1
        else:
            break
        
    elif b==M and a!=N:
        if time+A[a]<=K:
            time+=A[a]
            a+=1
            ans+=1
        else:
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())

A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]

a=0
b=0
ans=0
books=len(A)+len(B)
time=0


while(1):
    if a+b==books or time>=K:
        break
    
    elif (a!=N and b!=M):
        if A[a]>B[b]:
            if time+B[b]<=K:
                time+=B[b]
                b+=1
                ans+=1
            else:
                break
        
        elif B[b]>A[a]:
            if time+A[a]<=K:
                time+=A[a]
                a+=1
                ans+=1
            else:
                break
        
        else:
            if time+A[a]>K:
                break
            else:
                tmpa=a
                tmpb=b
                while(1):
                    tmpa+=1
                    tmpb+=1
                    if A[tmpa]>B[tmpb]:
                        if time+B[b]<=K:
                            time+=B[b]
                            b+=1
                            ans+=1
                        else:
                            break
                    
                    elif A[tmpa]<B[tmpb]:
                        if time+A[a]<=K:
                            time+=A[a]
                            a+=1
                            ans+=1
                        else:
                            break
            
    elif a==N and b!=M:
        time+=B[b]
        b+=1
        ans+=1
        
    elif b==M and a!=N:
        time+=A[a]
        a+=1
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())

A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]

a=0
b=0
ans=0
books=len(A)+len(B)
time=0


while(1):
    if a+b==books or time>=K:
        break
    
    elif (a!=N and b!=M):
        if A[a]>B[b]:
            if time+B[b]<=K:
                time+=B[b]
                b+=1
                ans+=1
            else:
                break
        
        elif B[b]>A[a]:
            if time+A[a]<=K:
                time+=A[a]
                a+=1
                ans+=1
            else:
                break
        
        else:
            if time+A[a]>K:
                break
            else:
                tmpa=a
                tmpb=b
                while(1):
                    tmpa+=1
                    tmpb+=1
                    if A[tmpa]>B[tmpb]:
                        time+=B[b]
                        b+=1
                        ans+=1
                        break
                    
                    elif A[tmpa]<B[tmpb]:
                        time+=A[a]
                        a+=1
                        ans+=1
                        break
            
    elif a==N and b!=M:
        time+=B[b]
        b+=1
        ans+=1
        
    elif b==M and a!=N:
        time+=A[a]
        a+=1
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())

A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]

a=0
b=0
ans=0
books=len(A)+len(B)
time=0


while(1):
    if a+b==books or time>=K:
        break
    
    elif (a!=N and b!=M):
        if A[a]>B[b]:
            if time+B[b]<=K:
                time+=B[b]
                b+=1
                ans+=1
            else:
                break
        
        elif B[b]>A[a]:
            if time+A[a]<=K:
                time+=A[a]
                a+=1
                ans+=1
            else:
                break
        
        else:
            if time+A[a]>K:
                break
            else:
                tmpa=a
                tmpb=b
                while(1):
                    tmpa+=1
                    tmpb+=1
                    if A[tmpa]>B[tmpb]:
                        time+=A[b]
                        b+=1
                        ans+=1
                        break
                    
                    elif A[tmpa]<B[tmpb]:
                        time+=A[a]
                        a+=1
                        ans+=1
                        break
            
    elif a==N:
        time+=B[b]
        b+=1
        ans+=1
    elif b==M:
        time+=A[a]
        a+=1
        ans+=1
print(ans)