Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

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

cnt = 0
while K > 0:
    if len(A) == 0:
        if K >= B[0]:
            K = K - B[0]
            B.pop(0)
            cnt += 1
        else:
            break
    elif len(B) == 0:
        if K >= A[0]:
            K = K - A[0]
            A.pop(0)
            cnt += 1
        else:
            break
    elif A[0] < B[0]:
        if K >= A[0]:
            K = K - A[0]
            A.pop(0)
            cnt += 1
        else:
            break
    else:
        if K >= B[0]:
            K = K - B[0]
            B.pop(0)
            cnt += 1
        else:
            break

print(cnt)

Submission status: Wrong Answer

Solution code:
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N, M, K = map(int, input().split())

    As = map(int, input().split())
    Bs = map(int, input().split())

    mod = 10**9+7

    count = 0
    total = 0

    a = next(As)
    b = next(Bs)

    n = 1
    m = 1

    while total <= K:

        if a == b == mod:
            count += 1
            break

        elif a > b:
            total += b
            if m < M:
                m += 1
                b = next(Bs)
            else:
                b = mod
        else:
            total += a
            if n < N:
                n += 1
                a = next(As)
            else:
                a = mod

        count += 1

    return count - 1


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
n,m,k = map(int,input().split())
a = list(map(int,input().split()))+[10**9+1]*m
b = list(map(int,input().split()))+[10**9+1]*n
Sum = 0
ans = 0
a_i = 0
b_i = 0
N = n+m

for _ in range(N):
    if a[a_i] < b[b_i]:
        Sum += a[a_i]
        a_i += 1
    else:
        Sum += b[b_i]
        b_i += 1
    if Sum > k:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans,t=0,0
i,j=0,0
while 1:
    if i>=n and j>=m:
        break
    elif i>=n:
        t+=b[j]
        j+=1
    elif j>=m:
        t+=a[i]
        i+=1
    else:
        if a[i]<=b[j]:
            t+=a[i]
            i+=1
        else:
            t+=b[j]
            j+=1
    if t<=k:
        ans+=1
    else:
        break
print(ans)
#print(t)

Submission status: Wrong Answer

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

q = []
r = []

for i in range(len(A)):
    q.append([sum(A[:i+1]), i+1])
for i in range(len(B)):
    r.append([sum(B[:i+1]), i+1])
ret = 0
for t1, v1 in q:
    for t2, v2 in r:
        if t1+t2 <= K:
            ret = max(v1+v2, ret)
        else:
            break
print(ret)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
SA = sum(A)
SB = sum(B)

if sum(A) + sum(B) <= k:
    print(len(A) + len(B))
else:
    t = 0
    ai = 0; bi = 0
    while True:
        if bi == m:
            t += A[ai]
            ai += 1
        elif ai == n:
            t += B[bi]
            bi += 1
        elif A[ai] < B[bi]:
            t += A[ai]
            ai += 1
        else:
            t += B[bi]
            bi += 1

        if t >= k:
            break
    print(ai + bi - 1)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answer=0
numbers=[]
a=0
b=0
while a<N and b<M:
    if A[a]>=B[b]:
        numbers.append(B[b])
        b+=1
    else:
        numbers.append(A[a])
        a+=1

if a<N:
    for a in A[a:]:
        numbers.append(a)
else:
    for b in B[b:]:
        numbers.append(b)
whole=0
for a in range(N+M):
    whole+=numbers[a]
    if whole<=K:
        answer+=1
print(answer)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
end = 10 ** 9 + 1
alist.append(end)
blist.append(end)
time = 0
book = 0
for i in range(len(alist)+len(blist)-2):
    if alist[0] >= blist[0]:
        time += blist.pop(0)
        book += 1
    else:
        time += alist.pop(0)
        book += 1
    if time > k:
        book -= 1
        break

print(book)

Submission status: Wrong Answer

Solution code:
import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
ans=0
if sum(a)+sum(b)<=k:
    print(n+m)
    sys.exit()
a.append(10**10)
b.append(10**10)
for i in range(4*10**5):
    if a[0]==min(a[0],b[0]):
        cnt+=a.pop(0)
    else:
        cnt+=b.pop(0)
    if cnt>k:
        print(ans)
        break
    ans+=1

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
time = 0
while True:

    if not a and not b:
        break
    elif a and not b:
        m = a[0]
        a.pop(0)
    elif not a and b:
        m = b[0]
        b.pop(0)
    else:
        m = min(a[0], b[0])
        if m == a[0]:
            a.pop(0)
        if m == b[0]:
            b.pop(0)
    
    time += m
    if time > k:
        break

    ans += 1
    
print(ans)

Submission status: Wrong Answer

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

count = 0
while(True):
    if len(A)==0 and len(B)==0:
        break

    elif len(A)==0:
        if K-B[0]<0:
            break
        K -= B[0]
        B = B[1:]
    elif len(B)==0:
        if K-A[0]<0:
            break
        K -= A[0]
        A = A[1:]
    else:
        if K-A[0]<0 and K-B[0]<0:
            break
        if A[0] < B[0]:
            K -= A[0]
            A = A[1:]
        else:
            K -= B[0]
            B = B[1:]
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
'''
Created on 2020/06/27

@author: harurun
'''
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
now=[A[0],B[0]]
A.pop(0)
B.pop(0)
num=0
time=0
for x in range(1,N+M-1):
    now.sort()
    time += now[0]
    now.pop(0)
    if not A:
        now.append(B[0])
        B.pop(0)
    elif not B:
        now.append(A[0])
        A.pop(0)
    else:
        if A[0]>B[0]:
            now.append(B[0])
            B.pop(0)
        else :
            now.append(A[0])
            A.pop(0)

    if time>K:
        break
    else:
        num += 1
print(num)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
time = 0
count = 0
while time < K:
    if len(A) > 0 and len(B) > 0:
        if A[0] < B[0]:
            time += A.pop(0)
            count += 1
        else:
            time += B.pop(0)
            count += 1
    elif len(A) > 0:
        time = A.pop(0)
        count += 1
    elif len(B) > 0:
        time = B.pop(0)
        count += 1
    else:
        break

if time <= K:
    print(count)
else:
    print(count -1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.reverse()
b.reverse()
ans = 0

for i in range(n + m):
    cost = 0
    if a[-1] > b[-1]:
        cost = b[-1]
        b.pop(-1)
    else:
        cost = a[-1]
        a.pop(-1)
    
    k -= cost
    if k < 0:
        break
    elif len(a) == 0:
        a.append(float('inf'))
    elif len(b) == 0:
        b.append(float('inf'))
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum = 0
count = 0
i = 0
j = 0
while sum <= k:
    if i == n and j == m:
        print(count)
        exit()
    elif i == n:
        sum += b[j]
        j += 1
        count += 1
    elif j == m:
        sum += a[i]
        i += 1
        count += 1
    else:
        if a[i] > b[j]:
            sum += b[j]
            j += 1
            count += 1
        else :
            sum += a[i]
            i += 1
            count += 1

print(count-1)

Submission status: Wrong Answer

Solution code:

N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list( map(int, input().split()) )

books = 0

p1 = 0
p2 = 0

while K > 0 and ( p1 < N and p2 < M ):
    books += 1

    if p1 < N and A[p1] < B[p2]:
        # print("chosen", "p1", p1)
        K -= A[p1]
        p1 += 1

    elif p2 < M:
        # print("chosen", "p2", p2)
        K -= B[p2]
        p2 += 1

    # print(K, p1, p2)

# print(K)

if K < 0:
    books -= 1
    print(books)

elif K == 0:
    print(books)

else:
    if p1 < N:
        while K > 0 and p1 < N:
            books += 1
            K -= A[p1]
            p1 += 1

    if p2 < M:
        while K > 0 and p2 < M:
            books += 1
            K -= B[p2]
            p2 += 1

    if K < 0:
        books -= 1
    print(books)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

inda = 0
indb = 0
ans = 0

while True:
    if inda == len(a) and indb == len(b):
        break

    else:
        if inda != len(a) and indb != len(b):
            if a[inda] >= b[indb]:
                zzz = b[indb]
                if k >= zzz:
                    k -= zzz
                    indb += 1
                    ans += 1
                else:
                    break
            elif a[inda] < b[indb] or indb == len(b):
                zzz = a[inda]
                if k >= zzz:
                    k -= zzz
                    inda += 1
                    ans += 1
                else:
                    break
        elif inda == len(a):
            zzz = b[indb]
            if k >= zzz:
                k -= zzz
                indb += 1
                ans += 1
            else:
                break
        else:
            zzz = a[inda]
            if k >= zzz:
                k -= zzz
                inda += 1
                ans += 1
            else:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
qa = deque(A)
qb = deque(B)
ans = 0
total = 0
for i in range(n+m):
    if n > 0 and m > 0:
        if qa[0] >= qb[0]:
            p = qb.popleft()
            total += p
            m -= 1
        else:
            p = qa.popleft()
            total += p
            n -= 1
        ans += 1
    elif m == 0 and n > 0:
        p = qa.popleft()
        total += p
        n -= 1
        ans += 1
    elif n == 0 and m > 0:
        p = qb.popleft()
        total += p
        m -= 1
        ans += 1
    if total > k:
        print(ans - 1)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split(" "));
arr = list(map(int,input().split(" ")));
brr = list(map(int,input().split(" ")));
i = 0;
j = 0;
cur = 0;
c = 0;
while(i<n and j<m):
  if(arr[i] > brr[j]):
    if(k >= cur + brr[j]):
      c+=1;
      cur+=brr[j];
      j+=1;
    else:
      break;
  else:
    if(k >= cur + arr[i]):
      c+=1;
      cur+=arr[i];
      i+=1;
    else:
      break;
while(i<n):
  if(k >= cur + arr[i]):
      c+=1;
      cur+=arr[i];
      i+=1;
  else:
    break;
while(j<m):
  if(k >= cur + brr[j]):
    c+=1;
    cur+=brr[j];
    j+=1;
  else:
    break;
print(c);

Submission status: Wrong Answer

Solution code:
n,m,k=map(float,input().split())
a=  list(map(float,input().split()))
b =  list(map(float,input().split()))

from collections import deque
a = deque(a)
b = deque(b)
# print(len(a),len(b))
c = 0
ans = 0
while (len(a)>0 or len(b)>0):
    if len(a)>0 and len(b)>0: 
        if (a[0]<b[0])&(a[0]<k):
                k-=a[0]
                a.pop()
                ans +=1
                # print("a")
        elif (a[0]>=b[0])&(b[0]<k):
                k-=b[0]
                b.pop()
                ans+=1
                # print("b")
        
        else:
                c=1
                break
    elif len(a)==0 :
        if b[0]>k:
            break
        else:
            k-=b[0]
            b.pop()
            ans +=1

    elif len(b)==0 :
        if a[0]>k:
            break
        else:
            k-=a[0]
            a.pop()
            ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M, K =  map(int, input().split())

if N <= M:
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

if N > M:
    B_list = list(map(int, input().split()))
    A_list = list(map(int, input().split()))

    N, M = M, N

A_cum = np.cumsum([0] + A_list)
B_cum = np.cumsum(B_list)

# A list is always smaller

max_books = 0

for ind in range(len(A_cum)):
    A_books = ind
    budget = K - A_cum[ind]

    if budget <= 0:
        continue
    B_books = np.searchsorted(B_cum, budget, side="right")


    Total = A_books + B_books

    if Total > max_books:
        max_books = Total


print(max_books)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
minutes = 0
ct = 0
while minutes < k:
    if n >0 and m>0:
        if min(A[0],B[0]) == A[0]:
            if minutes + A[0] <=k:
                n -= 1
                minutes += A[0]
                A.remove(A[0])
                ct +=1
            else:
                break
        elif min(A[0],B[0]) == B[0]:
            if minutes + B[0] <=k:
                m -= 1
                minutes += B[0]
                B.remove(B[0])
                ct +=1
            else:
                break
    elif n >0:
        if minutes + A[0] <=k:
                n -= 1
                minutes += A[0]
                A.remove(A[0])
                ct +=1
        else:
            break
    elif m >0:
        if minutes + B[0] <=k:
                m -= 1
                minutes += B[0]
                B.remove(B[0])
                ct +=1
        else:
            break
    else:
        break

print(ct)

Submission status: Wrong Answer

Solution code:
n ,m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

an = 0
bn = 0
time = 0
count = 0

for _ in range(10**6):
    if a[an] < b[bn]:
        time += a[an]
        if an < n-1:
             an += 1
        else:
            a[an] = float('inf')
    else:
        time += b[bn]
        if bn < m-1:
            bn += 1
        else:
            b[bn] = float('inf')
    if time <= k:
        count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = list(map(int, input().split()))
    INF = 1e+10
    A = [INF, ] + list(map(int, input().split()))[::-1]
    B = [INF, ] + list(map(int, input().split()))[::-1]
    a = A.pop()
    b = B.pop()
    s = 0
    ans = 0
    while s <= k:
        if ans == n + m:
            print(ans)
            exit()
        if a <= b:
            s += a
            a = A.pop()
        else:
            s += b
            b = B.pop()
        ans += 1
    print(ans - 1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ia, ib = 0, 0
ca, cb = 0, 0
t = 0
cnt = 0
INF = 9876543210

while True:
    if a:
        ca = a[0]
    else:
        ca = INF
    
    if b:
        cb = b[0]
    else:
        cb = INF
    
    if ca >= cb:
        t += cb
        if b:
            b.pop()
    elif ca < cb:
        t += ca
        if a:
            a.pop()
    
    if t > k:
        break
    
    cnt += 1

    if cnt == n+m:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.append(10**9+1)
b.append(10**9+1)
rest=k
ans=-1
ai=0
bi=0
while rest>=0 and ai+bi<n+m:
    ans+=1
    if a[ai]<=b[bi]:
        rest-=a[ai]
        ai+=1
    else:
        rest-=b[bi]
        bi+=1
if ai+bi==n+m:
  ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

maxmin = 0
ct = 0
ai = 0
bi = 0

while(maxmin <= k):
  nextbook = 0
  if(ai<n and bi<m):
    if(a[ai]<b[bi]):
      nextbook = a[ai]
      ai += 1
    else:
      nextbook = b[bi]
      bi += 1
  elif(ai>=n and bi>=m):
    break
  elif(ai<n and bi>=m):
    nextbook = a[ai]
    ai += 1
  else:
    nextbook = b[bi]
    bi += 1
  
  if(maxmin + nextbook <= k):
    maxmin += nextbook
    ct += 1
  else:
    break
    
print(ct)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=deque(a)
B=deque(b)
ans=0
SUM=0
while True:
    if len(A)>0 and len(B)>0:
        if A[0]>=B[0]:
            x=B.popleft()
        else:
            x=A.popleft()
    elif len(A)==0 and len(B)>0:
        x=B.popleft()
    elif len(A)>0 and len(B)==0:
        x=A.popleft()
    else:
        break
    
    if SUM+x<=k:
        SUM+=x
        ans+=1
    else:
        break
    #print(A,B,ans,SUM)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
import sys

input = sys.stdin.buffer.readline
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AA = list(accumulate([0] + A))
BB = list(accumulate([0] + B))
apos = bisect_right(A, k)

bpos = bisect_right(B, k)
j = 0
ans = 0
for i in range(apos, -1, -1):
    temp_a = AA[i]
    remain = k - temp_a
    while j <= bpos:
        if remain >= BB[j]:
            j += 1
        else:
            break
    ans = max(ans, i + j - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n, m , k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

cum_A = [A[0]]
for i in range(1, n):
    cum_A.append(cum_A[-1]+A[i])
cum_B = [B[0]]
for i in range(1, m):
    cum_B.append(cum_B[-1]+B[i])
ans = 0
for i in range(n+1):
    #  i is the number of book from A
    if i == 0:
        target = k
        ind = bisect_left(cum_B, target)
        ans = max(ans, i+ind)
    else:
        tmp_ans = cum_A[i-1]
        if tmp_ans > k:
            break
        target = k - tmp_ans
        ind = bisect_left(cum_B, target+0.5)
        ans = max(ans, i+ind)
print(ans)

Submission status: Wrong Answer

Solution code:
x = input().split()
y = input().split()
z = input().split()
s = 0
for nn in range(2000000):
    y.append(10000000001)
    z.append(10000000001)
for nn in range(2000000):
    print(x[2])
    if int(x[2]) < 0:
        break
    if int(y[0]) <= int(z[0]) :
        x[2] = int(x[2]) - int(y[0])
        del y[0]   
        s += 1
    else:
        x[2] = int(x[2]) - int(z[0])
        del z[0]
        s += 1
print(s-1)

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m,k=nm()
a=nl()
b=nl()

sm=0

ai=0
bi=0

cnt=0

books = []

for i in range(n+m):
  if ai==n:
    books.append(b[bi])
    bi+=1
  elif bi==m:
    books.append(a[ai])
    ai+=1
  elif a[ai] < b[bi]:
    books.append(a[ai])
    ai+=1
  else:
    books.append(b[bi])
    bi+=1

for i in range(n+m):
  if sm+books[i]<=k:
    sm+=books[i]
    cnt+=1
  else:
    break

print(cnt)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = time = sel = 0
while time <= K:
  if len(A) == len(B) == 0:
    break
  if len(B) == 0:
    if K >= time + A[0]:
      count += 1
      time += A[0]
      del A[0]
      continue
    else:
      break
  if len(A) == 0:
    if K >= time + B[0]:
      count += 1
      time += B[0]
      del B[0]
      continue
    else:
      break 
  if A[0] <= B[0]:
    if K >= time + A[0]:
      count += 1
      time += A[0]
      del A[0]
    else:
      break
  else:
    if K >= time + B[0]:
      count += 1
      time += B[0]
      del B[0]
    else:
      break
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = tuple(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for _ in range(len(a)+len(b)):
    if len(a) + len(b) == 0:
        break
    if len(a) == 0:
        if b[0] > k:
            break
        k -= b[0]
        ans += 1
        del b[0]
    elif len(b) == 0:
        if a[0] > k:
            break
        k -= a[0]
        ans += 1
        del a[0]
    elif a[0] <= b[0]:
        if a[0] > k:
            break
        k -= a[0]
        ans += 1
        del a[0]
    else:
        if b[0] > k:
            break
        k -= b[0]
        ans += 1
        del b[0]

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
ai      = list(map(int, input().split()))
bi      = list(map(int, input().split()))

books   = 0
minutes = 0

while True:
    if len(ai) != 0 and len(bi) != 0:
        if ai[0] <= bi[0]:
            if minutes + ai[0] > k: break

            books += 1
            minutes += ai[0]
            ai = ai[1:]

        else:
            if minutes + bi[0] > k: break

            books += 1
            minutes += bi[0]
            bi = bi[1:]

    else:
        if len(ai) == 0 and len(bi) != 0:
            if minutes + bi[0] > k: break

            books += 1
            minutes += bi[0]
            bi = bi[1:]

        elif len(ai) != 0 and len(bi) == 0:
            if minutes + ai[0] > k: break

            books += 1
            minutes += ai[0]
            ai = ai[1:]

        else:
            break

print(books)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))

sum = 0
book = 0
while (True):
    if (len(Alist) == 0):
        Alist.append(10000000000)
    elif(len(Blist) == 0):
        Blist.append(10000000000)

    if (Alist[0] < Blist[0]):
        if (k - Alist[0] >= 0):
            k -= Alist[0]
            Alist.pop(0)
            book += 1
        else:
            break
    else:
        if (k - Blist[0] >= 0):
            k -= Blist[0]
            Blist.pop(0)
            book += 1
        else:
            break

print(book)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = n
B = 0
if (a[0]>k):
    A = 0
for i in range(1,n):
    a[i] += a[i-1]
    if (a[i]>k):
        A = i
for i in range(1,m):
    b[i] += b[i-1]
if (a[0]>k):
    A = 0
ans = A
if (A==0):
        for i in range(m):
            if (b[i]>k):
                print(i)
                exit()
        print(len(b))
        exit()
a = [0] + a
b = [0] + b
while True:
    if (A<0):
        break
    if (B>=m):
        break
    B += 1
    #print(A,B)
    if (a[A]+b[B] >k):
        B -= 1
        A -= 1
    else:
        ans = max(ans,A+B)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A.append(100000000000)
    B.append(100000000000)
    a, b = 0, 0
    answer = 0

    while True:
        if A[a] < B[b]:
            going_to_read = A[a]
            a += 1
        else:
            going_to_read = B[b]
            b += 1

        if K >= going_to_read:
            answer += 1
            K -= going_to_read
        else: break

        if a == N and b == M: break

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

from collections import deque

a = deque(a)
b = deque(b)

ans = 0
time = k

while time >= 0:
    if a and b:
        tmp_a = time-a[0]
        tmp_b = time-b[0]
        if tmp_a >= 0 and tmp_b >= 0 and a[0] <= b[0]:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_a >= 0 and tmp_b >= 0 and b[0] <= a[0]:
            time -= b[0]
            b.popleft()
            ans += 1
        elif tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    elif a:
        tmp_a = time-a[0]
        if tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        else:
            break
    elif b:
        tmp_b = time-b[0]
        if tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split())) 
b = list(map(int, input().split())) 

i, j = 0, 0
ans = 0

mn = min(a[0], b[0])
k -= mn

while k > 0:
    # print(f'{i} {j}')
    s, t = a[i], b[j]
    
    mn = min(s, t)

    if s <= t and i < n-1:
        i += 1
    if s > t and j < m-1:
    # else:
        j += 1

    k -= mn

    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
S = 0
ans = 0
for i in range(M):
  S += B[i]
  if S > K:
    b = i - 1
    S -= B[i]
    break
  else:
    ans += 1
    if i==M-1:
      b = M-1
if b==0:
  ans = 0
  S = 0
  for a in A:
    if S + a <= K:
      S += a
      ans += 1
    else:
      break
  print(ans)
else:
  a = 0
  max_ans = ans
  while a<N:
    if S + A[a] <= K:
      S += A[a]
      ans += 1
      a += 1
    else:
      break
  max_ans = max(max_ans, ans)
  for j in range(b, -1, -1):
    S -= B[j]
    ans -= 1
    while a<N:
      if S + A[a] <= K:
        S += A[a]
        ans += 1
        a += 1
      else:
        break
      
    max_ans = max(max_ans, ans)
  print(max_ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
num = len(a) + len(b)
time = 0
for i in range(num):
    if len(a) >= 1 and len(b) >= 1:
        r = min(a[0], b[0])
        time += r
        if a[0] >= b[0]:
            b.remove(b[0])
        else:
            a.remove(a[0])
        if time >= k:
            break
    elif len(a) >= 1 and len(b) == 0:
        time += a[0]
        a.remove(a[0])
        if time >= k:
            break
    elif len(b) >= 1 and len(a) == 0:
        time += b[0]
        b.remove(b[0])
        if time >= k:
            break

if len(b) == 0 and len(a) == 0:
    print(i + 1)
else:
    print(i)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum=0
book_count=0
while True:
  if a!=[] and b!=[]:
    sum+=min(a[0],b[0])
    if sum>k:
      print(book_count)
      exit()
    else:
      book_count+=1
      if min(a[0],b[0])==a[0]:
        a.pop(0)
      else:
        b.pop(0)
  elif a==[] and b==[]:
    print(book_count)
    exit()
  elif a!=[] and b==[]:
    sum+=a[0]
    if sum>k:
      print(book_count)
      exit()
    else:
      book_count+=1
      a.pop(0)
  elif a==[] and b!=[]:
    sum+=b[0]
    if sum>k:
      print(book_count)
      exit()
    else:
      book_count+=1
      b.pop(0)
print(book_count)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int,input().split())
    from collections import deque
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ad = deque(a)
    bd = deque(b)
    cnt = 0
    inf = 10**18
    for i in range(m+n):
        if n > 0:
            p = ad.popleft()
        if m > 0:
            q = bd.popleft()
        if p == q:
            for j in range(min(n-1,m-1)):
                if ad[j] > bd[j]:
                    p += 1
                    break
                elif ad[j] < bd[j]:
                    q += 1
                    break
        if p == q:
            if n > m:
                p += 1
        if p < q:
            n -= 1
            bd.appendleft(q)
            k -= p
        else:
            ad.appendleft(p)
            m -= 1
            k -= q
        if k >= 0:
            cnt += 1
        if k <= 0:
            break
        p = inf
        q = inf
    print(cnt)              


if __name__ == '__main__':
    main()