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 itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))
booknumifonlyA = 0
timeifonlyA = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumifonlyA += 1
	timeifonlyA = time

time = timeifonlyA
bookcanbereadatA = booknumifonlyA
bookcanberead = [bookcanbereadatA]

for bookcanbereadatB in range(numOfB):
	print(f'time {time + timetoreadB[bookcanbereadatB]}, {bookcanbereadatA} {bookcanbereadatB}')
	if time + timetoreadB[bookcanbereadatB] <= target:
		bookcanberead.append(bookcanbereadatA + bookcanbereadatB + 1)
		time = time + timetoreadB[bookcanbereadatB]
	else:
		while time + timetoreadB[bookcanbereadatB] > target and bookcanbereadatA > 1:
			bookcanbereadatA -= 1
			time = time - timetoreadA[bookcanbereadatA-1]

print(max(bookcanberead))

import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))
booknumifonlyA = 0
timeifonlyA = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumifonlyA += 1
	timeifonlyA = time

time = timeifonlyA
bookcanbereadatA = booknumifonlyA
bookcanberead = [bookcanbereadatA]

for bookcanbereadatB in range(numOfB):
	if newtime := time + timetoreadB[bookcanbereadatB] <= target:
		bookcanberead.append(bookcanbereadatA + bookcanbereadatB + 1)
		time = newtime
	else:
		while newtime > target and bookcanbereadatA > 1:
			bookcanbereadatA -= 1
			newtime = newtime - timetoreadA[bookcanbereadatA-1]
		time = newtime

print(bookcanberead)

import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))

booknumonlyA = 0
totaltime = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumonlyA += 1
	totaltime = time

bookreadA = booknumonlyA
bookread = [bookreadA]

for posB in range(numOfB):
	bookreadB = posB + 1
	newtime = totaltime + timetoreadB[posB]
	if newtime <= target:
		bookread.append(bookreadA + bookreadB)
		totaltime = newtime
	else:
		while newtime > target and bookreadA > 0:
			bookreadA -= 1
			newtime = newtime - timetoreadA[bookreadA]

		if newtime <= target:
			bookread.append(bookreadA + bookreadB)

		totaltime = newtime

print(bookread)

import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))
booknumifonlyA = 0
timeifonlyA = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumifonlyA += 1
	timeifonlyA = time

time = timeifonlyA
bookcanbereadatA = booknumifonlyA
bookcanberead = [bookcanbereadatA]

for bookcanbereadatB in range(numOfB):
	if newtime := time + timetoreadB[bookcanbereadatB] <= target:
		bookcanberead.append(bookcanbereadatA + bookcanbereadatB + 1)
		time = newtime
	else:
		while newtime > target and bookcanbereadatA > 1:
			bookcanbereadatA -= 1
			newtime = newtime - timetoreadA[bookcanbereadatA-1]
		time = newtime

print(max(bookcanberead))

import itertools

numOfA,numOfB,target = map(int, input().split())

timetoreadA = list(map(int,input().split()))
timetoreadB = list(map(int,input().split()))

timetoreadAacc = list(itertools.accumulate(timetoreadA))

booknumonlyA = 0
totaltime = 0
for time in timetoreadAacc:
	if target < time:
		break
	booknumonlyA += 1
	totaltime = time

bookreadA = booknumonlyA
bookread = [bookreadA]

for posB in range(numOfB):
	bookreadB = posB + 1
	newtime = totaltime + timetoreadB[posB]
	if newtime <= target:
		bookread.append(bookreadA + bookreadB)
		totaltime = newtime
	else:
		while newtime > target and bookreadA > 0:
			bookreadA -= 1
			newtime = newtime - timetoreadA[bookreadA]

		if newtime <= target:
			bookread.append(bookreadA + bookreadB)

		totaltime = newtime

print(max(bookread))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted