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:
from collections import deque
n,m,k = map(int,input().split())
a = deque([int(i) for i in input().split()])
b = deque([int(i) for i in input().split()])
ans = 0
count = 0
while ans < k:
    if count % 2 == 0:
        try:
            ans1 = a.popleft()
        except Exception as e:
            pass
        ans += ans1
        count += 1
    else:
        try:
            ans2 = b.popleft()
        except Exception as e:
            pass
        ans += ans2
        count += 1
print(count-1)

Submission status: Wrong Answer

Solution code:
import math
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(10**10)
b.append(10**10)

if a[0]>k and b[0]>k:
  print(0)
else:
  if sum(a)+sum(b)<=k:
    print(n+m)
  else:
    ans=0
    time=0
    for i in range(n+m):
      ans += 1    
      if a[0]<=b[0]:
        time+=a.pop(0)
      else:
        time+=b.pop(0)
      
      if time>k:
        break
    print(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()))
count = 0
while K > 0:
    if A == []:
        K -= B.pop(0)
    elif B == []:
        K -= A.pop(0)
    else:
        K -= min(A[0],B[0])
        if A[0] > B[0]:
            del B[0]
        else:
            del A[0]
    if K >= 0:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
K = int(a[2])
Ai = input().split(" ")
Bi = input().split(" ")
Ai = [int(s) for s in Ai]
Bi = [int(s) for s in Bi]
time_ = int(K)
time0 = 0
acount = 0
bcount = 0

for i in range(10000000000000000):
    try:
        time0 += Ai[i]
        if time0 > time_:
            time0 -= Ai[i]
            break
        acount += 1
    except IndexError:
        break
atime = time0
time0 = 0
for i in range(10000000000000000):
    try:
        time0 += Bi[i]
        if time0 > time_:
            time0 -= Bi[i]
            break
        bcount += 1
    except IndexError:
        break
btime = time0
allc = bcount
if bcount > acount:
    hic = bcount
else:
    hic = acount
# AiからBiに移す
ci = 0
for i in range(acount):

    try:
        while time0 + Ai[i + ci] <= time_:
            time0 += Ai[i+ci]
            allc += 1
            ci += 1
            if hic < allc:
                hic = allc
    except IndexError:
        pass
    try:
        time0 -= Bi[bcount - 1]
        bcount -= 1
        allc -= 1
    except IndexError:
        pass
    try:
        while time0 + Ai[i+ci] <= time_:
            time0 += Ai[i+ci]
            allc += 1
            ci += 1
            if hic < allc:
                hic = allc
    except IndexError:
        break

print(hic)

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    n, m, k = map(int, input().split())
    a = deque(map(int, input().split()))
    b = deque(map(int, input().split()))
    asum = sum(a)
    bsum = sum(b)
    rk = asum + bsum - k
    time = 0
    bn = 0
    while (a or b):
        if time >= rk:
            break
        if a and b:
            if a[-1] > b[-1]:
                if time + a[-1] >= rk:
                    bn += 1
                    break
                else:
                    time += a.pop()
                    bn += 1
            else:
                if time + b[-1] >= rk:
                    bn +- 1
                    break
                else:
                    time += b.pop()
                    bn += 1
        elif a:
            if time + a[-1] >= rk:
                bn += 1
                break
            else:
                time += a.pop()
                bn += 1
        else:
            if time + b[-1] >= rk:
                bn += 1
                break
            else:
                bn += 1

    r = n + m - bn
    print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x = input().split()
N = int(x[0])
M = int(x[1])
K = int(x[2])
C =[]
A = input().split()
B = input().split()
A.append(10000000000)
B.append(10000000000)
for i in range(N + M):
    if int(A[0]) <= int(B[0]):
        C.append(int(A[0]))
        del A[0]
    else:
        C.append(int(B[0]))
        del B[0]

T = 0
book = 0
for i in range(len(C)):
    if T +C[i] <= K:
        T += C[i]
        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()))

time=0
book=0

while time<=k:
    if a and b:
        if a[0]<b[0]:
            time+=min(a[0], b[0])
            a.pop(0)
        else:
            time+=b[0]
            b.pop(0)
    elif b and (not a):
        time+=b[0]
        b.pop(0)
    elif a and (not b):
        time+=a[0]
        a.pop(0)
    else:
        break
        
    if time<=k:
    	book+=1
    else:
      break

print(book)

Submission status: Wrong Answer

Solution code:
from statistics import mean
N,M,K=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
k=0
c=0
if sum(a) + sum(b) <= K:
    print(N)
else:
    while k <= K:
        if len(a) > 0 and len(b)>0:
            if mean(a[:2]) < mean(b[:2]) and ((k+a[0]) <=K):
                k+=a[0]
                c+=1
                a.pop(0)
            elif mean(a[:2]) > mean(b[:2]) and ((k+b[0]) <=K):
                k+=b[0]
                c+=1
                b.pop(0)
            else:
                if (a[0] < b[0]) and ((k+a[0]) <=K):
                    k+=a[0]
                    c+=1
                    a.pop(0)

                elif (a[0] > b[0]) and ((k+b[0]) <=K):
                    k+=b[0]
                    c+=1
                    b.pop(0)
                else:
                    break
        elif (len(a) > 0) and (len(b) ==0):
            if ((k+a[0]) <=K):
                k+=a[0]
                c+=1
                a.pop(0)
            else:
                break
        elif (len(b) > 0) and (len(a) ==0):
            if ((k+b[0]) <=K):
                k+=b[0]
                c+=1
                b.pop(0)
            else:
                break
        else:
            break
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))

book = sorted(A + B)
now = 0
ans = 0

while now <= K:
    if len(A) != 0:
        a = A.popleft()
    else:
        a = -1
    if len(B) != 0:
        b = B.popleft()
    else:
        b = -1

    if a == -1 and b == -1:
        break
    elif a != -1 and b != -1:
        if a <= b:
            now += a
            B.appendleft(b)
            if now > K:
                break
            ans += 1
        else:
            now += b
            A.appendleft(a)
            if now > K:
                break
            ans += 1
    elif a != -1:
        now += b
        if now > K:
            break
        ans += 1
    elif b != -1:
        now += a
        if now > K:
            break
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
"""
AtCoder :: Beginner Contest 172 :: C :: Tsundoku
https://atcoder.jp/contests/abc172/tasks/abc172_c

"""
import sys
from math import inf


def solve(A, B, K):
    """Solve puzzle."""
    books_read = 0
    read_time = 0

    a = 0
    while a < len(A):
        book_time = A[a]
        if read_time + book_time > K:
            break
        else:
            read_time += book_time
            books_read += 1
            if a == len(A) - 1:
                break
            a += 1

    b = 0
    while b < len(B):
        book_time = B[b]
        if read_time + book_time > K:
            break
        else:
            read_time += book_time
            books_read += 1
            if b == len(B) - 1:
                break
            b += 1

    max_books = books_read

    for a0 in range(min(len(A)-1, a), -1, -1):
        read_time -= A[a0]
        books_read -= 1
        while b < len(B):
            book_time = B[b]
            if read_time + book_time > K:
                break
            else:
                read_time += book_time
                books_read += 1
                if b == len(B) - 1:
                    break
                b += 1
        max_books = max(max_books, books_read)

    return max_books


def main():
    """Main program."""
    N, M, K = (int(i) for i in sys.stdin.readline().split())
    A = [int(i) for i in sys.stdin.readline().strip().split()]
    B = [int(i) for i in sys.stdin.readline().strip().split()]
    print(solve(A, B, K))


if __name__ == '__main__':
    main()

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()))
if sum(A)+sum(B)<=K:
  print(len(A)+len(B))
elif sum(A)<K and sum(A)+sum(B)>K:
  ans=len(A)
  time=sum(A)
  for i in range(len(B)):
    time+=B[i]
    if time>K:
      print(ans)
    else:
      ans+=1
elif sum(B)<K and sum(A)+sum(B)>K:
  ans=len(B)
  time=sum(B)
  for i in range(len(A)):
    time+=A[i]
    if time>K:
      print(ans)
    else:
      ans+=1
else:
  ans=0
  time=0
  while len(A)!=0 and len(B)!=0 :
    time+=min(A[0],B[0])
    ans+=1
    if A[0]<B[0]:
      del A[0]
    else:
      del B[0]
    if time>K:
      print(ans-1)
      break

Submission status: Wrong Answer

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

A_it = list(it.accumulate(A))
B_it = list(it.accumulate(B))

A_index = bisect.bisect_left(A_it, K)
B_index = bisect.bisect_left(B_it, K)

A_it = [0]+A_it[:A_index]
B_it = B_it[:B_index]

maxs = 0
count=0
for i in A_it[::-1]:
    if K-i < 0:
        continue
    now = K-i
    B_index = bisect.bisect_right(B_it, now)
    
    maxs = max(maxs, B_index + A_index - count)
    count+=1

if len(A_it)==0:
    print(B_index)
elif len(B_it)==0:
    print(A_index)
else:
    print(maxs)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = deque([int(i) for i in input().split()])
B = deque([int(i) for i in input().split()])
ans = 0
inf = 10**10
a = A.popleft()
b = B.popleft()

while K >= 0 or (A and B):
    if a < b:
        K -= a
        if K >= 0:
            ans += 1
        try:
            a = A.popleft()
        except:
            a = inf

    else:
        K -= b
        if K >= 0:
            ans += 1
        try:
            b = B.popleft()
        except:
            b = inf

print(ans)

Submission status: Wrong Answer

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

N,M,K=(int(x) for x in input().rstrip('\n').split())
As=[int(x) for x in input().rstrip('\n').split()]
Bs=[int(x) for x in input().rstrip('\n').split()]
res = 0
now = 0
now_a = 0
now_b = 0
for i in range(N+M):
  if now_a==len(As):
    if now_b==len(Bs):
      c=2
      break
    else:
      c=0
  elif now_b==len(Bs):
    c=1
  elif As[now_a]!=Bs[now_b]:
    if As[now_a]<Bs[now_b]:
      c=1
    else:
      c=0
  else:
    nex_a=now_a+1
    nex_b=now_b+1
    if all(x==y for x,y in zip(As[now_a:],Bs[now_b:])):
      c=1
    else:
      while 5572>573:
        if nex_a==len(As):
          c=0
          break
        elif nex_b==len(Bs):
          c=1
          break
        else:
          if As[nex_a]<Bs[nex_b]:
            c=1
            break
          elif As[nex_a]>Bs[nex_b]:
            c=0
            break
          else:
            nex_a+=1
            nex_b+=1
  if c == 1:
    now += As[now_a]
    now_a += 1
  elif c>1:
    break
  else:
    now += Bs[now_b]
    now_b += 1
  if now>K:
    break
  res += 1
print(res)

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()))
cntA = 0
ans = 0
for i in range(n):
  if cntA+a[i] > k:
    break
  ans += 1
  cntA += a[i]
indA = ans-1
nc = indA+1
copyA = cntA+1
for j in range(indA+1):
  temp = 0
  adds = 0
  for v in b:
    adds += v
    if cntA + adds > k:
      break
    temp += 1
  cntA -= a[nc-1-j]
  ans = max(ans,indA+1+temp)
  indA -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n , m , k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
x = 0
num = 0
for i in range(n+m):
    if x <= k :
        num += 1
        if len(a_list) == 0:
            y = b_list.pop(0)
            x += y
        elif len(b_list) == 0:
            y = a_list.pop(0)
            x += y
        else :
            if a_list[0] <= b_list[0]:
                y = a_list.pop(0)
                x += y
            else :
                y = b_list.pop(0)
                x += y
print(num-1)

Submission status: Wrong Answer

Solution code:
n, m, k = map((lambda x: int(x)), input().split())
a_list = list(map((lambda x: int(x)), input().split()))
b_list = list(map((lambda x: int(x)), input().split()))
read_cnt = 0
a_cnt = 0
b_cnt = 0
k = 0
a_list.append(200001)
b_list.append(200001)
val = 'aaaaa'
ans = 'bbbbb'
while k > 0:
    if a_list[a_cnt] > b_list[b_cnt]:        
#         pdb.set_trace()
        k -= b_list[b_cnt]
        b_cnt += 1
        read_cnt += 1
    elif a_list[a_cnt] == b_list[b_cnt]:
        if a_list[a_cnt] == 200001:
            break
        else:
            val, ans = compare_list(a_list, b_list, a_cnt, b_cnt)
            if ans == 'a':
                k -= a_list[a_cnt]
                a_cnt += 1
                read_cnt += 1                
            else:
                k -= b_list[b_cnt]
                b_cnt += 1
                read_cnt += 1
    else:
        k -= a_list[a_cnt]
        a_cnt += 1
        read_cnt += 1

print(read_cnt)        
        
def compare_list(a, b, a_cnt, b_cnt):
    dummy_a_cnt = a_cnt
    dummy_b_cnt = b_cnt
    while a_list[dummy_a_cnt] == b_list[dummy_b_cnt]:
        dummy_a_cnt += 1
        dummy_b_cnt += 1
        if a_list[dummy_a_cnt] > b_list[dummy_b_cnt]:
            answer = 'b'
            return b_list[b_cnt], answer
        else:
            answer = 'a'
            return a_list[a_cnt], answer

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()) )

N_book = 0
for nb in range(len(B)):
    for na in range(len(A)):
        if sum(B[:nb]) + sum(A[:na]) > K:
            break
        else:
            if N_book < na + nb:
                N_book = na + nb
print(N_book)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
bookcount = 0
time = 0
a = 0
b = 0
while time <= k:
    if a == len(deskA) and b == len(deskB):
        bookcount += 1
        break
    elif b == len(deskB):
        t = deskA[a]
        a += 1
    elif a == len(deskA):
        t = deskB[b]
        b += 1
    elif deskA[a] < deskB[b]:
        t = deskA[a]
        a += 1
    elif deskA[a] > deskB[b]:
        t = deskB[b]
        b += 1
    else:
        if deskA[a:] < deskB[b:]:
            t = deskA[a]
            a += 1
        else:
            t = deskB[b]
            b += 1
    time += t
    bookcount += 1

print(bookcount-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

def main():
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    
    x = 0
    y = 0
    time = 0
    books = 0

    while time <= K:
        if x < N and y < M:
            if A[x] <= B[y]:
                if time + A[x] <= K:
                    time = time + A[x]
                    x = x + 1
                    books = books + 1
                else:
                    return books
            else:
                if time + B[y] <= K:
                    time = time + B[y]
                    y = y + 1
                    books = books + 1
                else:
                    return books
        elif x < N and y >= M:
            if time + A[x] <= K:
                time = time + A[x]
                x = x + 1
                books = books + 1
            else:
                return books
        elif x >= N and y < M:
            if time + B[y] <= K:
                time = time + B[y]
                y = y + 1
                books = books + 1
            else:
                return books
        else:
            return books
        
    return books

def main_2():
    books = main()
    print(books)

main_2()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [1000000001] * 200000
B = [1000000001] * 200000
A[:N] = list(map(int, input().split()))
B[:M] = list(map(int, input().split()))
T = 0  # 経過時間
result = 0
a = 0
b = 0  # それぞれのフラグ
count = 0
while T < K:
    result = T
    if A[a] < B[b]:
        T += A[a]
        a += 1
        if T > K:
            break
        if a == len(A):
            A = [1000000001] * 200000
    elif B[b] < A[a]:
        T += B[b]
        b += 1
        if T > K:
            break
        if b == len(B):
            B = [1000000001] * 200000
    else:
        Asum = sum(A[a:])
        Bsum = sum(B[b:])
        if Asum < Bsum:
            T += A[a]
            a += 1
        else:
            T += B[b]
            b += 1
        if T > K:
             break
    count += 1
print(count)

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()))

cnt = 0

num = 0

while num < K:
    if a == [] and b == []:
        break
    elif a == []:
        num += b.pop(0)
    elif b == []:
        num += a.pop(0)
    else:
        if a[0] < b[0]:
            num += a.pop(0)
        else:
            num += b.pop(0)
    cnt += 1

if K < num:
    print(cnt-1)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, KK = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))
k = 0


max = N + M
  #print(max)
summ = 0

for i in range(max):

  if len(a) > 0 and len(b) > 0:
    #print(a[0], b[0])
    if a[0] < b[0]:
      k += a[0]
      a.popleft()
    else:
      k += b[0]
      b.popleft()
    
    if KK >= k :
      summ += 1
    else:
      break
      
  elif len(a) > 0 and len(b) == 0:
    k += a[0]
    
    if KK >= k :
      summ += 1
      a.popleft()
    else:
      break
  
  elif len(a) == 0 and len(b) > 0:
    k += b[0]
    
    if KK >= k :
      summ += 1
      b.popleft()
    else:
      break
    
  else:
    break
    
  #print(a)
  #print(b)
  #print(KK)
print(summ)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum

n, m, k = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

cumA = cumsum(A)
cumB = cumsum(B)

if cumA[0] > k:
    print(bisect_right(cumB, k))
    exit()

ans = 0

for idx_a, a in enumerate(cumA):
    if a > k:
        break
    rem = k - a
    idx_b = bisect_right(cumB, rem)
    ans = max(ans, idx_a + 1 + idx_b)
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()))

time = 0
book = 0
stop = 0
for i in range(N):
    if time + A[i] <= K:
        time += A[i]
        book += 1
        stop = i

max_book = book 
flag = True
for i in range(M):
    if time + B[i] <= K:
        time += B[i]
        book += 1
        max_book = max(max_book, book)
    else:
        if flag == False:
            break
        while True:
            if stop >= 0:
                time -= A[stop]
                stop -= 1
                book -= 1
                if time + B[i] <= K:
                    if stop < 0:
                        time += B[i]
                        book += 1
                        max_book = max(max_book, book)
                        flag = False
                    break
            else:
                flag = False
                break

print(max_book)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

count = 0
time = 0
for i in range(N + M + 2):
  if len(A) + len(B) == 0:
    break
  if len(A) == 0:
    book = B.popleft()
  elif len(B) == 0:
    book = A.popleft()
  else:
    if A[0] < B[0]:
      book = A.popleft()
    else:
      book = B.popleft()
  
  time += book
  if time > K:
    break
  else:
    count += 1

print(count)

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

while (len(a)>0 or len(b)>0) and ((len(a)>0 and k>=a[0]) or (len(b)>0 and k>=b[0])):
    sum1 = 0
    sum2 = 0
    i1=0
    i2=0
    while i1<len(a) and sum1+a[i1]<=k:
        sum1+=a[i1]
        i1+=1
    while i2<len(b) and sum2+b[i2]<=k:
        sum2+=b[i2]
        i2+=1
    if i1==i2:
        if sum1<sum2:
            ans+=i1
            a=a[i1:]
            k-=sum1
        else:
            ans+=i2
            b=b[i2:]
            k-=sum2
                
    elif i1>i2:
        ans+=i1
        a=a[i1:]
        k-=sum1
    else:
        ans+=i2
        b=b[i2:]
        k-=sum2
        

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K=(int(x) for x in input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

A_i = 0
B_i = 0

A_i_sub = 0
B_i_sub = 0

next_A = A_list[A_i]
next_B = B_list[B_i]

count_read = 0

while(K >= next_A or K >= next_B):
    if(next_A <= next_B and A_i < N):
        K = K - next_A
        count_read += 1
        if(A_i < N-1):
            A_i += 1
            next_A = A_list[A_i]
        elif(A_i == N-1):
            next_A = 10000000000
    elif(next_B < next_A and B_i < M):
        count_read += 1
        if(B_i < M-1):
            B_i += 1
            next_B = B_list[B_i]
        elif(B_i == M-1):
            next_B = 10000000000

print(count_read)

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()))

total = 0
books = 0
while total < K:
    if A == []:
        total += B.pop(0)
    elif B == []:
        total += A.pop(0)
    elif A[0] <= B[0]:
        total += A.pop(0)
    elif A[0] > B[0]:
        total += B.pop(0)
    else:
        break
    if total > K:
        break
    books += 1
    print(total)
print(books)

Submission status: Wrong Answer

Solution code:
desk_A, desk_B, time_limit = map(int, input().split())
desk_A_Book = list(map(int, input().split()))
desk_B_Book = list(map(int, input().split()))

read   = 0
answer = 0

for k in range(desk_A+desk_B):
  if len(desk_A_Book) == 0:
    select = desk_B_Book.pop(0)
  elif len(desk_B_Book) == 0:
    select = desk_A_Book.pop(0)
  else:
    select = min(desk_A_Book[0], desk_B_Book[0])
    if desk_A_Book[0] == select:
    	desk_A_Book.remove(select)
    else:
    	desk_B_Book.remove(select)
  if select > time_limit:
    break
  else:
    time_limit -= select
    answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
import collections

n,m,k = map(int,input().split())
a = collections.deque()
A = list(map(int,input().split()))
for i in A:
    a.append(i)
b = collections.deque()
B = list(map(int,input().split()))
for i in B:
    b.append(i)

ans = 0
time = 0
while time < k:
    if len(a) != 0 and len(b) != 0:
        if a[0] < b[0]:
            tmp = a.popleft() 
        elif a[0] > b[0]:
            tmp = b.popleft()
        elif a[0] == b[0]:
            for i in range(1,min(len(a),len(b))):
                if a[i] < b[i]:
                    tmp = a.popleft()
                    break
                elif a[i] > b[i]:
                    tmp = b.popleft()
                    break
                else:
                    pass
            else:
                if len(a) == len(b):
                    tmp = a.popleft()
                elif len(a) > len(b):
                    tmp = a.popleft()
                elif len(a) < len(b):
                    tmp = b.popleft()
    elif len(a) == 0 and len(b) != 0:
        tmp = b.popleft()
    elif len(b) == 0 and len(a) != 0:
        tmp = a.popleft()
    else:
        break
    time += tmp        
    if time <= k:
        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()))

total = 0
cnt = 0

while 1:
    if A == []:
        A += B
    if B == []:
        B += A   
        
    total += min(A[0],B[0])
    if total > k:
        break
    
    if min(A[0],B[0]) == A[0]:
        A.pop(0)
    else:
        B.pop(0)
        
    cnt += 1
    
print(cnt)

Submission status: Wrong Answer

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

import sys
import collections

def input():
    return sys.stdin.readline()

def greedy_reading(n, m, k, a_list, b_list):

    max_books = len(a_list) + len(b_list)

    k_remain = k
    count = 0
    for i in range(max_books):
        if len(a_list) > 0 and len(b_list) > 0:
            if a_list[0] <= b_list[0]:
                if k_remain < a_list[0]:
                    break
                k_remain -= a_list.popleft()
                count += 1
            else:
                if k_remain < b_list[0]:
                    break
                k_remain -= b_list.popleft()
                count += 1
        elif len(a_list) > 0:
            if k_remain < a_list[0]:
                break
            k_remain -= a_list.popleft()
            count += 1
        elif len(b_list) > 0:
            if k_remain < b_list[0]:
                break
            k_remain -= b_list.popleft()
            count += 1

        #print(k_remain)

    return count


def resolve():
    n, m, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    a_list = collections.deque(a_list)
    b_list = collections.deque(b_list)
    ans = greedy_reading(n, m, k, a_list, b_list)


    a_sum = 0
    b_sum = 0
    a_num = 0
    b_num = 0
    a_remain = 0
    b_remain = 0
    # Aから
    for i in range(len(a_list)):
        a_sum += a_list[i]
        if a_sum > k:
            a_sum -= a_list[i]
            a_num = i
            break
    if a_num == 0 and a_sum == 0:
        print(ans)
        exit()
    elif a_num == 0:
        a_num = len(a_list)

        a_remain = k - a_sum

    # B
    for i in range(len(b_list)):
        b_sum += b_list[i]
        if b_sum > k:
            b_sum -= b_list[i]
            b_num = i
            break

    if b_num == 0 and b_sum == 0:
        print(ans)
        exit()
    elif b_num == 0:
        b_num = len(b_list)
        b_remain = k - b_sum


    # Aオーバーしない
    a_b_sum = a_sum
    a_b_num = a_num

    for i in range(len(b_list)):
        a_b_sum += b_list[i]
        if a_b_sum > b_remain:
            a_b_sum -= b_list[i]
            a_b_num += i
            break
    # bオーバーしない
    b_a_sum = b_sum
    b_a_num = b_num
    for i in range(len(a_list)):
        b_a_sum += a_list[i]
        if b_a_num > a_remain:
            b_a_sum -= a_list[i]
            b_a_num += i
            break

    print(a_b_num, b_a_num, ans)
    if ans < a_b_num and b_a_num <= a_b_num:
        print(a_b_num)
        exit()

    if ans < b_a_num and a_b_num <= b_a_num:
        print(b_a_num)
        exit()

    print(ans)











if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
N,M,K = input().split()
n = int(N)
m = int(M)
k = int(K)

listA = [int(x) for x in input().split()]
listB = [int(y) for y in input().split()]

a = 0
b = 0
total = 0
counter = 0

while k >= total:
    if a == len(listA) and b != len(listB):
        total = total + listB[b]
        b = b + 1
        counter = counter + 1

    elif b == len(listB) and a != len(listA):
        total = total + listA[a]
        a = a + 1
        counter = counter + 1

    elif a == len(listA) and b == len(listB):
        counter = counter + 1
        break

    else:
        if listA[a] >= listB[b]:
            total = total + listB[b]
            b = b + 1
            counter = counter + 1
                
        elif listA[a] <= listB[b]:
            total = total + listA[a]
            a = a + 1
            counter = counter + 1

counter = counter - 1
print(counter)