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):
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_t, b_t = [0], [0]
for i in range(n):
    a_t.append(a_t[i] + a[i])
for i in range(m):
    b_t.append(b_t[i] + b[i])
ans = 0
j = m
for i in range(n+1):
    if (a[i] > k):
        break
    while(a_t[i] + b_t[j] > k):
        j -= 1
    ans = max(ans, i + j)
print(ans)



import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_max = 0
bi_max = 0
for bi in b:
    if b_max > k:
        b_max -= bi
        bi_max -= 1
        break
    b_max += bi
    bi_max += 1
ti = bi_max
t_max = 0
ai_max = 0
a_max = 0
for ai in a:
    if a_max + ai > k:
        break
    ai_max += 1
    a_max += ai
    for j in range(bi_max, -1, -1):
        if ai_max + bi_max <= k:
            if ai_max + bi_max > ti:
                ti = ai_max + bi_max
            break
        bi_max -= 1
    if ai_max + bi_max > ti:
        ti = ai_max + bi_max
print(ti)    





import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_max = 0
bi_max = 0
for bi in b:
    if b_max > k:
        b_max -= bi
        bi_max -= 1
        break
    b_max += bi
    bi_max += 1
ti = bi_max
t_max = 0
ai_max = 0
a_max = 0
for ai in a:
    if a_max + ai > k:
        break
    ai_max += 1
    a_max += ai
    for j in range(bi_max, 0, -1):
        if ai_max + bi_max <= k:
            if ai_max + bi_max > ti:
                ti = ai_max + bi_max
            break
        bi_max -= 1
    if ai_max + bi_max > ti:
        ti = ai_max + bi_max
print(ti)    





import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_max = 0
bi_max = 0
for bi in b:
    if b_max > k:
        b_max -= bi
        bi_max -= 1
        break
    b_max += bi
    bi_max += 1
ti = bi_max
t_max = 0
ai_max = 0
a_max = 0
for ai in a:
    if a_max + ai > k:
        break
    ai_max += 1
    a_max += ai
    for j in range(bi_max, 0, -1):
        if ai_max + bi_max <= k:
            if ai_max + bi_max > ti:
                ti = ai_max + bi_max
            break
        bi_max -= 1
print(ti)    





import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_t, b_t = [0], [0]
for i in range(n):
    a_t.append(a_t[i] + a[i])
for i in range(m):
    b_t.append(b_t[i] + b[i])
ans = 0
j = m
for i in range(n+1):
    if (a_t[i] > k):
        break
    while(a_t[i] + b_t[j] > k):
        j -= 1
    ans = max(ans, i + j)
print(ans)



Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted