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 = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
a = [0]*N
b = [0]*M
a[0] = A[0]
b[0] = B[0]
ae = N-1
be = M-1
e = 0
for i in range(1, N):
    a[i] = a[i-1] + A[i]
    if(a[i] > K):
        ae = i-1
        break
for i in range(1, M):
    b[i] = b[i-1] + B[i]
    if(b[i] > K):
        be = i-1
        break
ans = be+1
for i in range(ae, -1, -1):
    ans = max(ans, i+1)
    for j in range(e, be+1):
        if a[i] + b[j] > K:
            e = max(j-1, 0)
            break
        print(a[i],b[j],i,j)
        ans = max(ans, i+j+2)
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 = 0
j = 0
ans = 0
time = 0

while 1:
    if (i < N and j < M):
        if A[i] <= B[j]:
            ans += 1
            time += A[i]
            i += 1
        else:
            ans += 1
            time += B[j]
            j += 1
    elif i < N and j >= M:
        ans += 1
        time += A[i]
        i += 1
    elif i >= N and j < M:
        ans += 1
        time += B[j]
        j += 1
    elif i >= N and j >= M:
        break

    if time > K:
        ans -= 1
        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()))

S = [0]

Sum = 0


for i in range(N):
  K = K - A[i]
  if K >= 0:
    Sum += 1
  else:
    K = K + A[i]
    break
S.append(Sum)

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if i == 0:
      break
    for k in range(i):
      K = K + A[i-k-1]
      Sum = Sum - 1
      if K >= 0:
        i = i-k-1
        break
      else:
        i = i-k-1
    if K >= 0:
      Sum += 1
    else:
      Sum -= 1
  S.append(Sum)
print(max(S))

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
ans = 0
for i in range(200000):
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        cnt += b.pop(0)
        if cnt > k:
            break
    elif len(b) == 0:
        cnt += a.pop(0)
        if cnt > k:
            break
    else:
        if a[0] >= b[0]:
            cnt += b.pop(0)
            if cnt > k:
                break
        else:
            cnt += a.pop(0)
            if cnt > 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()))

books = sorted(A+B)

cnt=0
max = N+M-1

print(books)

while True:
  print(books[cnt])
  
  K-=books[cnt]
  if K < 0:
    break
  elif cnt >= max:
    cnt+=1
    break    
  else:
    cnt+=1
  
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()))
res = 0
while k:
    if k == 0:
        break
    if k < 0:
        res -= 1
        break
    if len(a) == 0 and len(b) == 0:
        break
    if len(a) == 0:
        if b[0] > k:
            break
        else:
            k -= b.pop(0)
            res += 1
            continue
    if len(b) == 0:
        if a[0] > k:
            break
        else:
            k -= a.pop(0)
            res += 1
            continue
    if a[0] < b[0]:
        k -= a.pop(0)
        res += 1
        continue
    else:
        k -= b.pop(0)
        res += 1
        continue
print(res)

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
sum = 0
acount = 0
bcount = 0

while(sum <= k):
    if acount == len(a) and bcount == len(b):
        break

    elif acount == len(a):
        mi = b[bcount]
        sum += mi
        ans += 1
        bcount += 1

    elif bcount == len(b):
        mi = a[acount]
        sum += mi
        ans += 1
        acount += 1

    else:
        if a[acount] < b[bcount]:
            mi = a[acount]
            sum += mi
            ans += 1
            acount += 1
        else:
            mi = b[bcount]
            sum += mi
            ans += 1
            bcount += 1

if k < sum:
    print(ans - 1)
else:
    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
hon = 0
if min(a) > k or min(b) > k:
    print("0")
    quit()
while ans <= k :

    if  a and b:
        if a[0] > b[0]:
            ans += a[0]
            a.pop(0)
        else:
            ans += b[0]
            b.pop(0)
    elif not a and b:
        ans += b[0]
        b.pop(0)
    elif a and not b:
        ans += a[0]
        a.pop(0)
    else:
        break
    hon += 1
print(hon)

Submission status: Wrong Answer

Solution code:
# C - Tsundoku
def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    t = 0
    cnt = 0

    while True:
        if len(a) == 0 and len(b) == 0:
            print(cnt)
            exit()
        if len(a) == 0:
            t += b.pop(0)
            if t > k:
                print(cnt)
                exit()
            else:
                cnt += 1
        elif len(b) == 0:
            t += a.pop(0)
            if t > k:
                print(cnt)
                exit()
            else:
                cnt += 1


        elif a[0] >= b[0]:
            t += b.pop(0)
            if t > k:
                print(cnt)
                exit()
            else:
                cnt += 1

        else:
            t += a.pop(0)
            if t > k:
                print(cnt)
                exit()
            else:
                cnt += 1



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

a=N
b=M
count =0

while K != "sf":
    if a ==0 and b==0:
        break
    
    if a >0 and b > 0:
        if A[N-a] < B[M-b]:
            count += 1
            K -= A[N-a]
            a -=1
            
        elif A[N-a] > B[M-b]:
            count += 1
            K -=  B[M-b]
            b -=1
            
        elif A[N-a] == B[M-b]:
            if a-1>=0 and b-1 >=0:
                if A[N-a] <= B[M-b]:
                    count += 1
                    K -= A[N-a]
                    a -=1
            
                elif A[N-a] > B[M-b]:
                    count += 1
                    K -=  B[M-b]
                    b -=1
            elif a-1 >=0 and b-1 <0:
                count += 1
                K -= A[N-a]
                a -=1
            elif b-1 >=0 and a-1 <0:
                count += 1
                K -= B[M-b]
                b -=1
            else:
                count += 1
                K -= A[N-a]
                a -=1
                
            
    elif a>0 and b ==0:
        count += 1
        K -= A[N-a]
        a -=1
    elif b>0 and a ==0:
        count += 1
        K -= B[M-b]
        b -=1
        
    
    #print(count,K,N-a,M-b)
    
    if K < 0:
        count -= 1
        break
    
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()))
c = 0
ans = -1
ia = 0
ib = 0
while c <= K:
  ans += 1
  a = 0
  if ia == N and ib == M:
    a = K+1
   
  elif ia == N:
    a = B[ib]
    ib += 1
     
  elif ib == M:
    a = A[ia]
    ia += 1
    
  elif A[ia] <= B[ib]:
    a = A[ia]
    ia += 1
     
  else:
    a = B[ib]
    ib += 1
  c += a
print(ans)

Submission status: Wrong Answer

Solution code:
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(" ")]

if (N>10**8) | (M>10**8) |(K>10**8):
    print(0)
else:
    time=0
    a_idx=0
    b_idx=0
    count=0
    while time<K:
        count+=1
        try:
            if a_idx+1==N:
                time+=b[b_idx]
                b_idx+=1
                if time>K:
                    count-=1
                continue
            elif b_idx+1==M:
                time+=a[b_idx]
                a_idx+=1
                if time>K:
                    count-=1
                continue    

            if a[a_idx]<b[b_idx]:
                time+=a[a_idx]
                a_idx+=1

            elif a[a_idx]>b[b_idx]:
                time+=b[b_idx]
                b_idx+=1
            else:
                try:
                    a_com=a_idx
                    b_com=b_idx
                    while True:
                        if a[a_com]>b[b_com]:
                            time+=a[a_idx]
                            a_idx+=1
                            break
                        elif a[a_com]<b[b_com]:
                            time+=b[b_idx]
                            b_idx+=1
                            break
                        a_com+=1
                        b_com+=1
                except:
                    time+=a[a_idx]
                    a_idx+=1
            if time>K:
                count-=1            
        except:
            break
    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(' ')))
a.reverse()
b.reverse()

w=0
w=int(w)
t=0
t=int(t)
while(1):
    if len(a)>0 and len(b)>0:
        if a[-1]>=b[-1]:
            u=b[-1]
            s=0
        elif a[-1]<b[-1]:
            u=a[-1]
            s=1
        
        if t+u<=k:
            t=t+u
            w+=1
            if s==0:
                q=b.pop(-1)
            elif s==1:
                q=a.pop(-1)
        else:
            break

    elif len(a)>0 and len(b)==0:
        u=a[-1]
        if t+u<=k:
            t=t+u
            w+=1
            q=a.pop(-1)
        else:
            break

    elif len(a)==0 and len(b)>0:
        u=b[-1]
        if t+u<=k:
            t=t+u
            w+=1
            q=b.pop(-1)
        else:
            break
    elif len(a)==0 and len(b)==0:
        break

print(w)

Submission status: Wrong Answer

Solution code:
from collections import deque
import bisect
N,M,K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

#if(sum(As) + sum(Bs) <= K):
#    print(N + M)
#    exit()


Asruisekiwa = []
Bsruisekiwa = []

Asruisekiwa.append(As[0])
Bsruisekiwa.append(Bs[0])

for i, j in enumerate(As[1:]):
    Asruisekiwa.append(Asruisekiwa[-1]+j)

for i, j in enumerate(Bs[1:]):
    Bsruisekiwa.append(Bsruisekiwa[-1] + j)

#print(Asruisekiwa)
#print(Bsruisekiwa)

ans = 0
#print(Asruisekiwa)
#print(Bsruisekiwa)

if(Asruisekiwa[0] >= Bsruisekiwa[0]):
    tmp = Asruisekiwa
    Asruisekiwa = Bsruisekiwa
    Bsruisekiwa = tmp

Asruisekiwa.insert(0,0)
Bsruisekiwa.insert(0,0)

#print(Asruisekiwa)
#print(Bsruisekiwa)


for index, i in enumerate(Asruisekiwa):

    if(i > K):
        break

    tmp = i
    maxcheck = K - i


    hoge = bisect.bisect_left(Bsruisekiwa, maxcheck)

    ans = max(ans, index + hoge)

#        print(ans, tmp, hoge, maxcheck)

print(ans)

Submission status: Wrong Answer

Solution code:
def merge(x, y, a):
    i = 0
    j = 0
    while i < len(x) or j < len(y):
        if i == len(x):
            a[i+j] = y[j]
            j += 1
        elif j == len(y):
            a[i+j] = x[i]
            i += 1
        elif x[i] <= y[j]:
            a[i+j] = x[i]
            i += 1
        else:
            a[i+j] = y[j]
            j += 1
    return a
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[0]*(N+M)
C=merge(A,B,C)
for i in range(N+M):
    K-=C[i]
    if K<0:
        print(i)
        break
else:
    print(N+M)

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

a=0
b=0
tmp=0
count=0

while tmp <= K:
    if A_list[int(a)] <= B_list[int(b)]:#Aの机にある本のほうが短い時間で読めるとき
        tmp+=A_list[int(a)]
        a+=1
    else:#Bの机にある本のほうが短い時間で読めるとき
        tmp+=B_list[int(b)]
        b+=1
    count+=1
    if a >= len(A_list):#リストが空だったら
        A_list.append(10**9+1)
    if b >= len(B_list):#リストが空だったら
        B_list.append(10**9+1)
    if 0 <= tmp <= 10**9:
        pass
    else:
        tmp=10**9+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()))
a.insert(0, 0)
ans = 0
num_a = n
num_b = 0
flg = True

total_time = sum(a)

for i in range(n+1):
    if total_time > k:
        total_time -= a[num_a]
        num_a -= 1
    else:
        for j in range(num_b, m):
            if total_time + b[num_b] > k:
                flg = False
                break
            else:
                total_time += b[num_b]
                num_b += 1
                flg = True


ans = num_a + num_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()))

Sa = [0]*N
Sb = [0]*M
Sa[0] = A[0]
Sb[0] = B[0]
a = 0
b = 0
ans = 0
if Sa[0] > K:
    a = 0
else:
    for i in range(1, N):
        Sa[i] = Sa[i-1] + A[i]
        if Sa[i] > K:
            a = i
            break
    else:
        a = N

if Sb[0] > K:
    b = 0
else:
    for i in range(1, M):
        Sb[i] = Sb[i-1] + B[i]
        if Sb[i] > K:
            b = i
            break
    else:
        b = M

for i in range(a):
    temp = K - Sa[i]
    if temp < Sb[0]:
        ans = max(ans, i+1)
        continue
    elif temp >= Sb[max(0,b-1)]:
        ans = max(ans, i+1+b)
        continue
    ok = 0
    ng = b
    t = (ok+ng)//2
    while ok+1 < ng:
        t = (ok+ng)//2
        if temp >= Sb[t]:
            ok = t
        else:
            ng = t
    ans = max(ans, i+1+ok+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.append(K + 1)
B.append(K + 1)

count = -1
time = 0

while time <= K:
    count += 1
    if A[0] <= B[0]:
        time += A.pop(0)
    else:
        time += B.pop(0)

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

r = 0
s = 0
t = 0

for i in range(N):
  if Ali[i] <= K-t:
    r += 1
    t += Ali[i]
    
for i in range(M):
  if Bli[i] <= K-t:
    r += 1
    t += Bli[i]
    
for i in range(M):
  if Bli[i] <= K-t:
    s += 1
    t += Bli[i]
    
for i in range(N):
  if Ali[i] <= K-t:
    s += 1
    t += Ali[i]
    
print(max(r,s))

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
cnt = 0
a_idx = 0
b_idx = 0

while True:
    if a_idx < len(a) and b_idx < len(b):
        if a[a_idx] <= b[b_idx]:
            time += a[a_idx]
            if time > k:
                break
            a_idx += 1
            cnt += 1
        elif b[b_idx] < a[a_idx]:
            time += b[b_idx]
            if time > k:
                break
            b_idx += 1
            cnt += 1
    elif a_idx == len(a) and b_idx != len(b):
        time += b[b_idx]
        if time > k:
            break
        b_idx += 1
        cnt += 1
    elif a_idx != len(a) and b_idx == len(b):
        time += a[a_idx]
        if time > k:
            break
        a_idx += 1
        cnt += 1
    elif a_idx == len(a) and b_idx == len(b):
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
count = 0
i = 0
A_max = 0
for i in range(N + 1):
    count += A_list[i]
    if count > K:
        break
A_max = i
output = A_max + 2

for j in range(1, A_max + 1):
    alcount = sum(A_list[:j + 1])
    blcount = sum(B_list[:A_max - j + 1])
    total = alcount + blcount
    if total > K:
        continue
    else:
        for h in range(A_max - j + 1, M + 1):
            alcount += B_list[h]
            if alcount > K:
                break
            if j + h + 2 > output:
                output = j + h + 2
if A_list[1] > K and B_list[1] > K:
    print(output - 3)
elif B_list[1] > K:
    print(output - 3)
else:
    print(output - 2)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum = 0
j = 0
l = 0
count = 0

for i in range(10 ** 9 * 10 ** 9):


    if A == [] and B == []:
        break

    if A == [] or B == []:
        if A == []:
            if B[0] + sum <= K:
                sum += Decimal(B[0])
                B.pop(0)
                count += 1
                # j += 1
            else:
                break
        elif B == []:
            if A[0] + sum <= K:
                sum += Decimal(A[0])
                A.pop(0)
                count += 1
                # j += 1
            else:
                break
    else:
        if A[0] > B[0]:
            if B[0] + sum <= K:
                sum += Decimal(B[0])
                B.pop(0)
                count += 1
                # j += 1
            else:
                break
        else:
            if A[0] + sum <= K:
                sum += Decimal(A[0])
                A.pop(0)
                count += 1
                # l += 1
            else:
                break
        

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    
    AB = A + B
    AB.sort()
    read_time = 0
    ans = 0
    
    for i in range(len(AB)):
        read_time += AB[i]
        if read_time > K:
            break
        else:
            ans = i + 1
         
    print(f'{ans}')


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

A = [0]
B = [0]
A.extend(a)
B.extend(b)
time = sum(A)
ai = len(A)-1
bi = 0
con = 0
flg = None
count = 0

    

while True:
    print("---------")
    print(str(ai)+":"+str(bi))
    if time > K:
        if flg is not None:
            con = max(con,flg-1)
            flg = None
        
        if ai == 0:
            break
        time -=A[ai]
        ai -= 1
    else:
        print("b")
        flg = ai+bi
        time +=B[bi]
        bi += 1
        if bi == len(B):
            if time > K:
                if flg is not None:
                    con = max(con, flg-1)
                pass
            else:
                con = max(con,ai+bi-1)
            break
    print(flg)
print(con)

Submission status: Wrong Answer

Solution code:
root = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))      
a.append(1000000000)
b.append(1000000000)
minute=0
books=0
ai=0
bi=0

while minute <= root[2]:
    books += 1
    if a[ai] < b[bi]:
        minute += a[ai]
        ai += 1
    elif b[bi] < a[ai]:
        minute += b[bi]
        bi += 1
    else:
        if b[bi] == a[ai] == 1000000000:
            break
        if len(a) > ai:
            ai += 1
        elif len(b) > bi:
            bi += 1

print(books-1)

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

ans = 0
for n in range(N):
    for m in range(M):
        if K >= sum(A_list[:n+1])+sum(B_list[:m+1]):
            ans = max(ans, n+m+2)
            
print(ans)

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(idx_a, 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()))
c=a+b
ans=0
while k>min(c):
    if a==[]:
        k-=b[0]
        b.remove(b[0])
        ans+=1
    elif b==[]:
        k-=a[0]
        a.remove(a[0])
        ans+=1
    elif a==[] and b==[]:
        break
    else:               
        if a[0]<b[0]:
            k-=a[0]
            a.remove(a[0])
            ans+=1
        else:
            k-=b[0]
            b.remove(b[0])
            ans+=1
print(ans)

Submission status: Wrong Answer

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

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

B=[int(i) for i in input().split()]
flag=0
if ((k<A[0])|(k<B[0])):
    print(0)
    flag=1
count=0
time=0
if flag==0:
    for i in range(1,n+m+1):
        if ((time>k)|((A[0]==0)&(B[0]==0))):
            break
        if A[0]>B[0]:
            count+=1
            time+=A[0]
            del A[0]
        else:
            count+=1
            time+=B[0]
            del B[0]
        if A==[]:
            A.append(0)
        if B==[]:
            B.append(0)
    print(count)

Submission status: Wrong Answer

Solution code:
def main():
  M, N, K = map(int, input().split())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  spent_time = 0
  count = 0
  AB = A + B
  AB.sort()
  
  while(True):
    if count == M + N:
      break
    temp = AB[count]
    #print(temp, spent_time)
    if spent_time + temp > K:
      break
    spent_time = spent_time + temp
    count += 1
  
  #print('----')
  #print(spent_time)
  print(count)
  
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()))

ia = 0
ib = 0
book = 0
minute = 0

while minute < k:
    if a[ia] > b[ib]:
        minute += b[ib]
        book += 1
        if minute > k:
            book -= 1
        ib += 1
        if ib == m:
            ib = m - 1
            b[ib] = float('inf')
    else:
        minute += a[ia]
        book += 1
        if minute > k:
            book -= 1
        ia += 1
        if ia == n:
            ia = n - 1
            a[ia] = float('inf')


print(book)

Submission status: Wrong Answer

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

if sum(a) + sum(b) <= k:
    print(len(a) + len(b))
else:
    ans = 0
    x = a.pop()
    y = b.pop()
    v = len(a)
    w = len(b)
    while k > 0:
        k -= min(x, y)
        if k < 0:
                break
        if x > y:
            if w == 0:
                y = 10**9+1
            else:
                y = b.pop()
                w -= 1
        else:
            if v == 0:
                x = 10**9+1
            else:
                x = a.pop()
                v -= 1
        ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
I = list(map(int,input().split()))

N = I[0]
M = I[1]
K = I[2]

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

A_top = 0
B_top = 0
time = 0
result = 0

A_over = -1
B_over = -1

Asum = 0
Bsum = 0

for iter in range(len(A)):
    Asum += A[iter]
    if Asum > K:
        A_over = iter
        break

for iter in range(len(B)):
    Bsum += B[iter]
    if Bsum > K:
        B_over = iter
        break


while time < K:
    if A_over == A_top and B_over == B_top:
        break

    if B_top >= len(B) and A_top < len(A) and time + A[A_top] <= K:
        time += A[A_top]  
        A_top += 1
        continue
    elif B_top >= len(B) and time + A[A_top] > K:
        break

    if A_top >= len(A) and B_top < len(B) and time + B[B_top] <= K:
        time += B[B_top]
        B_top += 1
        continue
    elif A_top >= len(A) and time + B[B_top] > K:
        break
    
    if A[A_top] <= B[B_top] and time + A[A_top] <= K:
        time += A[A_top]
        A_top += 1
        continue

    if A[A_top] >= B[B_top] and time + B[B_top] <= K:
        time += B[B_top]
        B_top += 1
        continue


    
    break

result = A_top + B_top
# if time > K and result > 0:
#     result -= 1

print(result)

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 = 0
n = 0
a = 0
b = 0

while K >= t :
    if a < N and b < M :
        if A[a] < B[b] :
            t += A[a]
            n += 1
            a += 1

        elif A[a] > B[b] :
            t +=B[b]
            n += 1
            b += 1
        
        else :
            if sum(A) <= sum(B) :
                t += A[a]
                n += 1
                a += 1
            
            else :
                t +=B[b]
                n += 1
                b += 1
    
    elif a == N and b < M:
        while b < M :
            t += B[b]
            n += 1
            b += 1
        
        else :
            break

    else :
        while a < N :
            t += A[a]
            n += 1
            a += 1

print(n)

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,K=nm()
INF=10**18
A=nl()
B=nl()
A.append(INF)
B.append(INF)
A_c=0
B_c=0
ans=0
sum_l_A=[INF]*(N+2)
sum_l_B=[INF]*(M+2)

sum_l_A[0]=0
sum_l_B[0]=0
for i in range(1,N+2):
    sum_l_A[i]=sum_l_A[i-1]+A[i-1]

for i in range(1,M+2):
    sum_l_B[i]=sum_l_B[i-1]+B[i-1]



ans=0
a_c=0
b_c=0
for j in range(N+M+4):
    resume=0
    if(sum_l_A[a_c+1]<=sum_l_B[b_c+1]):
        a_c+=1
    else:
        b_c+=1
    resume=sum_l_A[a_c]+sum_l_B[b_c]
    if(K<=resume):
        print(ans)
        sys.exit(0)
    ans+=1

Submission status: Wrong Answer

Solution code:
n, m, p = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ta = sum(a)
tb = sum(b)
tt = ta + tb
l = n + m
j, k = 0, 0
sumc = 0
countc = 0
for i in range(l):
  ca = a[j:j+1]
  cb = b[k:k+1]
  caa = int(ca[0])
  cbb = int(cb[0])
  if (tt - caa) > (tt - cbb):
    tt -= caa
    sumc += caa
    if sumc > p:
      break
    countc += 1    
    j += 1
  else:
    tt -= cbb
    sumc += cbb
    if sumc > p:
      break
    countc += 1
    k += 1
  if (j == n):
    for j in range(m - k):
      ccb = b[k:k+1]
      ccbb = int(ccb[0]) 
      tt -= ccbb
      sumc += ccbb
      if sumc > p:
        break
      countc += 1
      k += 1
    break
  if (k == m):
    for j in range(n - j):
      cca = a[j:j+1]
      ccaa = int(cca[0])
      tt -= ccaa
      sumc += ccaa
      if sumc > p:
        break
      countc += 1
      j += 1
    break
print(countc)

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()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    k = K - A[i] - B[j]
    if k >= 0:
        r = max(r, i + j)
print(r)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int, input().split())
#N,M,K=3, 4, 240
A = [0]
B = [0]
A = list(map(int, input().split()))
#A += [60,90,120]
B = list(map(int, input().split()))
#B += [80,150, 80, 150]

As = A.copy()
for i in range(1, len(As)):
    As[i] += As[i-1]
    
Bs = B.copy()
for i in range(1, len(Bs)):
    Bs[i] += Bs[i-1]

Ans = len(As) + len(Bs)

while True:
    L = [(i,Ans-i) for i in range(Ans+1)]
    for i in range(len(L)):
        if L[i][0] < len(As) and L[i][1] < len(Bs):
            if As[L[i][0]] + Bs[L[i][1]] <= K:
                print(Ans)
                exit()
                
    Ans -= 1
    if Ans == 0:
        print(0)
        exit()

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_a=sum(a)
sum_b=sum(b)

cumsum=0
cnt=0
i=0
j=0
while True:
    if i<=n-1:
        a_i=a[i]
    else:
        a_i=10**9+1
    
    if j<=m-1:
        b_j=b[j]
    else:
        b_j=10**9 + 1

    if a_i < b_j:
        cumsum+=a_i
        sum_a-=a_i
        i+=1
    elif a_i > b_j:
        cumsum+=b_j
        sum_b-=b_j
        j+=1
    elif a_i==b_j:
        if sum_a<=sum_b:
            cumsum+=a_i
            sum_a-=a_i
            i+=1
        else:
            cumsum+=b_j
            sum_b-=b_j
            j+=1
    
    if cumsum<=k:
        cnt+=1
    else:
        break

    if i>n-1 and j>m-1:
        break

print(cnt)