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())
DeskA = list(map(int,input().split()))
DeskB = list(map(int,input().split()))
Time = 0
countA=0
countB=0
result=0
while(Time<K):
    if(DeskA[countA]<=DeskB[countB] and Time+DeskA[countA] <= K):
        Time += DeskA[countA]
        if(countA==N-1):
            DeskA[countA]=2000000000
            result += 1
        else:
            countA += 1
    elif(DeskB[countB]<=DeskA[countA] and Time+DeskB[countB] <= K):
        Time += DeskB[countB]
        if(countB==M-1):
            DeskB[countB]=2000000000
            result += 1
        else:
            countB += 1
    else:
        break
print(result+countA+countB)

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()))
Time = 0
countA=0
countB=0
result=0
while(Time<K):
    if(DeskA[countA]<DeskB[countB] and Time+DeskA[countA] <= K):
        Time += DeskA[countA]
        if(countA==N-1):
            DeskA[countA]=2000000000
            result += 1
        else:
            countA += 1
    elif(DeskB[countB]<DeskA[countA] and Time+DeskB[countB] <= K):
        Time += DeskB[countB]
        if(countB==M-1):
            DeskB[countB]=2000000000
            result += 1
        else:
            countB += 1
    else:
        break
print(result+countA+countB)

Submission status: Wrong Answer

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


def cusum(array):
    for i in range(len(array) - 1):
        array[i + 1] += array[i]


cusum(A)
cusum(B)
tsundoku = 0
ia = 0
ib = len(B) - 1

for ia, x in enumerate(A):
    if x >= K:
        break
    while x + B[ib] > K and ib >= 0:
        if (x + B[ib]) <= K:
            break
        ib -= 1
    if (ia + ib) > tsundoku - 2:
        tsundoku = ia + ib + 2

print(tsundoku)

Submission status: Wrong Answer

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


def cusum(array):
    for i in range(len(array) - 1):
        array[i + 1] += array[i]


cusum(A)
cusum(B)
tsundoku = 0
ia = 0
ib = len(B) - 1

for ia, x in enumerate(A):
    if x > K:
        break
    while x + B[ib] > K and ib > 0:
        if (x + B[ib]) <= K:
            break
        ib -= 1
    if (ia + ib) > tsundoku - 2:
        tsundoku = ia + ib + 2

print(tsundoku)

Submission status: Wrong Answer

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


def cusum(array):
    for i in range(len(array) - 1):
        array[i + 1] += array[i]


cusum(A)
cusum(B)
tsundoku = 0
ia = 0
ib = len(B) - 1

for ia, x in enumerate(A):
    if x > K:
        break
    while x + B[ib] > K and ib >= 0:
        if (x + B[ib]) <= K:
            break
        ib -= 1
    if (ia + ib) > tsundoku - 2:
        tsundoku = ia + ib + 2

print(tsundoku)

Submission status: Wrong Answer

Solution code:
import sys

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB_list = []
time_sum = 0
ans = 0

if A[0] > K or B[0] > K:
  print(0)
  sys.exit()

for _ in range(len(A) + len(B)):
  if len(A) == 0:
    AB_list.append(B[0])
    B.pop(0)
  elif len(B) == 0:
    AB_list.append(A[0])
    A.pop(0)
  elif A[0] <= B[0]:
    AB_list.append(A[0])
    A.pop(0)
  else:
    AB_list.append(B[0])
    B.pop(0)
    
for i in range(len(AB_list)):
  time_sum += AB_list[0]
  if time_sum > K:
    break
  ans += 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB_list = []
time_sum = 0
ans = 0

if A[0] > K or B[0] > K:
  print(0)
  sys.exit()

for _ in range(len(A) + len(B)):
  if len(A) == 0:
    AB_list.append(B[0])
    B.pop(0)
  elif len(B) == 0:
    AB_list.append(A[0])
    A.pop(0)
  elif A[0] <= B[0]:
    AB_list.append(A[0])
    A.pop(0)
  else:
    AB_list.append(B[0])
    B.pop(0)
    
for _ in range(len(AB_list)):
  time_sum += AB_list[0]
  AB_list.pop(0)
  if time_sum > K:
    break
  ans += 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB_list = []
time_sum = 0
ans = 0

if A[0] > K or B[0] > K:
  print(0)
  sys.exit()

for _ in range(len(A) + len(B)):
  if len(A) == 0:
    AB_list.append(B[0])
    B.pop(0)
  elif len(B) == 0:
    AB_list.append(A[0])
    A.pop(0)
  elif A[0] <= B[0]:
    AB_list.append(A[0])
    A.pop(0)
  else:
    AB_list.append(B[0])
    B.pop(0)
    
while len(AB_list) > 0:
  time_sum += AB_list[0]
  AB_list.pop(0)
  if time_sum > K:
    break
  ans += 1
  
print(ans)

Submission status: Wrong Answer

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

read_a = 0
read_b = 0
time = 0

while True:
    time += min(a[read_a],b[read_b])

    if time > k:
        print(read_a + read_b)
        sys.exit()
    
    if a[read_a] <= b[read_b]:
        read_a += 1
        if read_a >= n:
            a.append(10**6)
            
    else:
        read_b += 1
        if read_b >= m:
            b.append(10**6)

Submission status: Wrong Answer

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

read_a = 0
read_b = 0
time = 0

while True:
    time += min(a[read_a],b[read_b])

    if time > k:
        print(read_a + read_b)
        sys.exit()
    
    if a[read_a] <= b[read_b]:
        read_a += 1
        if read_a >= n:
            a.append(10**6)
            
    else:
        read_b += 1
        if read_b >= m:
            b.append(10**6)

Submission status: Wrong Answer

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

for i in range(1,n+1): a[i]=a[i]+a[i-1]
for i in range(1,m+1): b[i]=b[i]+b[i-1]
j=m-1
ans=0
for i in range(n):
    if j<0: break
    while a[i]+b[j]>k and j>=0: j-=1
    ans=max(i+j,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()))

for i in range(1,n): a[i]=a[i]+a[i-1]
for i in range(1,m): b[i]=b[i]+b[i-1]
if a[0]>k or b[0]>k:
    print(0)
    exit()
j=m-1
ans=0
for i in range(n):
    if j<0: break
    while a[i]+b[j]>k and j>=0: j-=1
    ans=max(i+j+2,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()))

for i in range(1,n): a[i]=a[i]+a[i-1]
for i in range(1,m): b[i]=b[i]+b[i-1]
j=m-1
ans=0
for i in range(n):
    if j<0: break
    while a[i]+b[j]>k and j>=0: j-=1
    ans=max(i+j+2,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()))
ans=0
time=0
while True:
    if len(a)==0 and len(b)==0:
        break
    if len(a)==0 and len(b)!=0:
        if time+b[0]>k:
            break
        else:
            time+=b[0]
            b.pop(0)
            ans+=1
            continue
    if len(a)!=0 and len(b)==0:
        if time+a[0]>k:
            break
        else:
            time+=a[0]
            a.pop(0)
            ans+=1
            continue
    if time+min(a[0],b[0])>k:
        break
    else:
        time+=min(a[0],b[0])
    if a[0]<b[0]:
        a.pop(0)
    else:
        b.pop(0)
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(x) for x in input().split(' ')]
a_costs = [0]
a_costs.extend([int(x) for x in input().split(' ')])
b_costs = [0]
b_costs.extend([int(x) for x in input().split(' ')])
for i in range(1, len(a_costs)):
    a_costs[i] += a_costs[i - 1]
    if (a_costs[i] > k):
        break
for i in range(1, len(b_costs)):
    b_costs[i] += b_costs[i - 1]
    if (b_costs[i] > k):
        break
max_count = 0
for ai in range(0, len(a_costs)):
    remain_cost = k - a_costs[ai]
    if (remain_cost <= 0):
        break
    min_req_count = max_count - ai
    for bi in range(max(min_req_count, 0), len(b_costs)):
        if (b_costs[bi] <= remain_cost):
            max_count = ai + bi
        else:
            break
print(max_count)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(x) for x in input().split(' ')]
a_costs = [0]
a_costs.extend([int(x) for x in input().split(' ')])
b_costs = [0]
b_costs.extend([int(x) for x in input().split(' ')])
for i in range(1, len(a_costs)):
    a_costs[i] += a_costs[i - 1]
    if (a_costs[i] > k):
        break
for i in range(1, len(b_costs)):
    b_costs[i] += b_costs[i - 1]
    if (b_costs[i] > k):
        break
max_count = 0
for ai in range(0, len(a_costs)):
    exit_flag = False
    for bi in range(0, len(b_costs)):
        if (a_costs[ai] + b_costs[bi] <= k):
            max_count = ai + bi
        else:
            if bi == 0:
                exit_flag = True
            break
    if (exit_flag):
        break
print(max_count)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(x) for x in input().split(' ')]
a_costs = [0]
a_costs.extend([int(x) for x in input().split(' ')])
b_costs = [0]
b_costs.extend([int(x) for x in input().split(' ')])
for i in range(1, len(a_costs)):
    a_costs[i] += a_costs[i - 1]
for i in range(1, len(b_costs)):
    b_costs[i] += b_costs[i - 1]
max_count = 0
for ai in range(0, len(a_costs)):
    exit_flag = False
    for bi in range(0, len(b_costs)):
        if (a_costs[ai] + b_costs[bi] <= k):
            max_count = ai + bi
        else:
            if bi == 0:
                exit_flag = True
            break
    if (exit_flag):
        break
print(max_count)

Submission status: Wrong Answer

Solution code:
#n,m,k=map(int,input().split())
m,n,k=map(int,input().split())
#a=[int(i) for i in input().split()]
#b=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
ans=chk=w=0
for i in range(n):
    if k>=a[i]:
        chk+=1
        k-=a[i]
        w=i
        ans=max(ans,chk)
    else:
        break

for i in range(m):
    if k<b[i]:
        while w>=0:
            if k>=b[i]: break
            k+=a[w]
            chk-=1
            w-=1
    if k>=b[i]:
        chk+=1
        k-=b[i]
        ans=max(ans,chk)
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(x) for x in input().split(' ')]
a_costs = [0]
a_costs.extend([int(x) for x in input().split(' ')])
b_costs = [0]
b_costs.extend([int(x) for x in input().split(' ')])
for i in range(1, len(a_costs)):
    a_costs[i] += a_costs[i - 1]
for i in range(1, len(b_costs)):
    b_costs[i] += b_costs[i - 1]
max_count = 0
for ai in range(0, len(a_costs)):
    for bi in range(0, len(b_costs)):
        if (a_costs[ai] + b_costs[bi] <= k):
            max_count = ai + bi
print(max_count)

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()]
ans=chk=w=0
for i in range(n):
    if k>=a[i]:
        chk+=1
        k-=a[i]
        w=i
        ans=max(ans,chk)
    else:
        break

for i in range(m):
    if k<b[i]:
        while w>=0:
            if k>=b[i]: break
            k+=a[w]
            chk-=1
            w-=1
    if k>=b[i]:
        chk+=1
        k-=b[i]
        ans=max(ans,chk)
    else:
        break
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()]
ans=chk=0
w=[0,0]
for i in range(n):
    if k>=a[i]:
        chk+=1
        k-=a[i]
        w[0]=i
        ans=max(ans,chk)
    else:
        break

for i in range(m):
    if k<b[i]:
        while w[0]>=0:
            if k>=b[i]: break
            k+=a[w[0]]
            chk-=1
            w[0]-=1
    if k>=b[i]:
        chk+=1
        k-=b[i]
        w[1]=i
        ans=max(ans,chk)
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()][::-1]
b=[int(i) for i in input().split()][::-1]
ans=chk=0
w=[0,0]
for i in range(n):
    if k>=a[i]:
        chk+=a[i]
        k-=a[i]
        w[0]=i
        ans=max(ans,chk)
    else:
        break

for i in range(m):
    if k<b[i]:
        while w[0]>=0:
            if k>=b[i]: break
            k+=a[w[0]]
            w[0]-=1
    if k>=b[i]:
        chk+=b[i]
        k-=b[i]
        w[1]=i
        ans=max(ans,chk)
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k,*ab=map(int,open(0).read().split())
a=ab[:n]
b=ab[n:]
ans=0
i=0
j=0
while k>=0:
  if n==i:
    if m==j:
      break
    else:
      k-=b[j]
      j+=1
  elif m==j:
    k-=a[i]
    i+=1
  else:
    mini=a[i] if a[i]<b[j] else b[j]
    if a[i]>b[j]:
      j+=1
    else:
      i+=1
    k-=mini
  if k>=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k,*ab=map(int,open(0).read().split())
a=ab[:n]
b=ab[n:]
ans=0
i=0
j=0
while k>=0:
  ans+=1
  if n==i:
    if m==j:
      break
    else:
      k-=b[j]
      j+=1
  elif m==j:
    k-=a[i]
    i+=1
  else:
    mini=a[i] if a[i]<b[j] else b[j]
    if a[i]>b[j]:
      j+=1
    else:
      i+=1
    k-=mini
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()))

t = 0
count = 0
while 1:
  if len(a) > 0 and len(b) > 0:
    if a[0] <= b[0]:
      t += a[0]
      a.pop(0)
    else:
      t += b[0]
      b.pop(0)
  elif len(a) > 0 and len(b) == 0:
    t += a[0]
    a.pop(0)
  elif len(a) == 0 and len(b) > 0:
    t += b[0]
    b.pop(0)
  else:
    break
  if t <= K:
    count += 1
  else:
    print(count)
    exit()
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()))

t = 0
count = 0
while 1:
  if len(a) > 0 and len(b) > 0:
    if a[0] < b[0]:
      t += a[0]
      a.pop(0)
    else:
      t += b[0]
      b.pop(0)
  elif len(a) > 0 and len(b) == 0:
    t += a[0]
    a.pop(0)
  elif len(a) == 0 and len(b) > 0:
    t += b[0]
    b.pop(0)
  else:
    break
  if t <= K:
    count += 1
  else:
    print(count)
    exit()
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k,*ab=map(int,open(0).read().split())
a=ab[:n]
b=ab[n:]
ans=0
i=0
j=0
while k>=0:
  ans+=1
  if len(a)==i:
    if len(b)==j:
      break
    else:
      k-=b[j]
      j+=1
  elif len(b)==j:
    k-=a[i]
    i+=1
  else:
    mini=min(a[i],b[j])
    if a[i]>b[j]:
      j+=1
    else:
      i+=1
    k-=mini
print(ans-1)

Submission status: Wrong Answer

Solution code:
n,m,k,*ab=map(int,open(0).read().split())
a=ab[:n]
b=ab[n:]
ans=0
i=0
j=0
while k>=0:
  ans+=1
  if len(a)==i:
    if len(b)==j:
      break
    else:
      k-=b[j]
      j+=1
  elif len(b)==j:
    k-=a[i]
    i+=1
  else:
    mini=min(a[0],b[0])
    if a[0]>b[0]:
      j+=1
    else:
      i+=1
    k-=mini
print(ans-1)

Submission status: Wrong Answer

Solution code:
n,m,k,*ab=map(int,open(0).read().split())
a=ab[:n]
b=ab[n:]
ans=0
while k>=0:
  ans+=1
  if len(a)==0:
    if len(b)==0:
      break
    else:
      k-=b.pop(0)
  elif len(b)==0:
    k-=a.pop(0)
  else:
    m=min(a[0],b[0])
    if a[0]>b[0]:
      del b[0]
    else:
      del a[0]
    k-=m
print(ans-1)

Submission status: Wrong Answer

Solution code:
n,m,k,*ab=map(int,open(0).read().split())
a=ab[:n]
b=ab[n:]
ans=0
while n>=0:
  ans+=1
  if len(a)==0:
    if len(b)==0:
      break
    else:
      n-=b.pop(0)
  elif len(b)==0:
    n-=a.pop(0)
  else:
    m=min(a[0],b[0])
    if a[0]>b[0]:
      del b[0]
    else:
      del a[0]
    n-=m
print(ans-1)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            i_b -= 1
            break
        else :
            K -= B[i_b]
    
    count = (i_a+1) + (i_b+1) # 読んだ本のindexの次のindexが格納されている。
    # 1冊も読めない⇒0
    # idx = i_a,i_bまで読んだ。
    # forの繰り返しをすべて終えた時 +1されるのか?
    for i in range(i_a,-1,-1): # A のアイテムを1つずつ減らしていく。
        K += A[i] # i番目の本を読まなかったとする。
        for j in range(i_b,len(B)):
            if K < B[j]:
                j -= 1
                break
            else:
                K -= B[j]
        count = max(count,(i+j+1))
    print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            i_b -= 1
            break
        else :
            K -= B[i_b]
    
    count = (i_a+1) + (i_b+1) # 読んだ本のindexの次のindexが格納されている。
    # 1冊も読めない⇒0
    # idx = i_a,i_bまで読んだ。
    # forの繰り返しをすべて終えた時 +1されるのか?
    print("{}+{}={}".format(i_a,i_b,count))
    for i in range(i_a,-1,-1): # A のアイテムを1つずつ減らしていく。
        K += A[i] # i番目の本を読まなかったとする。

        j = 0
        for j in range(i_b+1,len(B)):
            if K < B[j]:
                j -= 1
            else :
                K -= B[j]
        print("i_a:{},i_b:{}".format(i,i_b))
        i_b = j
        # A ⇒ i
        # B ⇒ 　
        count = max(count,(i+i_b))
    print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            i_b -= 1
            break
        else :
            K -= B[i_b]
    
    count = (i_a+1) + (i_b+1) # 読んだ本のindexの次のindexが格納されている。
    # 1冊も読めない⇒0
    # idx = i_a,i_bまで読んだ。
    # forの繰り返しをすべて終えた時 +1されるのか?
    print("{}+{}={}".format(i_a,i_b,count))
    for i in range(i_a,-1,-1): # A のアイテムを1つずつ減らしていく。
        K += A[i] # i番目の本を読まなかったとする。

        j = 0
        for j in range(i_b+1,len(B)):
            if K < B[j]:
                j -= 1
            else :
                K -= B[j]
        i_b = j + 1
        # A ⇒ i
        # B ⇒ 　
        count = max(count,(i+i_b))
    print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            break
        else :
            K -= B[i_b]
    
    count = i_a + i_b
    i_a,i_b = (i_a-1),(i_b-1)

    # idx = i_a,i_bまで読んだ。
    for i in range((i_a),-1,-1): # A のアイテムを1つずつ減らしていく。
        K += A[i]
        while True:
            if i_b >= len(B):
                break
            if K < B[i_b] :
                break
            else :
                K -= B[i_b]
                i_b += 1
        count = max(count,((i+1)+(i_b)))
    print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            break
        else:
            K -= A[i_a]
    # replace B item
    while True:
        if i_b >= len(B):
            break

        if K < B[i_b] :
            break
        else :
            K -= B[i_b]
            count += 1
            i_b += 1
    for i in range((i_a-1),-1,-1): # A のアイテムを1つずつ減らしていく。
        K += A[i]
        while True:
            if i_b >= len(B):
                break
            if K < B[i_b] :
                break
            else :
                K -= B[i_b]
                i_b += 1
        count = max(count,((i+1)+(i_b)))
    print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            break
        else:
            count += 1
            K -= A[i_a]
    # replace B item
    while True:
        if i_b >= len(B):
            break
        
        if K < B[i_b] :
            break
        else :
            K -= B[i_b]
            count += 1
            i_b += 1
    for i in range((i_a-1),-1,-1):
        K += A[i]
        while True:
            if i_b >= len(B):
                break
            if K < B[i_b] :
                break
            else :
                K -= B[i_b]
                i_b += 1
        count = max(count,((i+1)+(i_b)))
    print(count)

Submission status: Wrong Answer

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

i,j=0,0
res=0
tot=0
while i<n or j<m:
  a1=999999999999
  a2=999999999999
  if i<n:
    a1 = narr[i]
  if j<m:
    a2 = marr[j]
  if a1<a2:
    i+=1
  else:
    j+=1  
  tot+=min(a1,a2)
  res+=1
  if tot > k:
    res-=1
    break
print(res)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
As.extend(Bs)
As.sort()
x = 0
i = 0
while x < K:
  x += As[i]
  i = i + 1
print(i - 1)

Submission status: Wrong Answer

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

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

if a[0] > k:
    res = 0
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            res += 1
        else:
            break
    print(res)
else:
    cnt = 0
    a_idx = 0
    for i in range(n):
        if a[i] <= k:
            k -= a[i]
            cnt += 1
            a_idx = i
        else:
            break
    
    b_idx = 0
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            cnt += 1
            b_idx = i
        else:
            break
    
    res = cnt

    for i in range(a_idx,-1,-1):
        k += a[i]
        cnt -= 1
        fi = b_idx
        for j in range(b_idx+1,m):
            if b[j] <= k:
                k -= b[j]
                cnt += 1
                fi = j
            else:
                break
        b_idx = fi
        res = max(res,cnt)
    print(res)

Submission status: Wrong Answer

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

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

if a[0] > k:
    res = 0
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            res += 1
        else:
            break
    print(res)
else:
    cnt = 0
    a_idx = n-1
    for i in range(n):
        if a[i] <= k:
            k -= a[i]
            cnt += 1
            a_idx = i
        else:
            break
    
    b_idx = m-1
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            cnt += 1
            b_idx = i
        else:
            break
    
    res = cnt

    for i in range(a_idx,-1,-1):
        k += a[i]
        cnt -= 1
        fi = b_idx
        for j in range(b_idx+1,m):
            if b[j] <= k:
                k -= b[j]
                cnt += 1
                fi = j
            else:
                break
        b_idx = fi
        res = max(res,cnt)
    print(res)

Submission status: Wrong Answer

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

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

if a[0] > k:
    res = 0
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            res += 1
        else:
            break
    print(res)
else:
    cnt = 0
    a_idx = n-1
    for i in range(n):
        if a[i] <= k:
            k -= a[i]
            cnt += 1
            a_idx = i
        else:
            break
    
    b_idx = m-1
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            cnt += 1
            b_idx = i
        else:
            break
    
    res = cnt

    for i in range(a_idx,-1,-1):
        k += a[i]
        cnt -= 1
        fi = b_idx
        for j in range(b_idx+1,m):
            if b[j] <= k:
                k -= b[j]
                cnt += 1
                fi = b_idx
            else:
                break
        res = max(res,cnt)
    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()))

for i in range(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)

x = 0
jmax = 0
for i in range(n+1):
    for j in range(m+1):
        if b[j] <= k-a[i]:
            pass
        else:
            jmax = j-1
            if jmax + i > x:
                x = jmax + i
            break
print(x)

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(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)

x = 0
jmax = 0
for i in range(n+1):
    for j in range(jmax, m+1):
        if b[m-j] > k-a[i]:
            pass
        else:
            jmax = m-j
            if jmax + i > x:
                x = jmax + i
            break
print(x)

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(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)
print(a)
print(b)
x = 0
for i in range(n+1):
    for j in range(m+1):
        if b[m-j] > k-a[i]:
            pass
        else:
            jmax = m-j
            if jmax + i > x:
              x = jmax + i
print(x)

Submission status: Wrong Answer

Solution code:
def total_time(l, max_t):
    total_t = [0]
    for i in range(len(l)):
        if (l[i] + total_t[i]) > max_t:
            break
        total_t.append(l[i]+total_t[i])
    return total_t

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

A_total = total_time(A, K)
B_total = total_time(B, K)

i1 = len(A_total)
i2 = len(B_total)

if i1 == 1:
    print(i2-1)
    exit()
elif i2 == 1:
    print(i1-1)
    exit()

max_time = A_total[i1-1] 
max_book = len(A_total) - 1
   
for i in range(1,i1):
    for j in range (i2-1,0,-1):
        t = A_total[i] + B_total[j]
        if t > K:
            continue
        if max_time < t:
            max_time = t
            max_book = i + j
            break

print(max_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()))
sum = 0
count = 0
while k >= sum:
  if a[0] <= b[0]:
    if a[0] <= k-sum:
      sum += a[0]
      a.pop(0)
      a.append(k+1)
    else:
      break
  else:
    if b[0] <= k-sum:
      sum += b[0]
      b.pop(0)
      b.append(k+1)
    else:
      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()))

total_read_time = 0
num_read_books = 0
for i in range(N+M):
    if A == [] and B == []:
        break
    elif A == [] and B != []:
        read_book_time = B[0]
        del B[0]
    elif B == [] and A != []:
        read_book_time = A[0]
        del A[0]
    elif A[0] <= B[0]:
        read_book_time = A[0]
        del A[0]
    else:
        read_book_time = B[0]
        del B[0]


    total_read_time += read_book_time
    if total_read_time > K:
        break
    num_read_books += 1

print(num_read_books)

Submission status: Wrong Answer

Solution code:
n, m, k =map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ta=sum(a)
a.append(0)
tb=0
ans=0

for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    for j in range(m):
        tb += b[j]
        if tb + ta >k:
            break
        if j==m-1:
            j +=1

    ans=max(ans,n-i+j)

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()))
ta=sum(a)
a.append(0)
tb=0
ans=0

for i in range(n+1):
    ta -= a[n-i]
    for j in range(m):
        tb += b[j]
        if tb + ta >k:
            break
        if j==m-1:
            j +=1

    ans=max(ans,n-i+j)

print(ans)