Problem p02623 (python)

Fixed submission:
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = [0]
bsum = [0]
ans = 0
for i in range(anum):
    asum.append(asum[i]+alist[i])
for i in range(bnum):
    bsum.append(bsum[i]+blist[i])

b = bnum
for a in range(anum+1):
    if asum[a] > acc:
        break
    while asum[a] + bsum[b] > acc:
        b -=1
    ans = max(ans,a+b)

print(ans)

Buggy submission (verdict: Runtime Error):
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = 0;bsum = 0
ans = 0;a = 0;b = 0
while asum + alist[a] <= acc:
    asum += alist[a];a+=1
    if a == anum:
        break

while asum + blist[b] <= acc:
    bsum += blist[b];b += 1
    if b == bnum:
        break

if a == 0 and b == 0:
    pass
elif b == bnum:
    ans = a + b
else:
    ans = a + b
    for i in range(a):
        while asum - alist[a-(i+1)] + bsum + blist[b] <= acc:
            bsum += blist[b];b += 1
            if a + b > ans:
                ans = a + b
            if b == bnum:
                break

print(ans)

Buggy submission (verdict: Runtime Error):
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = 0;bsum = 0
ans = 0;a = 0;b = 0
while asum + alist[a] <= acc:
    asum += alist[a];a+=1
    if a == anum:
        break

while asum + blist[b] <= acc:
    bsum += blist[b];b += 1
    if b == bnum:
        break

if a == 0 and b == 0:
    pass
elif (a == anum and b == bnum) or a == 0:
    ans = a + b
else:
    ans = a + b
    for i in range(a):
        while asum - alist[a-(i+1)] + bsum + blist[b] <= acc:
            bsum += blist[b];b += 1
            if a + b > ans:
                ans = a + b
            if b == bnum:
                break

print(ans)

Buggy submission (verdict: Runtime Error):
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = 0;bsum = 0
ans = 0;a = 0;b = 0
while asum + alist[a] <= acc:
    asum += alist[a];a+=1
    if a == anum:
        break

while asum + blist[b] <= acc:
    bsum += blist[b];b += 1
    if b == bnum:
        break

if a == 0 and b == 0:
    pass
elif (a == anum and b == bnum) or a == 0:
    ans = a + b
else:
    ans = a + b
    for i in range(a):
        while asum - alist[a-(i+1)] + bsum + blist[b] <= acc:
            if b == bnum:
                break
            bsum += blist[b];b += 1
            if a + b > ans:
                ans = a + b

print(ans)

Buggy submission (verdict: Runtime Error):
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asum = 0;bsum = 0
ans = 0;a = 0;b = 0
while asum + alist[a] <= acc:
    asum += alist[a];a+=1
    if a == anum:
        break

while asum + blist[b] <= acc:
    bsum += blist[b];b += 1
    if b == bnum:
        break

if a == 0 and b == 0:
    pass
elif (a == anum and b == bnum) or a == 0:
    ans = a + b
else:
    ans = a+b
    for i in range(1,a):
        while asum - alist[a-i] + bsum + blist[b] <= acc:
            if b == bnum:
                break
            bsum += blist[b];b += 1
            if a + b > ans:
                ans = a + b

print(ans)

Buggy submission (verdict: Runtime Error):
alen,blen,k = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
max = 0

bcount = blen
while sum(blist[:bcount]) > k:
    bcount -= 1
if bcount != 0:
    bsum = sum(blist[:bcount])
for a in range(alen+1):
    acount = alen-a
    asum = sum(alist[:acount])
    if bcount != 0:
        while asum + bsum > k:
            bcount -= 1
            bsum -= blist[bcount-1]
    if acount + bcount > max and asum + sum(blist[:bcount])<=k:
        max = acount + bcount

print(max)