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

Submission status: Wrong Answer

Solution code:
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 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))

Submission status: Wrong Answer

Solution code:
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))

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.sort(reverse = True)
b.sort(reverse = True)
a = [10**9+10]+a
b = [10**9+10]+b
cnt = 0
while(min(a[-1],b[-1]) <= k):
    if a[-1] == min(a[-1],b[-1]):
        k = k-min(a[-1],b[-1])
        a.pop()

    else:
        k = k-min(a[-1],b[-1])
        b.pop()

    cnt = cnt+1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left, bisect_right
N,M,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
B=map(int, sys.stdin.readline().split())

RUISEKI_A=[0]
RUISEKI_B=[0]
for a in A: RUISEKI_A.append(RUISEKI_A[-1]+a)
for b in B: RUISEKI_B.append(RUISEKI_B[-1]+b)

ans=0
for i in range(N+1):
    nokori=K-RUISEKI_A[i]
    if 0<nokori:
        ans=max(ans,i+bisect_right(RUISEKI_B,nokori)-1)

print ans

Submission status: Wrong Answer

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

N,M,K = map(int,readline().split())

A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().split()))

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

for i in range(1, len(B)):
  B[i] += B[i - 1]
  
import bisect

ans = 0
for i in range(len(A)):
  rest = K - A[i]
  if rest <= 0:
    if ans < i:
      ans = i
    continue
  b_read = bisect.bisect_right(B, rest)
  if ans < i + b_read - 1:
    ans = i + b_read - 1
    
print(ans)

Submission status: Wrong Answer

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

N,M,K = map(int,readline().split())

A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().split()))

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

for i in range(1, len(B)):
  B[i] += B[i - 1]
  
import bisect

ans = 0
for i in range(len(A)):
  rest = K - A[i]
  if rest <= 0:
    continue
  b_read = bisect.bisect_right(B, rest)
  if ans < i + b_read - 1:
    ans = i + b_read - 1
    
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 = [0]
B = [0]
for i in range(N):
  A.append(A[i] + a[i])
for i in range(M):
  B.append(B[i] + b[i])
  
ans = 0
j = M
for n in range(N + 1):
  while True:
    time = A[n] + B[j]
    if time <= K or j == 0:
      ans = max(ans, n + j)
      break
    else:
      j -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]

A, B = [0]*(N+1), [0]*(M+1)
for i in range(1, N):
    A[i] = A[i-1] + A_temp[i-1]
    
for j in range(1, M):
    B[j] = B[j-1] + B_temp[j-1]
    
ans = 0
for a in range(N+1):
    if A[a] > K:
        break
    for b in range(ans-a+1, M+1):
        if A[a] + B[b] > K:
            break
        ans = max(ans, a+b)
        
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_temp = [int(i) for i in input().split()]
B_temp = [int(i) for i in input().split()]

A, B = [0]*(N+1), [0]*(M+1)
for i in range(1, N):
    A[i] = A[i-1] + A_temp[i-1]
    
for j in range(1, M):
    B[j] = B[j-1] + B_temp[j-1]
    
ans = 0
for a in range(N+1):
    if A[a] > K:
        break
    for b in range(M+1):
        if A[a] + B[b] > K:
            break
        ans = max(ans, a+b)
        
print(ans)

Submission status: Wrong Answer

Solution code:
f_inf = float('inf')
N, M, K = map(int, input().split())
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))

# AL,BL add list last inf
AL.append(f_inf)
BL.append(f_inf)

total_book = 0

while K >= 0:
    if AL[0] <= BL[0]:
        _tmp = AL.pop(0)
    else:
        _tmp = BL.pop(0)

    K -= _tmp
    total_book +=1

print(total_book - 1)

Submission status: Wrong Answer

Solution code:
A,B,time = map(int,input().split())
list_A = list(map(int,input().split()))
list_B = list(map(int,input().split()))

# print(list_B)

list_A_num = 0
list_B_num = 0

total_time = 0
count = 0

while True:
    if len(list_A) == 0 and len(list_B) == 0:
        break
    elif len(list_A) > 0 and len(list_B) > 0: # どちらも要素１以上
        if list_A[list_A_num] <= list_B[list_B_num]: # Aの値の方が小さければ
            total_time += list_A[list_A_num]
            list_A.pop(0)
        else: # Bの方が小さい
            total_time += list_B[list_B_num]
            list_B.pop(0)
    elif len(list_A) == 0: # Aが0個
        total_time += list_B[list_B_num]
        list_B.pop(0)
    else: #Bが0個
        total_time += list_A[list_A_num]
        list_A.pop(0)
    if total_time <= time:
        count += 1
    else:
        break

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()))
ALLB = sorted(A+B)

sumt = 0
cnt = 0
summax = sum(ALLB)
if summax <= K:
    print(N+M)
    exit(0)
    
for i in range(N+M):
    sumt += ALLB[i]
    if sumt > K:
        print(cnt)
        exit(0)
        
    cnt += 1

Submission status: Wrong Answer

Solution code:
import copy

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

sumt = 0
cnt = 0
cnt2 = N+M
summax = sum(ALLB)
ALLB2 = copy.deepcopy(ALLB[::-1])

for i in range(N+M):
    sumt += ALLB.pop(0)
    if sumt > K:
        print(cnt)
        exit(0)
        
    summax -= ALLB2.pop(0)
    if summax < K:
        print(cnt2)
        exit(0)
    cnt2 -= 1
    cnt += 1

Submission status: Wrong Answer

Solution code:
import copy

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

sumt = 0
cnt = 0
cnt2 = N+M
summax = sum(ALLB)
ALLB2 = copy.deepcopy(ALLB[::-1])

if summax < K:
    print(cnt2)
    exit(0)

for i in range(N+M):
    sumt += ALLB.pop(0)
    if sumt > K:
        print(cnt)
        exit(0)
        
    summax -= ALLB2.pop(0)
    cnt2 -= 1
    if summax < K:
        print(cnt2)
        exit(0)
    cnt += 1

Submission status: Wrong Answer

Solution code:
import copy

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

sumt = 0
cnt = 0
cnt2 = N+M
summax = sum(ALLB)
ALLB2 = copy.deepcopy(ALLB[::-1])

if summax < K:
    print(cnt2)
    exit(0)

for i in range(N+M):
    sumt += ALLB.pop(0)
    if sumt > K:
        print(cnt)
        exit(0)
        
    summax -= ALLB2.pop(0)
    if summax < K:
        print(cnt2)
        exit(0)
    cnt += 1
    cnt2 -= 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()))
time = 0
cnt = 0
while time <= K:
    cnt += 1
    if A ==[] and B == []:
        break
    elif A == []:
        time += int(B[0])
        del B[0]
    elif B == []:
        time += int(A[0])
        del A[0]
    elif A[0] <= B[0]:
        time += int(A[0])
        del A[0]
    elif B[0] <= A[0]:
        time += int(B[0])
        del B[0]
print(cnt - 1)

Submission status: Wrong Answer

Solution code:
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,0
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            K_temp = K - A_sum_arr[i]
            for j in range(len(B_sum_arr)):
                if B_sum_arr[j] > K_temp:
                    break
                else:
                    K_temp -= B_sum_arr[j]
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    print(get_max_book_num(A,B,K))

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
counter_of_A = 0
counter_of_B = 0
counter_of_time = 0


while(True):
    if counter_of_A < N:
        book_A = A_list[counter_of_A]
    else:
        book_A = -1

    if counter_of_B < M:
        book_B = B_list[counter_of_B]
    else:
        book_B = -1

    if book_A == -1 and book_B == -1:
        sum_counter = counter_of_A + counter_of_B
        break

    if book_A <= book_B and book_A != -1:
        counter_of_time += book_A
        counter_of_A += 1
    else:
        counter_of_time += book_B
        counter_of_B += 1

    if counter_of_time > K:
        sum_counter = counter_of_A + counter_of_B - 1
        break

print(sum_counter)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
counter_of_A = 0
counter_of_B = 0
counter_of_time = 0


while(True):
    if counter_of_A < N:
        book_A = A_list[counter_of_A]
    else:
        book_A = 10**8

    if counter_of_B < M:
        book_B = B_list[counter_of_B]
    else:
        book_B = 10**8

    if book_A == 10**10 and book_B == 10**10:
        sum_counter = counter_of_A + counter_of_B
        break

    if book_A <= book_B:
        counter_of_time += book_A
        counter_of_A += 1
    else:
        counter_of_time += book_B
        counter_of_B += 1

    if counter_of_time > K:
        sum_counter = counter_of_A + counter_of_B - 1
        break

print(sum_counter)

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):
    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 = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
time = 0
count = 0
buff = -1
while time < K and count-buff == 1 and i < N or j < M:
    buff = count
    if i >= N or j >= M:
        if i >= N:
            if K-time>B[j]:
                time += B[j]
                j += 1
                count += 1
        elif j >= M:
            if K-time>A[i]:
                time += A[i]
                i += 1
                count += 1
    else:
        if A[i] < B[j]:
            if K-time>A[i]:
                time += A[i]
                i += 1
                count += 1
        elif A[i] >= B[j]:
            if K-time>B[j]:
                time += B[j]
                j += 1
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N,M,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
time = 0
count = 0
buff = -1
while time < K and count-buff == 1 and i < N or j < M:
    buff = count
    if i >= N or j >= M:
        if i >= N:
            time += B[j]
            j += 1
            count += 1
        elif j >= M:
            time += A[i]
            i += 1
            count += 1
    else:
        if A[i] < B[j]:
            time += A[i]
            i += 1
            count += 1
        elif A[i] >= B[j]:
            time += B[j]
            j += 1
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
counter_of_A = 0
counter_of_B = 0
counter_of_time = 0


while(True):
    if counter_of_A < N:
        book_A = A_list[counter_of_A]
    else:
        book_A = 10**10

    if counter_of_B < M:
        book_B = B_list[counter_of_B]
    else:
        book_B = 10**10

    if book_A == 10**10 and book_B == 10**10:
        sum_counter = counter_of_A + counter_of_B
        break

    if book_A <= book_B:
        counter_of_time += book_A
        counter_of_A += 1
    else:
        counter_of_time += book_B
        counter_of_B += 1

    if counter_of_time > K:
        sum_counter = counter_of_A + counter_of_B - 1
        break

print(sum_counter)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
counter_of_A = 0
counter_of_B = 0
counter_of_time = 0

while(True):
    if counter_of_A < N:
        book_A = A_list[counter_of_A]
    else:
        book_A = 10**10

    if counter_of_B < M:
        book_B = B_list[counter_of_B]
    else:
        book_B = 10**10

    if book_A <= book_B:
        counter_of_time += book_A
        counter_of_A += 1
    else:
        counter_of_time += book_B
        counter_of_B += 1

    if counter_of_time > K:
        sum_counter = counter_of_A + counter_of_B -1
        break

print(sum_counter)

Submission status: Wrong Answer

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

sa = [0]
for i, val in enumerate(A):
  sa.append(sa[i] + val)

sb = [0]
for i, val in enumerate(B):
  sb.append(sb[i] + val)

max_num = 0
ind_max = M
for i in range(N+1):
  if(sa[i]>K):
    break
  for k in range(ind_max+1):
    if(sb[ind_max-k]<=K-sa[i]):
      break
    ind_max -= 1
  max_num = max(max_num,i+ind_max)

      
      
print(max_num)

Submission status: Wrong Answer

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

sa = [0]
for i, val in enumerate(A):
  sa.append(sa[i] + val)

sb = [0]
for i, val in enumerate(B):
  sb.append(sb[i] + val)

max_num = 0
ind_max = M
for i in range(N+1):
  if(sa[i]>K):
    break
  for k in range(ind_max):
    if(sb[M-k]<=K-sa[i]):
      break
    ind_max -= 1
  
  max_num = max(max_num,i+M-k)

      
      
print(max_num)

Submission status: Wrong Answer

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

sa = {0: 0}
for i, val in enumerate(A):
  sa[i+1] = sa[i] + val

sb = {0: 0}
for i, val in enumerate(B):
  sb[i+1] = sb[i] + val

max_num = 0

for i in range(N+1):
  for j in range(M):
    if(sb[M-j]<=K-sa[i]):
      break
  max_num = max(max_num,i+M-j)

      
      
print(max_num)

Submission status: Wrong Answer

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

sa = {-1: 0}
for i, val in enumerate(A):
  sa[i] = sa[i-1] + val

sb = {-1: 0}
for i, val in enumerate(B):
  sb[i] = sb[i-1] + val

max_num = 0

for i in range(N):
  for j in range(M):
    if(sa[i]+sb[j]<=K):
      max_num = max(max_num,i+j+2)
      
      
print(max_num)

Submission status: Wrong Answer

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    As=[0]*(n+1)
    Bs=[0]*(m+1)
    ans=0
    for i in range(n):
        As[i+1]=As[i]+A[i]
    A=As
    for i in range(m):
        Bs[i+1]=Bs[i]+B[i]
    B=Bs
    #print(A,B)

    if A[-1]+B[-1]<=k:
        ans=n+m

    b_s=m

    for i in range(n+1):

        if A[i]>k:
            #print(i)
            temp=i-1
            ans=max(ans,temp)
            break
        for i2 in range(b_s,-1,-1):
            #print(i,i2)
            #print(A[i]+B[i2])
            if A[i]+B[i2]<k:
                temp=i+i2
                b_s=i2
                #print(ans,temp)
                ans=max(ans,temp)
                break
        

    
    print(ans)

if __name__ == '__main__':
    do()

Submission status: Wrong Answer

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    As=[0]*(n+1)
    Bs=[0]*(m+1)
    ans=0
    for i in range(n):
        As[i+1]=As[i]+A[i]
    A=As
    for i in range(m):
        Bs[i+1]=Bs[i]+B[i]
    B=Bs
    #print(A,B)

    if A[-1]+B[-1]<=k:
        ans=n+m

    b_s=m

    for i in range(n+1):

        if A[i]>k:
            #print(i)
            temp=i-1
            ans=max(ans,temp)
            break
        for i2 in range(b_s,-1,-1):
            #print(i,i2)
            #print(A[i]+B[i2])
            if A[i]+B[i2]<k:
                temp=i+i2-1
                b_s=i2
                #print(ans,temp)
                ans=max(ans,temp)
                break
        

    
    print(ans)

if __name__ == '__main__':
    do()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = k

# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# mcount分読むのにかかる時間。最初は最大冊数分持っているか、mcountが減るたびに減少していく
mtime = sum(mlist)

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(len(nlist) + 1):
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  # このループで読める冊数はncount+mcount。ループごとの最大値が答え
  result = max(result, ncount + mcount)
  # nlistの本を全部読み終わっていたら処理を終了する
  if ncount == n:
    break;
  # ncountから1冊読んだので、mrestをその時間分減らす
  mrest -= nlist[ncount]
  # これでmlistを読む時間が無くなってしまったら処理を終了する
  if mrest <= 0:
    break
print(result)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = k

# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# mcount分読むのにかかる時間。最初は最大冊数分持っているか、mcountが減るたびに減少していく
mtime = sum(mlist)

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(0, len(nlist) + 1):
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mtime > 0 and mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  # ?
  if mtime > mrest:
    break;
  # このループで読める冊数はncount+mcount。ループごとの最大値が応え
  result = max(result, ncount + mcount)
  # nlistの本を全部読み終わっていたら処理を終了する
  if ncount == n:
    break;
  # ncountから1冊読んだので、mrestをその時間分減らす
  mrest -= nlist[ncount]
  # これでmlistを読む時間が無くなってしまったら処理を終了する
  if mrest <= 0:
    break
print(result)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = k

# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# mcount分読むのにかかる時間。最初は最大冊数分持っているか、mcountが減るたびに減少していく
mtime = sum(mlist)

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(0, len(nlist) + 1):
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mtime > 0 and mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  # このループで読める冊数はncount+mcount。ループごとの最大値が応え
  result = max(result, ncount + mcount)
  # nlistの本を全部読み終わっていたら処理を終了する
  if ncount == n:
    break;
  # ncountから1冊読んだので、mrestをその時間分減らす
  mrest -= nlist[ncount]
  # これでmlistを読む時間が無くなってしまったら処理を終了する
  if mrest <= 0:
    break
print(result)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0

# mlistが読める残り時間。ncount(nが読める冊数)が増えるたびに減少していく
mrest = k

# mlistが読める冊数。最初はの最大冊数だが、ncount(nが読める冊数)が増えるたびに減少していく
mcount = m

# mcount分読むのにかかる時間。最初は最大冊数分持っているか、mcountが減るたびに減少していく
mtime = sum(mlist)

# ncount(nが読める冊数)を1ずつ増やしていく
for ncount in range(0, len(nlist) + 1):
  # mlistが読める残り時間も冊数もあれば、mlistから本を取っていく
  # もしmlistが読める残り時間が最大時間を超えていたら後ろから諦めていく
  while mrest > 0 and mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  # このループで読める冊数はncount+mcount。ループごとの最大値が応え
  result = max(result, ncount + mcount)
  # nlistの本を全部読み終わっていたら処理を終了する
  if ncount == n:
    break;
  # ncountから1冊読んだので、mrestをその時間分減らす
  mrest -= nlist[ncount]
  # これでmlistを読む時間が無くなってしまったら処理を終了する
  if mrest <= 0:
    break
print(result)

Submission status: Wrong Answer

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    cta=0
    ctb=0
    time=0
    for i in range(n+m+1):
        #print('ct',i,cta,ctb)
        if i==n+m:
            ans=i
            break
        elif k<time: 
            ans=i-1
            break    
        else:
            if cta==n:
                time+=B[ctb]
                ctb+=1
            elif ctb==m:
                time+=A[cta]
                cta+=1
            else:
                if A[cta]<=B[ctb]:
                    time+=A[cta]
                    cta+=1
                else:
                    time+=B[ctb]
                    ctb+=1
    
    print(ans)

if __name__ == '__main__':
    do()

Submission status: Wrong Answer

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    cta=0
    ctb=0
    time=0
    for i in range(n+m+1):
        #print('ct',i,cta,ctb)
        if k<time: 
            ans=i-1
            break
        elif i==n+m:
            ans=i
            break    
        else:
            if cta==n:
                time+=B[ctb]
                ctb+=1
            elif ctb==m:
                time+=A[cta]
                cta+=1
            else:
                if A[cta]<=B[ctb]:
                    time+=A[cta]
                    cta+=1
                else:
                    time+=B[ctb]
                    ctb+=1
    
    print(ans)

if __name__ == '__main__':
    do()

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()))
C = A+ B
C.sort()
time = 0
cnt = 0
for i in range(N + M):
    if time <= K:
        cnt += 1
        time += int(C[i])
    else:
        cnt -= 1
        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()))
C = A+ B
C.sort()
time = 0
cnt = 0
for i in range(N + M):
    if time < K:
        cnt += 1
        time += int(C[i])
    else:
        cnt -= 1
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
N = s[0]
M = s[1]
K = s[2]

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

asum = [0]
bsum = [0]
apsum = 0
bpsum = 0
for times in a:
  apsum += times
  asum.append(apsum)
for times in b:
  bpsum += times
  bsum.append(bpsum)

nums = []
i = 0
j = M
for i in range(N+1):
  if asum[i]>K:
    pass
  else:
    while asum[i]+bsum[j] > K:
      print(i,j)
      j += -1
    nums.append(i+j)
print(max(nums))

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
N = s[0]
M = s[1]
K = s[2]

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

asum = [0]
bsum = [0]
apsum = 0
bpsum = 0
for times in a:
  apsum += times
  asum.append(apsum)
for times in b:
  bpsum += times
  bsum.append(bpsum)
print(asum)
print(bsum)

nums = []
i = 0
j = M
for i in range(N+1):
  if asum[i]>K:
    pass
  else:
    while asum[i]+bsum[j] > K:
      print(i,j)
      j += -1
    nums.append(i+j)
print(max(nums))
print(nums)

Submission status: Wrong Answer

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

n = 0
m = 0
r = 0
while n < len(nn) or m < len(mm):
  if m == len(mm):
    if k < nn[n]:
      break
    k -= nn[n]
    r += 1
    n += 1
  elif n == len(nn):
    if k < mm[m]:
      break
    r += 1
    m += 1
  elif nn[n] < mm[m]:
    if k < nn[n]:
      break
    k -= nn[n]
    r += 1
    n += 1
  else:
    if k < mm[m]:
      break
    r += 1
    m += 1
print(r)

Submission status: Wrong Answer

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

n = 0
m = 0
r = 0
while n < len(nn) and m < len(mm):
  if nn[n] < mm[m]:
    if k < nn[n]:
      break
    k -= nn[n]
    r += 1
    n += 1
  else:
    if k < mm[m]:
      break
    k -= mm[m]
    r += 1
    m += 1
print(r)

Submission status: Wrong Answer

Solution code:
N,M,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
time = 0
count = 0
buff = 0
while time < K and count-buff ==1 and i < N or j < M:
    buff = count
    if i >= N or j >= M:
        if i >= N:
            time += B[j]
            j += 1
            count += 1
        elif j >= M:
            time += A[i]
            i += 1
            count += 1
    else:
        if A[i] < B[j]:
            time += A[i]
            i += 1
            count += 1
        elif A[i] >= B[j]:
            time += B[j]
            j += 1
            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()))

readtime_a = [0]
readtime_b = [0]
for i in range(n):
    readtime_a.append(readtime_a[i]+a[i])
for i in range(m):
    readtime_b.append(readtime_b[i]+b[i])

cnt = [0]

for i in range(n):
    for j in range(m-1,-1,-1):
        if readtime_a[i+1] > k:
            break
        if readtime_a[i+1] + readtime_b[j+1] > k:
            continue
        else:
            cnt.append((i+1) + (j+1))
            break

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

readtime_a = [0]
readtime_b = [0]
for i in range(n):
    readtime_a.append(readtime_a[i]+a[i])
for i in range(m):
    readtime_b.append(readtime_b[i]+b[i])

cnt = []

for i in range(n):
    for j in range(m):
        if readtime_a[i+1] + readtime_b[j+1] > k:
            cnt.append((i+1) + (j))
            break
        else:
            if j == m-1:
                cnt.append((i+1) + m)

print(max(cnt))