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()))
a = []
b = []
p = 0
for i in range(N):
  p += A[i]
  a.append(p)
q = 0
for j in range(M):
  q += B[j]
  b.append(q)
ans = 0
j = M - 1
for i in range(N):
  while j >= 0:
    if a[i] + b[j] <= K:
      ans = i + j + 2
      break
    j -= 1
  if j < 0:
    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()))
a = []
b = []
p = 0
for i in range(N):
  p += A[i]
  a.append(p)
q = 0
for j in range(M):
  q += B[j]
  b.append(q)
ans = 0
j = M - 1
for i in range(N):
  while j >= 0:
    if a[i] + b[j] < K:
      ans = i + j + 2
      break
    j -= 1
  if j < 0:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

n,m,k=map(int,input().split())
a_acum=list(accumulate(list(map(int,input().split()))))
b_acum=list(accumulate(list(map(int,input().split()))))

def ask_number(data,value):
    start,end=0,len(data)
    while True:
        mid=(start+end)//2
        if start == mid:
            break
        if data[mid] > value:
            end=mid
        else:
            start=mid
    if start == 0 and data[0] > value:
        return 0
    else:
        return end
    
ans=ask_number(b_acum,k)

for i in range(n):
        sub = k - a_acum[i]
        if sub <=0:
            break
        else:
            ans=max(ans,ask_number(b_acum,sub)+i+1)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(i) for i in input().split()]
a = [0] + [int(i) for i in input().split()]
b = [0] + [int(i) for i in input().split()]
for i in range(1, n+1):
  a[i] += a[i-1]
for i in range(1, m+1):
  b[i] += b[i-1]
cnt, cnt_ = 0, 0
for i in range(n+1):
  if a[i] <= k:
    cnt = i
for j in range(m+1):
  if b[j] + a[cnt] <= k:
    cnt_ = j
ans = cnt + cnt_
for i in range(cnt):
  for j in range(cnt_, m+1):
    if a[cnt - i - 1] + b[j] > k:
      cnt_ = j
    else:
      ans = max(ans, cnt - i - 1 + j)
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()]
a_ = a.pop(0)
b_ = b.pop(0)
cnt = 0
cnt_t = 0
while True:
  if a_ < b_ and cnt_t + a_ <= k:
    cnt += 1
    cnt_t += a_
    if a:
      a_ = a.pop(0)
    else:
      if cnt_t + b_ <= k:
          cnt += 1
          cnt_t += b_
      for b_ in b:
        if cnt_t + b_ <= k:
          cnt += 1
          cnt_t += b_
        else:
          break
      print(cnt)
      break
  elif cnt_t + b_ <= k:
    cnt += 1
    cnt_t += b_
    if b:
      b_ = b.pop(0)
    else:
      if cnt_t + a_ <= k:
          cnt += 1
          cnt_t += a_
      for a_ in a:
        if cnt_t + a_ <= k:
          cnt += 1
          cnt_t += a_
        else:
          break
      print(cnt)
      break
  else:
    print(cnt)
    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()))

if K>=(sum(A)+sum(B)):#全部読みきれる場合
  print(N+M)
else:#全部読みきれない場合

  A.append(100000000000)
  B.append(1000000000000)
  ans=0
  time=0
  a=0
  b=0

  while time<K:
    if A[a]<=B[b]:
      time+=A[a]
      ans+=1
      a+=1

    elif B[b]<A[a]:
      time+=B[b]
      ans+=1
      b+=1
  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()))

if K>=(sum(A)+sum(B)):
  print(N+M)
else:

  A.append(1000000000000)
  B.append(1000000000000)
  ans=0
  time=0
  a=0
  b=0

  while time<K:
    if A[a]<=B[b]:
      time+=A[a]
      ans+=1
      a+=1

    elif B[b]<=A[a]:
      time+=B[b]
      ans+=1
      b+=1
  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()))

if K>=(sum(A)+sum(B)):
  print(N+M)
else:

  A.append(10000000000)
  B.append(10000000000)
  ans=0
  time=0
  a=0
  b=0

  while time<K:
    if A[a]<=B[b]:
      time+=A[a]
      ans+=1
      a+=1

    elif B[b]<=A[a]:
      time+=B[b]
      ans+=1
      b+=1
  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()))

if K>=(sum(A)+sum(B)):
  print(N+M)
else:
  
  A.append(10000000000)
  B.append(10000000000)
  ans=0
  time=0
  a=0
  b=0

  while time<K:
    if A[a]<=B[b]:
      time+=A[a]
      ans+=1
      a+=1

    elif B[b]<=A[a]:
      time+=B[b]
      ans+=1
      b+=1
  print(ans-1)

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

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

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

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

Submission status: Wrong Answer

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

a_acum=list(accumulate(a))
b_acum=list(accumulate(b))

ans=0

def ask_index(value):
    i=0
    while i<m:
        if b_acum[i] <= value:
            i += 1
        else:
            break
    return i

sub=k
i=-1
while i < n:
    if sub > 0:
        ans = max(ans,ask_index(sub)+i+1)
        i += 1
        if i == n:
            break
        sub = k - a_acum[i]
    else:
        break
print(ans)

Submission status: Wrong Answer

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

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
  
ans, j = 0, M
for i in range(N+1):
  if a[i] >= K: break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, 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()))

T = 0
n = 0
i = 0
while T <= K:
  if (len(A) > 0 and len(B) > 0): 
    if (A[i] <= B[i]):
      T += A[i]
      n += 1
      del A[i]
      if (A == []): A.append(10**10)
    else:
      T += B[i]
      n += 1
      del B[i]
      if (B == []): B.append(10**10)

print(n-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
n = 0
i = 0
while T <= K:
  if (len(A) > 0 and len(B) > 0): 
    if (A[i] <= B[i]):
      T += A[i]
      n += 1
      del A[i]
    else:
      T += B[i]
      n += 1
      del B[i]
  elif (len(A) > 0 and len(B) == 0):
    T += A[i]
    n += 1
    del A[i]
  elif (len(A) == 0 and len(B) > 0):
    T += B[i]
    n += 1
    del B[i]
  else:
    n += 1
    break
    
print(n-1)

Submission status: Wrong Answer

Solution code:
x, y ,z = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.extend(b)
a = sorted(a)

result = 0

for i in range(len(a)):
    z -= a[i]
    if z > 0:
        result += 1
print(result)

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
l = m
for j in range(n+1):
    if k-suma[j] < 0:
        break
    while k-suma[j]-sumb[l] < 0 and l > 0:
        l -= 1
    res.append(j+l-1)
print(max(res))

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
for j in range(n+1):
    if k-suma[j] < 0:
        break
    for l in range(m+1):
        if k-suma[j]-sumb[l] < 0:
            res.append(j+l-1)
            break
print(max(res))

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
for j in range(n+1):
    if k-suma[j] < 0:
        break
    for l in range(m+1):
        if k-suma[j]-sumb[l] > 0:
            res.append(j+l)
print(max(res))

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = []
sumb = []
a = 0
b = 0
for i in an:
    a += i
    if a <= k:
        suma.append(a)
    else:
        break
for i in bn:
    b += i
    if b <= k:
        sumb.append(b)
    else:
        break
suma = suma[::-1]
sumb = sumb[::-1]
res = [0]
al = len(suma)
bl = len(sumb)
for j,l in enumerate(suma):
    dif = k-l
    for o,p in enumerate(sumb):
        if p < dif:
            res.append(al-j+bl-o)
            break
print(max(res))

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = []
sumb = []
a = 0
b = 0
for i in an:
    a += i
    if a <= k:
        suma.append(a)
    else:
        break
for i in bn:
    b += i
    if b <= k:
        sumb.append(b)
    else:
        break
suma = suma[::-1]
res = [0]
for j,l in enumerate(suma):
    dif = k-l
    for o,p in enumerate(sumb):
        if p <= dif:
            res.append(len(suma)-j+o+1)
        else:
            break
            
print(max(res))

Submission status: Wrong Answer

Solution code:


n,m,k=[int(i) for i in input().strip().split(" ")]
a=[int(i) for i in input().strip().split(" ")]
b=[int(i) for i in input().strip().split(" ")]
alen,blen=len(a),len(b)
value=0
aPoint,bPoint=0,0
ans=0

while aPoint<alen and bPoint<blen :
    if a[aPoint]<b[bPoint]:
        value+=a[aPoint]
        ans+=1
        aPoint+=1
    else:
        value+=b[bPoint]
        ans+=1
        bPoint+=1
    if value>k:
        print(ans-1)
        break
    
while aPoint<alen :
    value+=a[aPoint]
    ans+=1
    aPoint+=1
    if value>k:
        print(ans-1)
        break
while bPoint<blen :
    value+=b[bPoint]
    ans+=1
    bPoint+=1
    if value>k:
        print(ans-1)
        break

Submission status: Wrong Answer

Solution code:
n,m,k=[int(i) for i in input().strip().split(" ")]
a=[int(i) for i in input().strip().split(" ")]
b=[int(i) for i in input().strip().split(" ")]
alen,blen=len(a),len(b)
value=0
aPoint,bPoint=0,0
ans=0
while aPoint<alen and bPoint<blen and value<k:
    if a[aPoint]<b[bPoint]:
        value+=a[aPoint]
        ans+=1
        aPoint+=1
    else:
        value+=b[bPoint]
        ans+=1
        bPoint+=1
while aPoint<alen and value<k:
    value+=a[aPoint]
    ans+=1
    aPoint+=1
while bPoint<blen and value<k:
    value+=b[bPoint]
    ans+=1
    bPoint+=1
print(ans-1)

Submission status: Wrong Answer

Solution code:
def read(a,b):
  if not a:
    return b.pop(0)
  	
  elif not b:
    return a.pop(0)
  
  else:
    if a[0] >= b[0]:
      return b.pop(0)
    else:
      return a.pop(0)
      
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

book = 0
while 1:
  if not A and not B:
    break
  else:
    K -= read(A,B)
    if K < 0 :
      break
    else:
      book += 1
    
print(book)

Submission status: Wrong Answer

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

A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
total = 0
A_B = A+B

A_B.sort()

for i in A_B:
    if total+i > K:
        break
    total += i
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def judge(num):
  if num>n+m:
    return False
  for i in range(max(0,num-m),min(n,num)+1):
    if a_cumsum[i] + b_cumsum[num-i]<=k:
      return True
  return False

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

a_cumsum = [0]
b_cumsum = [0]
for i in a:
  a_cumsum.append(a_cumsum[-1]+i)
for i in b:
  b_cumsum.append(b_cumsum[-1]+i)
  
left = 0
right = k+1

while right-left>1:
  mid = (right+left)//2
  
  if judge(mid):
    left = mid
  else:
    right = mid-1

print(left)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))
ab_sum , answer, b_i = sum(B), 0, M
for a_i in range(N+1):
  ab_sum += A[a_i]
  while b_i>0 and ab_sum >K:
    b_i -= 1
    ab_sum -= B[b_i]
  if ab_sum >K:
    break
  answer = max(answer, a_i+b_i-1)

print(answer)

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

# print(sum_A)
# print(sum_B)
last_index = M

for a in range(len(sum_A)):
    # print("----------------------")
    # print("a", a)
    if sum_A[a] >= K:
        count = max(count, a)
        break
    now = sum_A[a]
    rest = K - now
    # print("last_index", last_index)
    #able = len([i for i in sum_B[:last_index + 1] if i <= rest]) - 1

    while True:
        if last_index < 0:
            able = 0
            break
        if sum_B[last_index] > rest:
            last_index -= 1
        else:
            able = last_index
            break

    # print("now", now, "rest", rest, "able", able)
    # print("今回の最大countは", "a + able = ", a + able)
    count = max(count, a + able)
    # print("これまでの最大count", count)

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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

print(sum_A)
print(sum_B)
last_index = M

for a in range(len(sum_A)):
    print("----------------------")
    print("a", a)
    if sum_A[a] >= K:
        count = max(count, a)
        break
    now = sum_A[a]
    rest = K - now
    print("last_index", last_index)
    #able = len([i for i in sum_B[:last_index + 1] if i <= rest]) - 1

    while True:
        if last_index < 0:
            able = 0
            break
        if sum_B[last_index] > rest:
            last_index -= 1
        else:
            able = last_index
            break

    print("now", now, "rest", rest, "able", able)
    print("今回の最大countは", "a + able = ", a + able)
    count = max(count, a + able)
    print("これまでの最大count", count)

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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

#print(sum_A)
#print(sum_B)
last_index = M

for a in range(len(sum_A)):
    # print("----------------------")
    # print("a", a)
    if sum_A[a] >= K:
        count = max(count, a - 1)
        break
    now = sum_A[a]
    rest = K - now
    # print("last_index", last_index)
    #able = len([i for i in sum_B[:last_index + 1] if i <= rest]) - 1

    while True:
        if last_index < 0:
            able = 0
            break
        if sum_B[last_index] > rest:
            last_index -= 1
        else:
            able = last_index
            break

    # print("now", now, "rest", rest, "able", able)
    # print("今回の最大countは", "a + able = ", a + able)
    count = max(count, a + able)
    # print("これまでの最大count", count)

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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

#print(sum_A)
#print(sum_B)
last_index = M

for a in range(len(sum_A)):
    # print("----------------------")
    # print("a", a)
    if sum_A[a] >= K:
        count = max(count, a - 1)
        break
    now = sum_A[a]
    rest = K - now
    # print("last_index", last_index)
    #able = len([i for i in sum_B[:last_index + 1] if i <= rest]) - 1

    while True:
        if last_index <= 0:
            able = 0
            break
        if sum_B[last_index] > rest:
            last_index -= 1
        else:
            able = last_index
            break

    # print("now", now, "rest", rest, "able", able)
    # print("今回の最大countは", "a + able = ", a + able)
    count = max(count, a + able)
    # print("これまでの最大count", count)

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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

#print(sum_A)
#print(sum_B)
last_index = M

for a in range(len(sum_A)):
    #print("----------------------")
    #print("a", a)
    if sum_A[a] >= K:
        count = max(count, a - 1)
        break
    now = sum_A[a]
    rest = K - now
    #print("last_index", last_index)
    able = len([i for i in sum_B[:last_index + 1] if i <= rest]) - 1

    #print("now", now, "rest", rest, "able", able)
    last_index = able
    #print("今回の最大countは", "a + able = ", a + able)
    count = max(count, a + able)
    #print("これまでの最大count", count)

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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

# print(sum_A)
# print(sum_B)

for a in range(len(sum_A)):
    if sum_A[a] >= K:
        count = max(count, a - 1)
        break
    now = sum_A[a]
    rest = K - now
    able = len([i for i in sum_B if i <= rest]) - 1
    count = max(count, a + able)
    # print("now", now, "rest", rest, "able", able)
    # print("count", count)

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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

# print(sum_A)
# print(sum_B)

for a in range(len(sum_A)):
    if sum_A[a] >= K:
        count = max(count, a)
        break
    now = sum_A[a]
    rest = K - now
    able = len([i for i in sum_B if i <= rest]) - 1
    count = max(count, a + able)
    #print("now", now, "rest", rest, "able", able)
    #print("count", count)

print(count)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
total=0
inf=10
cord=[[inf for i in range(N)]for j in range(M)]

nax=0
last=0
for i in range(N):
    if total+A[i]<=K:
        total=total+A[i]
        ans+=1
    else:
        last=i
        break
tans=ans

if ans==0:
    for i in range(M):
        if total+B[i]<=K:
            total=total+B[i]
            ans+=1
        print(ans)
        exit()

for i in reversed(range(ans)):
    if total-A[i]<=K:
        total-=A[i]
        ans-=1
        for j in range(M):
            if total+B[j]<=K:
                total+=B[j]
                ans+=1
    tans=max(tans,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()))
idx_B = M-1
m = sum(B)
an = M
ans = 0
for a in [0] + A:
    m += a
    while idx_B > 0 and m > K:
        m -= B[idx_B]
        idx_B -= 1
        an -= 1
    if m > K:
        break
    if an > ans:
        ans = an
    an += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))

for i in range(len(alist)-1):
    alist[i+1] += alist[i]

for i in range(len(blist)-1):
    blist[i+1] += blist[i]

a_readable = bisect.bisect_right(alist, k)
d = k - alist[a_readable-1]
b_readable = bisect.bisect_right(blist, d)
ans1 = a_readable + b_readable

b_readable = bisect.bisect_right(blist, k)
d = k - blist[b_readable - 1]
a_readable = bisect.bisect_right(alist, d)
ans2 = a_readable + b_readable

print(ans1 if ans1 > ans2 else ans2)

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 = [a[0]]
sb = [0]
for i1 in range(m):
  if i1 != 0:
    sb.append(sb[i1-1]+b[i1])
maxn = 0
for i in range(n):
  if i != 0:
    sa.append(sa[i-1]+a[i])
  if sa[i] < k:
    for j in reversed(range(m)):
      if sa[i] + sb[j] < k:
        maxn = max(maxn,i+j+2)
        break     
print(maxn)

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 = [a[0]]
sb = [b[0]]
maxn = 0
for i in range(n):
  if i != 0:
    sa.append(sa[i-1]+a[i])
  for j in range(m):
    if j != 0:
      sb.append(sb[j-1]+b[j])
    if sa[i] + sb[j] <= k:
      maxn = max(maxn,i+j+2)
print(maxn)

Submission status: Wrong Answer

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

def binary_search(func, array, left=0, right=-1):
    if right==-1:right=len(array)-1
    y_left, y_right = func(array[left]), func(array[right])
    while True:
        middle = (left+right)//2
        y_middle = func(array[middle])
        if y_left==y_middle: left=middle
        else: right=middle
        if right-left==1:break

    return left

cumA = [0]
for i in range(N):
  cumA.append(cumA[-1]+A[i])
  
cumB = [0]
for i in range(M):
  cumB.append(cumB[-1]+B[i])
  
if cumA[-1]+cumB[-1]<=K:
  print(N+M)
  exit()
  
if A[0] > K and B[0] > K:
  print(0)
  exit()
  
ans = 0
for i in range(N+1):
  if K-cumA[i]<0:break
  idx = binary_search(lambda x:x<=K-cumA[i],cumB)
  res = max(0,i+idx)
  ans = max(ans, res)
  
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

cumA = [0]
for i in range(N):
  cumA.append(cumA[-1]+A[i])
  
cumB = [0]
for i in range(M):
  cumB.append(cumB[-1]+B[i])
  
if cumA[-1]+cumB[-1]<=K:
  print(N+M)
  exit()
  
ans = 0
for i in range(N+1):
  if K-cumA[i]<=0:break
  idx = bisect_left(cumB,K-cumA[i])
  if idx == 0:
    res = i
  else:
    res = i+idx-1
  ans = max(ans, res)
  
print(ans)

Submission status: Wrong Answer

Solution code:
def greather_than(tableA, curr_a_index, tableB, curr_b_index, rem_a, rem_b):
  while rem_a != 0 and rem_b != 0 and int(tableA[curr_a_index]) == int(tableB[curr_b_index]):
    curr_a_index += 1
    curr_b_index += 1
    rem_a -= 1
    rem_b -= 1
  if rem_a == 0 and rem_b == 0:
    return True
  elif rem_a == 0:
    return False
  elif rem_b == 0:
    return True
  else:
    return int(tableA[curr_a_index]) > int(tableB[curr_b_index])



[N, M, K] = map(int, input().split())
tableA = input().split()
tableB = input().split()
total_min = 0

curr_a_index = 0
curr_b_index = 0

rem_a = N
rem_b = M

while curr_a_index < N or curr_b_index < M:
  if total_min > K:
    break
  else:
    if rem_a == 0 and rem_b == 0:
      break
    elif rem_a == 0:
      total_min += int(tableB[curr_b_index])

      if total_min > K:
        break

      curr_b_index += 1
      rem_b -= 1
    elif rem_b == 0:
      total_min += int(tableA[curr_a_index])

      if total_min > K:
        break

      curr_a_index += 1
      rem_a -= 1
    else:
      if int(tableA[curr_a_index]) > int(tableB[curr_b_index]):
        total_min += int(tableB[curr_b_index])

        if total_min > K:
          break

        curr_b_index += 1
        rem_b -= 1
      elif int(tableA[curr_a_index]) < int(tableB[curr_b_index]):
        total_min += int(tableA[curr_a_index])

        if total_min > K:
          break

        curr_a_index += 1
        rem_a -= 1
      else:
        if greather_than(tableA, curr_a_index, tableB, curr_b_index, rem_a, rem_b):
          total_min += int(tableB[curr_b_index])

          if total_min > K:
            break

          curr_b_index += 1
          rem_b -= 1
        else:
          total_min += int(tableA[curr_a_index])

          if total_min > K:
            break

          curr_a_index += 1
          rem_a -= 1

print(curr_a_index + curr_b_index)

Submission status: Wrong Answer

Solution code:
[N, M, K] = map(int, input().split())
tableA = input().split()
tableB = input().split()
total_min = 0

curr_a_index = 0
curr_b_index = 0

rem_a = N
rem_b = M
while curr_a_index < N or curr_b_index < M:
  if total_min > K:
    break
  else:
    if rem_a == 0 and rem_b == 0:
      break
    elif rem_a == 0:
      total_min += int(tableB[curr_b_index])

      if total_min > K:
        break

      curr_b_index += 1
      rem_b -= 1
    elif rem_b == 0:
      total_min += int(tableA[curr_a_index])

      if total_min > K:
        break

      curr_a_index += 1
      rem_a -= 1
    else:
      if int(tableA[curr_a_index]) > int(tableB[curr_b_index]):
        total_min += int(tableB[curr_b_index])

        if total_min > K:
          break

        curr_b_index += 1
        rem_b -= 1
      else:
        total_min += int(tableA[curr_a_index])

        if total_min > K:
          break

        curr_a_index += 1
        rem_a -= 1

print(curr_a_index + curr_b_index)

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=[]
sma=0
for i in range(n):
    sma+=a[i]
    sa.append(sma)
sb=[]
smb=0
for i in range(m):
    smb+=b[i]
    sb.append(smb)
import bisect
lain=bisect.bisect_right(sa,k)-1
if lain<0:
    sm=0
else:
    sm=a[lain]
stin=bisect.bisect_right(sb,k-sm)-1

if lain<0:
    print(stin+1)
    exit()
if stin>=m-1:
    print(lain+1+m)
    exit()
am=lain+1+stin+1

mx=am
for i in range(lain,-1,-1):
    sm-=a[i]
    am-=1
    while sm+sb[stin+1]<=k:
        stin+=1
        am+=1
        if stin>=m-1:
            print(max(mx,am))
            exit()
    mx=max(mx,am)
print(mx)