Problem: 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.

Submission attempts (in order):
n, m, k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int, input().split()))
 
ans_list = []
ans_list.append(0)

sum_a = 0
for i in range(len(a)):
  sum_a += a[i]
  sum_b = 0
  if sum_a > k:
    break
  if sum_a == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(b)):
    if max(ans_list) < i+1+j:
      pass
    else:
      sum_b += b[j]
      if (sum_a + sum_b) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_a + sum_b) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
sum_b = 0
for i in range(len(b)):
  sum_b += b[i]
  sum_a = 0
  if sum_b > k:
    break
  if sum_b == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(a)):
    if max(ans_list) < i+1+j:
      pass
    else:
      sum_a += a[j]
      if (sum_b + sum_a) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_b + sum_a) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
print(max(ans_list))

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


ans = 0
sum_a = 0
for i in range(len(a)):
  sum_a += a[i]
  sum_b = 0
  if sum_a > k:
    break
  if sum_a == k:
    temp = i+1
    if temp > ans:
      ans = temp
    break
  for j in range(len(b)):
    sum_b += b[j]
    if (sum_a + sum_b) > k:
      temp = i+1+j
      ans_list.append(temp)
      if temp > ans:
        ans = temp
      break
    if (sum_a + sum_b) == k:
      temp = i+1+j+1
      if temp > ans:
        ans = temp
      break
      
sum_b = 0
for i in range(len(b)):
  sum_b += b[i]
  sum_a = 0
  if sum_b > k:
    break
  if sum_b == k:
    temp = i+1
    if temp > ans:
      ans = temp
    break
  for j in range(len(a)):
    sum_a += a[j]
    if (sum_b + sum_a) > k:
      temp = i+1+j
      if temp > ans:
        ans = temp
      break
    if (sum_b + sum_a) == k:
      temp = i+1+j+1
      if temp > ans:
        ans = temp
      break
      
print(ans)

n, m, k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int, input().split()))
 
ans_list = []
ans_list.append(0)

sum_a = 0
for i in range(len(a)):
  sum_a += a[i]
  sum_b = 0
  if sum_a > k:
    break
  if sum_a == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(b)):
    sum_b += b[j]
    if max(ans_list) < i+1+j:
      pass
    else:
      if (sum_a + sum_b) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_a + sum_b) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
sum_b = 0
for i in range(len(b)):
  sum_b += b[i]
  sum_a = 0
  if sum_b > k:
    break
  if sum_b == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(a)):
    sum_a += a[j]    
    if max(ans_list) < i+1+j:
      pass
    else:
      if (sum_b + sum_a) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_b + sum_a) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
print(max(ans_list))

n, m, k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int, input().split()))
 
ans_list = []
ans_list.append(0)

sum_a = 0
for i in range(len(a)):
  sum_a += a[i]
  if sum_a > k:
    break
  if sum_a == k:
    ans_list.append(i+1)
    break
  start = max(ans_list)-i
  sum_b = sum(b[0:start])
  for j in range(start,len(b)):
    sum_b += b[j]
    if (sum_a + sum_b) < k:
      ans_list.append(i+1+j)
    if (sum_a + sum_b) > k:
      ans_list.append(i+1+j-1)
      break
    if (sum_a + sum_b) == k:
      ans_list.append(i+1+j+1)
      break
      
sum_b = 0
for i in range(len(b)):
  sum_b += b[i]
  sum_a = 0
  if sum_b > k:
    break
  if sum_b == k:
    ans_list.append(i+1)
    break
  start = max(ans_list)-i
  sum_a = sum(a[0:start])
  for j in range(start,len(a)):
    sum_a += a[j]   
    if (sum_a + sum_b) < k:
      ans_list.append(i+1+j)
    if (sum_a + sum_b) > k:
      ans_list.append(i+1+j-1)
      break
    if (sum_a + sum_b) == k:
      ans_list.append(i+1+j+1)
      break
      
print(max(ans_list))

N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]

ans = 0
j = M

for i in range(N):
  a.append(a[i] + A[i])

for i in range(M):
  b.append(b[i] + B[i])

for i in range(N+1):
  if a[i] > K:
    break
  while a[i] + b[j] > K:
    j -= 1
  ans = max(ans, i+j)

print(ans)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted