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 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []

for i in range(n+m):
  if a == [] and b == []:
    break
  elif a == []:
    c.append(b[0])
    b.pop(0)
  elif b == []:
    c.append(a[0])
    a.pop(0)
  elif a[0] > b[0]:
    c.append(b[0])
    b.pop(0)
  else:
    c.append(a[0])
    a.pop(0)

    
num = 0
ans = 0

for j in range(n+m):
  num += c[j]
  if num > k:
    break
  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()))

a_max = 0
sum = 0
for i in range(n):
  sum += A[i]
  if sum > k:
    sum -= A[i]
    break
  a_max += 1
  
ans = a_max
kotae =ans
j = 0

for i in range(m):
  sum += B[i]
  ans += 1
  while sum > k and j < a_max:
    sum -= A[a_max-1-j]
    ans -= 1
    j += 1
  if sum > k:
    print(ans-1)
    exit()
  kotae = max(kotae, ans)
  if a_max-j == 0:
    break
  
print(kotae)

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
a.reverse()
b.reverse()
if sum(a)+sum(b)<=k:
    count=len(a)+len(b)+1
else:
    while k>0:
        if a==[]:
            k-=b[len(b)-1]
            del b[len(b)-1]
        elif b==[]:
            k-=a[len(a)-1]
            del a[len(a)-1]
        elif a[len(a)-1]<=b[len(b)-1]:
            k-=a[len(a)-1]
            del a[len(a)-1]
        elif a[len(a)-1]>b[len(b)-1]:
            k-=b[len(b)-1]
            del b[len(b)-1]
        count+=1
print(count-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
counter = 0
ans = 0
a = A.popleft()
b = B.popleft()
while counter < K:
    ans += 1
    if a >= b:
        counter += b
        if not B:
            b = 0
            break
        b = B.popleft()
    else:
        counter += a
        if not A:
            a = 0
            break
        a = A.popleft()
if counter > K:
    print(ans - 1)
elif counter == K:
    print(ans)
else:
    if a == 0:
        A = B
        a = b
    while counter < K:
        ans += 1
        counter += a
        if not A:
            break
        a = A.popleft()
    if counter <= K:
        print(ans)
    else:
        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()))
c = 0
ac = 0
bc = 0
la = len(a)
lb = len(b)
ch = 0

while 1:
  if ac >= la:
    ch = "a"
    break
  if bc >= lb:
    ch = "b"
    break
  aac = a[ac]
  bbc = b[bc]
  if k - aac < 0 and k - bbc < 0:
    break
  elif aac < bbc:
    k -= aac
    ac += 1
    c += 1
  elif aac > bbc:
    k -= bbc
    bc += 1
    c += 1
    
if ch == "a":
  while 1:
    if bc >= lb:
      break
    bbc = b[bc]
    if k - bbc < 0:
      break
    k -= bbc
    bc += 1
    c += 1
    
elif ch == "b":
  while 1:
    if ac >= la:
      break
    aac = a[ac]
    if k - aac < 0:
      break
    k -= aac
    ac += 1
    c += 1
  
print(c)

Submission status: Wrong Answer

Solution code:
n, m , has_time = [int(x) for x in input().split()]
maxs = max(n, m)
nb = [int(x) for x in input().split()]
if n < maxs:
    nb += [10e10] * (maxs - n)
mb = [int(x) for x in input().split()]
if m < maxs:
    mb += [0] * (maxs - m)
cost = [min(x, y) for x, y in zip(nb, mb)]
need = 0
done  = 0
for i,v in enumerate(cost):
    need += v
    if need <= has_time:
        done += 1
    else:break
print(done)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

INF = 1 << 60
A.append(INF)
B.append(INF)

p, q = 0, 0
while True:
    if A[p] < B[q]:
        if A[p] > K:
            break
        K -= A[p]
        p += 1
    else:
        if B[q] > K:
            break
        K -= B[q]
        q += 1

print(p+q)

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

time = 0
book = 0
for i in range(len(alist)+len(blist)):
    if len(alist) != 0 and len(blist) != 0:
        if alist[0] >= blist[0]:
            time += blist.pop(0)
            book += 1
        else:
            time += alist.pop(0)
            book += 1
        if time > k:
            book -= 1
            break
    elif len(alist) == 0:
        time += blist.pop(0)
        book += 1
        if time > k:
            book -= 1
            break
    elif len(blist) == 0:
        time += alist.pop(0)
        book += 1
        if time > k:
            book -= 1
            break

print(book)

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
totalbook = 0
totaltime = 0
for a in a_list:
  if totaltime+a <= K:
    totaltime+=a
    totalbook+=1
  else:
    break
ans = totalbook
nowaind = totalbook-1 if totalbook > 0 else 0
nowbind = 0
for b in b_list:
  if totaltime+b<=K:
    totaltime+=b
    totalbook+=1
    nowbind+=1
  else:
    break
ans = max(ans,totalbook)
for b in range(nowbind,len(b_list)):
  while nowaind >= 0 and totaltime+b_list[b]>K:
    totalbook-=1
    totaltime-=a_list[nowaind]
    nowaind-=1
  totaltime+=b_list[b]
  if totaltime+b_list[b]<=K:
    totalbook+=1
  else:
    break
print(max(ans,totalbook))

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 len(A) != 0 or len(B) != 0:
    if len(A) != 0 and len(B) != 0:
        if A[0] > B[0]:
            K -= B[0]
            B.pop(0)
        else:
            K -= A[0]
            A.pop(0)
    else:
        if len(A) > 0:
            K -= A[0]
            A.pop(0)
        elif len(B) > 0:
            K -= B[0]
            B.pop(0)

    if K < 0: break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
temp = [int(i) for i in input().split(" ")]
n = temp[0]
m = temp[1]
k = temp[2]

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]


arr = []

while True:
    if len(a) > 0 and len(b) > 0:
        if a[0] <= b[0]:
            arr.append(a.pop(0))
        else:
            arr.append(b.pop(0))

    elif len(a) > 0:
        arr.append(a.pop(0))

    elif len(b) > 0:
        arr.append(b.pop(0))
    
    else:
        break



time = 0
counter = 0
for i in range(len(arr)):
    
    temp = arr[i]

    time += temp
    if time <= k:
        counter += 1
    else:
        break

print(counter)

Submission status: Wrong Answer

Solution code:
from sys import stdin

A=list(map(int,stdin.readline().split()))
N=A[0]
M=A[1]
K=A[2]
B=list(map(int,stdin.readline().split()))  #N
C=list(map(int,stdin.readline().split()))  #M
D=dict()
DD=dict()
MAX=0

if B[0]<=K:
    D[(1,0)]=B[0]
if C[0]<=K:
    D[(0,1)]=C[0]

while len(D)>0:
    for t in D:
        if t[0]<N and D[t]+B[t[0]]<=K:
            DD[(t[0]+1,t[1])]=D[t]+B[t[0]]
            MAX=t[0]+t[1]+1
        if t[1]<M and t[0]==0:
            if D[t] + C[t[1]] <= K:
                DD[(t[0],t[1]+1)] = D[t] + C[t[1]]

    D=DD

    DD=dict()


print(MAX)

Submission status: Wrong Answer

Solution code:
#机A, B
#机A：N冊の本が縦積み, B: M冊
import collections

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

dqA=collections.deque()
dqB=collections.deque()

for a in A:
    dqA.append(a)
for b in B:
    dqB.append(b)


totaltime=0
answer=0
while totaltime <= K:
    if len(dqA) > 0 and len(dqB)> 0:    
        a=dqA.popleft()
        b=dqB.popleft()
        if a<=b:
            dqB.appendleft(b)
            totaltime += a
        else:
            dqA.appendleft(a)
            totaltime += b
    elif len(dqA)>0:
        a=dqA.popleft()
        totaltime += a
    elif len(dqB)>0 :
        b=dqB.popleft()
        totaltime += b
    elif len(dqA)==0 and len(dqB)==0:
        print(answer)
        exit()
    if totaltime > K:
        print(answer)
        exit()
    else:
        answer+=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()))

r0=0
rr = 0
t0=0
i = 0
j = 0
flag = 0

while t0<=K:
    t0 = t0 + A[i]
    if t0<=K:
        r0 = r0 + 1
        print(t0,r0)
        if i==N-1:
            break
        i = i + 1

if t0>K:
    t0 = t0 - A[i]

while t0<=K:
    t0 = t0 + B[j]
    if t0<=K:
        r0 = r0 + 1
        print(t0,r0)
        if j==M-1:
            flag = 1
            break
        j = j + 1

if t0>K:
    t0 = t0 - B[j]

rr = r0
Kk = K
tk = t0
rk = r0

for k in range(i):
    if flag == 1:
        break
    Kk = Kk + A[i-k] - tk
    print(Kk)
    tk = 0
    ik = 0
    rk = rk - 1
    while tk<=Kk:
        tk = tk + B[j]
        if tk<=Kk:
            rk = rk + 1
            print(tk,rk)
            if j == M-1:
                flag = 1
                break
            j = j+1
    rr = max(rk,rr)


print(rr)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
time = 0
cnt = 0
while time < K:
  try:
    if list_A[0] >= list_B[0]:
      time += list_B[0]
      if time > K:
        time -= list_B.pop(0)
        break
      else:
        list_B.pop(0)
        cnt += 1
        continue
    elif list_A[0] < list_B[0]:
      time += list_A[0]
      if time > K:
        time -= list_A.pop(0)
        break
      else:
        list_A.pop(0)
        cnt += 1
        continue
  except IndexError:
    list_A += list_B
    time += list_A[0]
    if time > K:
      time -= list_A.pop(0)
      break
    else:
      list_A.pop(0)
      cnt += 1
      continue
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()))
time = 0
count = 0
Anum = 0
Bnum = 0
judgea = 0
judgeb = 0
while time<=K:
    if judgea == 2 and judgeb ==1:
        break
    
    if A[Anum]>B[Bnum] or judgea == 2:
        time += B[Bnum]
        
        if Bnum+1 >= len(B):
            judgeb = 1
        else:
            Bnum += 1
        count += 1
    elif A[Anum]<=B[Bnum] or judgeb == 1:
        time += A[Anum]
       
        if Anum+1 >= len(A):
            judgea = 2
        else:
            Anum += 1
        count += 1
        
if time>K:
    count-= 1

print(count)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
from bisect import bisect

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

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

A_time = [0] * N
B_time = [0] * M

rui = 0
flag = True

for i in range(N):
    rui += A[i]
    A_time[i] = rui

rui = 0

for i in range(M):
    rui += B[i]
    B_time[i] = rui

T = 0
po = 0
num = 0

for i in range(N):
    
    T = K - A_time[i]
    
    if T < 0:
        continue
    
    po = bisect(B_time,T)
    
    num = max(num, po + i + 1)

print("{}".format(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()))
a.append(99999999999)
b.append(99999999999)

i=0
j=0
time = 0
while time <= k:
    if a[i] <= b[j] and a[i]+time <= k:
        time +=a[i]
        i+=1
    elif a[i] > b[j] and b[j]+time <= k:
        time+=b[j]
        j+=1
    else:
        break
print(i+j)

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()))
k=0
c=0
while k <= K:
    if len(a) > 0 and len(b)>0:
        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:
import sys
import math 
from collections import deque

n,m,k=map(int,input().split())
A = list(map(int,input().split()))
b = list(map(int,input().split()))

i=0
j=0
ans=0
tmp=0
re=0
while True:
    if i==n and j==m:
        print(ans)
        sys.exit()

    elif i==n:
        re=b[j]
        j+=1
    elif j==m:
        re=A[i]
        i+=1
    else:
        q=A[i]
        u=b[j]
        re=min(q,u)
        if re ==q:
            i+=1
        else:
            j+=1

    tmp+=re
    if tmp > k:
        print(ans)
        sys.exit()
    elif tmp ==k:
        ans+=1
        print(ans)
        sys.exit()

    ans+=1

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a_li = list(map(int,input().split()))
b_li = list(map(int,input().split()))
total_1 = 0
total_2 = 0
a_ruiseki = [0]*n
b_ruiseki = [0]*m
a = 0
b = 0
for i in range(n):
    total_1 += a_li[i]
    a_ruiseki[i] = total_1
for i in range(m):
    total_2 += b_li[i]
    b_ruiseki[i] = total_2
for i in range(n):
    if a_ruiseki[i] > k:
        a = i
        break
else:
    a = i+1
for i in range(m):
    if b_ruiseki[i] > k:
        b = i
        break
else:
    b = i+1
for i in range(m):
    if b_ruiseki[i] > k-a_ruiseki[a-1]:
        a += i
        break
else:
    a += i+1

for i in range(n):
    if a_ruiseki[i] > k-b_ruiseki[b-1]:
        b += i
        break
else:
    b += i+1
print(max(a,b))

Submission status: Wrong Answer

Solution code:
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heappushpop, heapreplace
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['NET', 'DA']
############# CODE STARTS HERE #############


test_case=1
while test_case:
    test_case-=1


    n, m, k=mi()
    a=li()
    b=li()
    t=c=i=j=0
    while t<=k:
        if i<n and j<m:
            if a[i]<b[j]:
                t+=a[i]
                i+=1
                if t<=k:
                    c+=1
                else:
                    break
            else:
                t+=b[j]
                j+=1
                if t<=k:
                    c+=1
                else:
                    break
        elif i<n:
            t+=a[i]
            i+=1
            if t<=k:
                c+=1
            else:
                break
        elif j<m:
            t+=b[j]
            j+=1
            if t<=k:
                c+=1
            else:
                break
        else:
            break
        #print(t)
    print(c)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
nb = list(map(int, input().split()))
mb = list(map(int, input().split()))
tc = 0
nc = 0
mc = 0
ans = 0
while tc <= k:
  if nc == n and mc == m:
      break
  if nc == n:
    tc = tc + mb[mc]
    mc = mc + 1
  elif mc == m:
    tc = tc + nb[nc]
    nc = nc + 1
  elif nb[nc]<mb[mc]:
    tc = tc + nb[nc]
    nc = nc + 1
  else:
    tc = tc + mb[mc]
    mc = mc + 1
  if tc <= k:
    ans = ans+1
    
      

print(ans)

Submission status: Wrong Answer

Solution code:
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import bisect


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N, M, K = LI()
    AArray = LI()
    BArray = LI()

    aSum = [AArray[0]]
    bSum = [BArray[0]]

    cnt = 0

    for i in range(1, N):
        aSum.append(aSum[i-1]+AArray[i])
    for i in range(1, M):
        bSum.append(bSum[i-1]+BArray[i])

    for i in range(N):
        a = aSum[i]
        if a >= K:
            break
        sa = K-a
        b = bisect.bisect_right(bSum, sa)
        cnt = max(cnt, i+1+b)

    # while K > 0 and (len(AArray) > 0 or len(BArray) > 0):
    #     if len(AArray) > 0 and len(BArray) > 0:
    #         if AArray[0] >= BArray[0]:
    #             b = BArray.pop(0)
    #             if K-b >= 0:
    #                 K -= b
    #                 cnt += 1
    #             else:
    #                 break
    #         elif AArray[0] < BArray[0]:
    #             a = AArray.pop(0)
    #             if K-a >= 0:
    #                 K -= a
    #                 cnt += 1
    #             else:
    #                 break
    #     elif len(AArray) == 0:
    #         b = BArray.pop(0)
    #         if K-b >= 0:
    #             K -= b
    #             cnt += 1
    #         else:
    #             break
    #     else:
    #         a = AArray.pop(0)
    #         if K-a >= 0:
    #             K -= a
    #             cnt += 1
    #         else:
    #             break

    print(cnt)


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

def search(a, b, time):
    check = False
    
    if a > len(A) - 1:
        if b > len(B) - 1:
            check = True
        else:
            time += B[b]
            b += 1
    else:
        if b > len(B) - 1:
            if a > len(A) - 1:
                check = True
            else:
                time += A[a]
                a += 1
        else:
            if A[a] > B[b]:
                time += B[b]
                b += 1

            else:
                time += A[a]
                a += 1
    
    return a, b, time, check

a = 0
b = 0
time = 0

for n in range(200000 + 200000):
    a, b, time, check = search(a, b, time)
    
    if time > K:
        print(a + b - 1)
        break
    
    if check:
        print(a + b)
        break

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()))
t_a=[]
t_b=[]
l=0
for i in range(N):
  l+=A[i]
  t_a.append(l)
l=0
for i in range(M):
  l+=B[i]
  t_b.append(l)
def bi_re(i):
  x=K-t_a[i]
  l=0;r=M-1
  while l<=r:
    m=(l+r)//2
    q=t_b[m]
    if q==x:
      return m+1
    elif q<x:
      l=m+1
    else:
      r=m-1
  return r+1
  
ans=0
for i in range(N):
  if t_a[i]==K:
    ans=max(i+1,ans)
  elif t_a[i]<K:
    ans=max(bi_re(i)+i+1,ans)
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()))
c = a+b
c.sort()
i = 0
ans = 0
count = 0
if sum(c) <= k:
    print(n+m)
    exit()
if c[0] > k:
    print(0)
    exit() 

while len(a) != 0 or len(b) != 0:
#    print(a,b)
    if len(a) == 0 or len(b) == 0:
        break
    if a[0] >= b[0]:
        ans += b[0]
        b = b[1:]
    else:
        ans += a[0]
        a = a[1:]
    if ans > k:
        break
    count += 1

while len(a) == 0:
    ans += b[0]
    b = b[1:]
    if ans > k:
        print(count)
        break
    count += 1


while len(b) == 0:
    ans += a[0]
    a = a[1:]
    if ans > k:
        print(count)
        break
    count += 1

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    A = deque(A)
    B = deque(B)

    inf = 10**10
    A.append(inf)
    B.append(inf)

    ans = tot = 0

    for i in range(len(A) + len(B) + 10):
        a = A[0]
        b = B[0]

        if a < b:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()

        elif a > b:
            if tot + b <= K:
                ans += 1
                tot += B.popleft()

        else:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m, k = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]

a_next_index = 0
b_next_index = 0
read_time = 0
readed_cnt = 0

while (a_next_index < n or b_next_index < m):
    if a_next_index == n:
        read_time += b[b_next_index]
        b_next_index += 1
    elif b_next_index == m:
        read_time += a[a_next_index]
        a_next_index += 1
    else:
        if a[a_next_index] == b[b_next_index]:
            if a_next_index + 1 == n:
                read_time += b[b_next_index]
                b_next_index += 1
            elif b_next_index + 1 == m:
                read_time += a[a_next_index]
                a_next_index += 1
            elif a[a_next_index + 1] < b[b_next_index + 1]:
                read_time += a[a_next_index]
                a_next_index += 1
            else:
                read_time += b[b_next_index]
                b_next_index += 1
        elif a[a_next_index] < b[b_next_index]:
            read_time += a[a_next_index]
            a_next_index += 1
        else:
            read_time += b[b_next_index]
            b_next_index += 1

    if (read_time > k):
        break

    readed_cnt += 1

print(readed_cnt)

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

cnt = 0
while k >= 0:
    if not A:
        a = 10 ** 11
    else:
        a = A.popleft()
    if not B:
        b = 10 ** 11
    else:
        b = B.popleft()
    if a <= b:
        k -= a
        B.appendleft(b)
        cnt += 1
    else:
        k -= b
        A.appendleft(a)
        cnt += 1
print(cnt - 1)

Submission status: Wrong Answer

Solution code:
N, M, K = (int(s) for s in input().rstrip().split())

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

i, j = (0, 0)
sum, count = (0, 0)

while sum < K:
  if (i < N) and (j < M):
    if A[i] <= B[j]:
      sum += A[i]
      i += 1
      count += 1
    else:
      sum += B[j]
      j += 1
      count += 1
  elif i < N:
    sum += A[i]
    i += 1
    count += 1
  else:
    sum += B[j]
    j += 1
    count += 1

if sum > K:
  count -= 1
    
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = [a for a in map(int,input().split())]
B = [b for b in map(int,input().split())]

ans = 0
l = len(A)
i = 0
for b in B:
    while True:
        if l == i:
            A.append(b)
            break
        if A[i] < b :
            i += 1
        else:
            A.insert(i,b)
            break

for a in A:
    if K <= 0:
        break
    K -= a
    ans += 1

if K < 0:
    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()))
cntA = 0
indA = 0
p = max(m,n)
if p == n:
  q = a
  r = b
else:
  q = b
  r = a
for i in range(p):
  if cntA+q[i] > k:
    break
  indA += 1
  cntA += q[i]
indA -= 1
ans = indA+1
for i in range(indA+1):
  temp = indA+1
  for v in r:
    if cntA + v > k:
      break
    cntA += v
    temp += 1
  cntA -= q[indA-1-i]
  ans = max(ans,temp)
print(ans)

Submission status: Wrong Answer

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

AN = list(map(int, input().split()))
BN = list(map(int, input().split()))

N = A + B + 5

dp = [0] * N

for i in range(N):
    if dp[i] <= K:
        if not AN:
            if not BN:
                print(i)
                exit()
            else:
                dp[i+1] = dp[i] + BN[0]
                del BN[0]
        elif not BN:
            if not AN:
                print(i)
                exit()
            else:
                dp[i+1] = dp[i] + AN[0]
                del AN[0]
        elif AN[0] > BN[0]:
            dp[i+1] = dp[i] + BN[0]
            del BN[0]
        else:
            dp[i+1] = dp[i] + AN[0]
            del AN[0]
    else:
        print(i-1)
        exit()

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

C =A+B
C.sort()

min = 0
cnt= 0

if sum(C) <= K:
  print(len(C))
else:
  for i in range(len(C)):
    if min <= K:
      cnt+=1
      min+=C[i]
    else:
      print(cnt-1)
      break

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
n = 0
m = 0
for i in range(N+M):
    if n < N and m < M:
        if A[n] <= B[m]:
            time += A[n]
            n += 1
        else:
            time += B[m]
            m += 1
    else:
        if n >= N and m >= M:
            break
        elif n >= N and m < M:
            time += B[m]
            m += 1
        elif m >= M and n < N:
            time += A[n]
            n += 1
    if time < K:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ia 
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = list(ia(A))
b = list(ia(B))
na = 0
nb = 0
for i in a:
  if i < K:
    na += 1
  else:
    break
for i in b:
  if i < K:
    nb += 1
  else:
    break
if na > nb:
  t = a[na-1]
  for i in B:
    if t + i > K:
      break
    else:
      na += 1
      t += i
  print(na)
elif nb > na:
  t = b[nb-1]
  for i in A:
    if t + i > K:
      break
    else:
      nb += 1
      t += i
  print(nb)
else:
  t = a[na-1]
  for i in B:
    if t + i > K:
      break
    else:
      na += 1
      t += i
  t = b[nb-1]
  for i in A:
    if t + i > K:
      break
    else:
      nb += 1
      t += i
  print(max(na, nb))

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

cnt = 0

while(i<len(a) and j<len(b) and k>0):
    if(a[i]<=b[j] and a[i]<=k):
        k-=a[i]
        i+=1
    elif(b[j]<=a[i] and b[j]<=k):
        k-=b[j]
        j+=1
    else:
        break
    cnt+=1
    

while(i<len(a) and k>0 and a[i]<=k):
    k-=a[i]
    i+=1
    cnt+=1
    
while(j<len(b) and k>0 and b[j]<=k):
    k-=b[j]
    j+=1
    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect as bc

N,M,K = map(int,input().split())
A = [0]*(N+1)
B = [0]*(M+1)
A[1:] = list(map(int,input().split()))
B[1:] = list(map(int,input().split()))
A.append(10**9+10)
B.append(10**9+10)

A_S = [0]*(N+2)
B_S = [0]*(M+2)

for i in range(1,N+2):
    A_S[i] = A_S[i-1]+A[i]
for i in range(1,M+2):
    B_S[i] = B_S[i-1]+B[i]

ans = 0
for i in range(N+2):
    tmp_K = K-A_S[i]
    if tmp_K > 0:
        j = bc.bisect_right(B_S,tmp_K) - 1
        ans = max(i+j,ans)
    ans = max(i,ans)
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()))

c = 0

ans = 0

while c <= k and (not (len(a) == 0 and len(b) == 0)):
    if len(a) == 0:
        if c + b[0] > k:
            break
        else:
            c += b[0]
            del b[0]
            ans += 1
    elif len(b) == 0:
        if c + a[0] > k:
            break
        else:
            c += a[0]
            del a[0]
            ans += 1
    else:
        if a[0] > b[0]:
            if c + b[0] > k:
                break
            else:
                c += b[0]
                del b[0]
                ans += 1
        else:
            if c + a[0] > k:
                break
            else:
                c += a[0]
                del a[0]
                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()))

ans = 0
time = 0


for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
tmp = ans
sub = ans

for j in range(len(b)):
    time += b[j]
    if time > k:
        if sub != 0: 
            for i in range(sub):
                time -= a[sub - 1 - i]
                if time <= k:
                    tmp = tmp - i
                    sub = sub - i
                    break
                if i == sub & time > k:
                    tmp -= 1
        else:
            break
    
    tmp += 1
    if tmp > ans :
        ans = tmp
    
print(ans)