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 numpy as np
import sys
input = sys.stdin.buffer.readline

N, M, K = map(int, input().split())
cumA = np.zeros(N+1, dtype=np.int32)
cumA[1:] = np.array(input().split(), dtype=np.int32).cumsum()
cumB = np.zeros(M+1, dtype=np.int32)
cumB[1:] = np.array(input().split(), dtype=np.int32).cumsum()
# print(cumA)
# print(cumB)

ans = 0
for i in range(N, -1, -1):
    if cumA[i] > K: continue
    j = np.searchsorted(cumB, K-cumA[i], side='right')
    ans = max(ans, i+j-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()))
asum = 0
maxtemp = 0
for i in range(n):   
    bsum = 0
    if(asum >k):
        temp = i-1
        break
    for j in range(m):
        if(asum + bsum > k):
            temp = i + j-1
            break
        bsum += b[j]
    else:
        temp = i + m
    if(maxtemp < temp):
        maxtemp = temp
    asum +=a[i]
print(maxtemp)

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()))
asum = 0
maxtemp = 0
for i in range(n):   
    bsum = 0
    if(asum >k):
        temp = i-1
        break
    for j in range(m):
        if(asum + bsum > k):
            temp = i + j-1
            break
        bsum += b[j]
    else:
        temp = i+1 + m
    if(maxtemp < temp):
        maxtemp = temp
    asum +=a[i]
print(maxtemp)

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
ans = 0
b_sum=[0]
cnt = 0
for i,b in enumerate(b_list):
  b_sum.append(b_sum[i] + b)
  if b_sum[i+1]<=K:
    cnt+=1
    ans=max(ans,cnt)

a_sum=0
for i,a in enumerate(a_list):
  a_sum+=a
  pos = K - a_sum
  books = i+1
  if pos<=0:
    break
  
  left = 0
  right = len(b_sum)-1
  while left<=right:
    mid = (left+right)//2

    if b_sum[mid]>pos:
        right = mid - 1
    else:
        left = mid + 1
  books+=right
  ans = max(ans, books)

print(ans)

Submission status: Wrong Answer

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

b_sum=[0]
for i,b in enumerate(b_list):
  b_sum.append(b_sum[i] + b)

ans = 0
a_sum=0
for i,a in enumerate(a_list):
  a_sum+=a
  pos = K - a_sum
  books = i+1
  if pos<=0:
    break
  
  left = 0
  right = len(b_sum)-1
  while left<=right:
    mid = (left+right)//2

    if b_sum[mid]>pos:
        right = mid - 1
    else:
        left = mid + 1
  books+=right
  ans = max(ans, books)

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

Submission status: Wrong Answer

Solution code:
def resolve():
    n,m,k = map(int, input().split())
    listA = input().split()
    listB = input().split()
    a = 0
    b = 0
    k_sum = 0
    count = 0
    value = 0
    for i in range(0,n+m):
        if a == n:
            c = 200000
        if b == m:
            d = 200000
        if a <= n-1:
            c = listA[a]
            c = int(c)
        if b <=m-1:
            d = listB[b]
            d = int(d)
        if a <= n-1 and c <= d:
            value = c
            a = a+1
        if b <= m-1 and c > d:
            value = d
            b = b + 1

        k_sum = k_sum + value
        if k_sum > k:
            break;
        count = count + 1

    print(count)

resolve()

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    AS = [0]
    for i in range(n):
        AS.append(AS[i] + A[i])

    BS = [0]
    for i in range(m):
        BS.append(BS[i] + B[i])

    ans = 0
    for ai in range(n, -1, -1):
        if AS[ai] > k:
            continue

        c = 0
        for bi in range(m + 1):
            if BS[bi] + AS[n - ai] > k:
                break

            c = ai + bi

        ans = max(c, ans)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import*
n,m,k,*a=map(int,open(0).read().split())
for i in range(1,n+m):a[i]+=i!=n and a[i-1]
b=a[n:]
print(max([i-~bisect(b,k-a[i])for i in range(n)if a[i]<=k]+[0]))

Submission status: Wrong Answer

Solution code:
n,m,k,*x=map(int,open(0).read().split())
s=sum(x[:n])
z=i=j=n
while~i:
	while j<n+m and s+x[j]<=k:s+=x[j];j+=1;z=max(z,i+j)
	i-=1
	s-=x[i]
print(z-n)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    t = 0
    ca, cb = 0, 0
    for a in A:
        t += a
        if t > k:
            t -= a
            break

        ca += 1

    while True:
        t += B[cb]
        cb += 1

        if t > k:
            cb -= 1
            t -= B[cb]
            break

        if cb == m:
            break

    AA = [ca + cb]
    while True:
        if ca == 0 or cb == m:
            break

        ca -= 1
        t -= A[ca]
        while True:
            if t > k or cb == m:
                break

            t += B[cb]
            cb += 1

        AA.append(ca + cb)

    print(max(AA))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
###############################################################################
#Imports
import collections
import sys
import itertools
from functools import lru_cache
import sys
import math
from decimal import Decimal
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
sys.setrecursionlimit(10**9) 
def helper():
	pass
###############################################################################
#Solver
def solve():
	n,m,k = map(int,input().split(' '))
	a = list(map(int,input().split(' ')))
	b = list(map(int,input().split(' ')))
	i1,i2,left = 0,0,k
	books = 0
	while(i1<n or i2<m):
		if k<=0:
			break
		if i1>=n:
			if left>=b[i2]:
				#print('read B -',b[i2],'left -',left,'books -',books+1)
				left-=b[i2]
				i2+=1
				books+=1
		elif i2>=m:
			if left>=a[i1]:
				#print('read A -',a[i1],'left -',left,'books -',books+1)
				left-=a[i1]
				i1+=1
				books+=1	
		elif a[i1]<b[i2]:
			if left>=a[i1]:
				#print('read A -',a[i1],'left -',left,'books -',books+1)
				left-=a[i1]
				i1+=1
				books+=1
			else:
				break
		else:
			if left>=b[i2]:
				#print('read B -',b[i2],'left -',left,'books -',books+1)
				left-=b[i2]
				i2+=1
				books+=1
			else:
				break
	print(books)

###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################

Submission status: Wrong Answer

Solution code:
###############################################################################
#Imports
import collections
import sys
import itertools
from functools import lru_cache
import sys
import math
from decimal import Decimal
###############################################################################
#Constants
MOD = int(1e9)+7
###############################################################################
#Helper
sys.setrecursionlimit(10**9) 
def helper():
	pass
###############################################################################
#Solver
def solve():
	n,m,k = map(int,input().split(' '))
	a = list(map(int,input().split(' ')))
	b = list(map(int,input().split(' ')))
	i1,i2,left = 0,0,k
	books = 0
	while(i1<n or i2<m) and k>=0:
		if i1>=n:
			if left>=b[i2]:
				#print('read B -',b[i2],'left -',left,'books -',books+1)
				left-=b[i2]
				i2+=1
				books+=1
		elif i2>=m:
			if left>=a[i1]:
				#print('read A -',a[i1],'left -',left,'books -',books+1)
				left-=a[i1]
				i1+=1
				books+=1	
		elif a[i1]<b[i2]:
			if left>=a[i1]:
				#print('read A -',a[i1],'left -',left,'books -',books+1)
				left-=a[i1]
				i1+=1
				books+=1
			else:
				break
		else:
			if left>=b[i2]:
				#print('read B -',b[i2],'left -',left,'books -',books+1)
				left-=b[i2]
				i2+=1
				books+=1
			else:
				break
	print(books)

###############################################################################
#Driver
t = 1
for _ in range(t):
	solve()
###############################################################################

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

a_cs = [0] + [0 for _ in range(n)]
b_cs = [0] + [0 for _ in range(m)]

a_max = n
for i in range(1, n+1):
    a_cs[i] = a_cs[i-1] + a_list[i-1]
    if a_cs[i] > k:
        a_max = i - 1
        break

b_ind = m
for i in range(1, m+1):
    b_cs[i] = b_cs[i-1] + b_list[i-1]
    if a_cs[a_max] + b_cs[i] > k:
        b_ind = min(i - 1, b_ind)

ans = a_max + b_ind
for a_ind in range(a_max, -1, -1):
    while a_cs[a_ind] + b_cs[b_ind] < k and b_ind < m:
        if a_cs[a_ind] + b_cs[b_ind+1] < k:
            b_ind += 1
        else:
            break
    ans = max(ans, a_ind + b_ind)
print(ans)

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

a_cs = [0] + [0 for _ in range(n)]
b_cs = [0] + [0 for _ in range(m)]

a_max = n
for i in range(1, n+1):
    a_cs[i] = a_cs[i-1] + a_list[i-1]
    if a_cs[i] > k:
        a_max = i - 1
        break

b_ind = m
for i in range(1, m+1):
    b_cs[i] = b_cs[i-1] + b_list[i-1]
    if a_cs[a_max] + b_cs[i] > k:
        b_ind = min(i - 1, b_ind)

ans = a_max + b_ind
for a_ind in range(a_max, 0, -1):
    while a_cs[a_ind] + b_cs[b_ind] < k and b_ind < m:
        if a_cs[a_ind] + b_cs[b_ind+1] < k:
            b_ind += 1
        else:
            break
    ans = max(ans, a_ind + b_ind)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import*
n,m,k,*x=[int(v)for l in open(0) for v in l.split()];a=accumulate([0]+x[:n]);b=[*accumulate(x[n:])];print(max(i+bisect.bisect(b,k-v)for i,v in enumerate(a)if k>v))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count_A = 0
max_count_B = 0
max_count_AB = 0
max_j = 0

for i in range(N):
  if A_cumsum[i] <= K and max_count_A <= i+1:
    max_count_A = i + 1
  else:
    break
for i in range(M):
  if B_cumsum[i] <= K and max_count_B <= i+1:
    max_count_B = i + 1
  else:
    break
    
for i in range(N):
  if A_cumsum[i] + B_cumsum[max_j] > K:
    for j in range(max_j + 1):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count_AB <= i + j + 2:
        max_count_AB = i + j + 2
        max_j = j
      else:
        break
  else:
    for j in range(max_j, M):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count_AB <= i + j + 2:
        max_count_AB = i + j + 2
        max_j = j
      else:
        break
    
print(max(max_count_A, max_count_B, max_count_AB))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count_A = 0
max_count_B = 0
max_count_AB = 0
max_j = 0

for i in range(N):
  if A_cumsum[i] <= K and max_count_A <= i+1:
    max_count_A = i + 1
  else:
    break
for i in range(M):
  if B_cumsum[i] <= K and max_count_B <= i+1:
    max_count_B = i + 1
  else:
    break
    
for i in range(N):
  if A_cumsum[i] + B_cumsum[max_j] > K:
    for j in range(max_j):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count_AB <= i + j + 2:
        max_count_AB = i + j + 2
        max_j = j
      else:
        break
  else:
    for j in range(max_j, M):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count_AB <= i + j + 2:
        max_count_AB = i + j + 2
        max_j = j
      else:
        break
    
print(max(max_count_A, max_count_B, max_count_AB))

Submission status: Wrong Answer

Solution code:
def generatea_cumulative_list(numbers):
    result = [0] * len(numbers)
    result[0] = numbers[0]
    for i in range(1, len(result)):
        result[i] = result[i - 1] + numbers[i]
    return result


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

sum_A = generatea_cumulative_list(A)
sum_B = generatea_cumulative_list(B)

a = 0
for i in range(len(sum_A)):
    if sum_A[i] > K:
        a = i
        break
else:
    a = len(sum_A)
b = 0
for i in range(len(sum_B)):
    if sum_B[i] > K:
        b = i
        break
else:
    b = len(sum_B)

if a and b:
    import bisect

    ans = 0
    for i in range(a):
        rem = K - sum_A[i]
        j = bisect.bisect(sum_B, rem)
        ans = max(ans, i + j + 1)
    print(ans)
else:
    print(max(a, b))

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import*
n,m,k,*x=[int(v)for l in open(0) for v in l.split()];a=accumulate(x[:n],initial=0);b=[*accumulate(x[n:])];print(max(i+bisect.bisect(b,k-v)for i,v in enumerate(a)if k>v))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
max_j = 0

for i in range(N):
  if A_cumsum[i] <= K and max_count <= i+1:
    max_count = i + 1
  else:
    break
for i in range(M):
  if B_cumsum[i] <= K and max_count <= i+1:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] + B_cumsum[max_j] > K:
    for j in range(max_j):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= i + j + 2:
        max_count = i + j + 2
        max_j = j
      else:
        break
  else:
    for j in range(max_j, M):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= i + j + 2:
        max_count = i + j + 2
        max_j=j
      else:
        break
    
print(max_count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
max_j = 0
for i in range(M):
  if B_cumsum[i] <= K and max_count <= i+1:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] <= K and max_count <= i+1:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] > K:
    break
  elif A_cumsum[i] + B_cumsum[max_j] > K:
    for j in range(max_j):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= i + j + 2:
        max_count = i + j + 2
        max_j = j
      else:
        break
  else:
    for j in range(max_j, M):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= max_count <= i + j + 2:
        max_count = i + j + 2
        max_j=j
      else:
        break
    
print(max_count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
max_j = 0
for i in range(M):
  if B_cumsum[i] <= K and max_count <= i+1:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] <= K and max_count <= i+1:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] > K:
    break
  elif A_cumsum[i] + B_cumsum[max_j] > K:
    for j in range(max_j):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= i + j + 2:
        max_count = i + j + 2
        max_j = j
      else:
        break
  else:
    for j in range(max_j, M)[::-1]:
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= max_count <= i + j + 2:
        max_count = i + j + 2
        max_j=j
      else:
        break
    
print(max_count)

Submission status: Wrong Answer

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

sumA=sum(arr)
bpointer=0
ans=0
sumB=0
for i in range(len(arr),-1,-1):
    if i<n:
        sumA-=arr[i]
    if sumA<=k:
        while bpointer<m and sumA+sumB+brr[bpointer]<=k:
            sumB+=brr[bpointer]
            bpointer+=1
    ans=max(ans,i+bpointer)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K =  [int(x) for x in input().split()]

stackA = [int(x) for x in input().split()]
stackB = [int(x) for x in input().split()]

indexB = 0
indexA = 0

books = 0
mostBooks = 0
time = 0

for x in stackB:
    if time + x > K:
        indexB -= 1
        break

    else:
        time += x
        indexB += 1
        books += 1

indexB -= 1

mostBooks = books

for x in stackA:
    time += x
    books += 1

    while time > K and indexB >= 0:
        time -= stackB[indexB]
        indexB -= 1
        books -= 1

    if indexB < 0 and time > K:
        break

    mostBooks = max(mostBooks, books)

print(mostBooks)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(n, m, k, a, b):
    prefix_sum_a = [a[0]]
    for i in range(1, len(a)):
        prefix_sum_a.append(a[i] + prefix_sum_a[-1])
    prefix_sum_b = [b[0]]
    for i in range(1, len(b)):
        prefix_sum_b.append(b[i] + prefix_sum_b[-1])

    pa = bisect_right(prefix_sum_a, k) - 1
    result = 0
    while pa >= 0:
        left = k - prefix_sum_a[pa]
        pb = bisect_right(prefix_sum_b, left)
        result = max(result, pa + pb + 1)
        pa -= 1
    return result


if __name__ == "__main__":
    n, m, k = arr_in()
    a = arr_in()
    b = arr_in()
    out(solve(n, m, k, a, b))

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_i=0
b_i=0
time=0
count=0
flag = True
while True:
    if a_i == n and b_i == m:
        break
    elif a_i == n:
        flag = False
        b = B[b_i]
    elif b_i == m:
        flag = True
        a = A[a_i]
    else:
        a = A[a_i]
        b = B[b_i]
        if a <= b:
            flag = True
        else:
            flag = False

    if flag:
        time += a
        a_i += 1
    else:
        time += b
        b_i += 1

    if time > k:
        break

    count +=1
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))[::-1]
x=sum(a)
z=n
ans=0
while a and x>k:
  c=a.pop()
  x-=c
  z-=1
  if x>k:continue
  ans=max(ans,z)
while a:
  while b and b[-1]+x<=k:
    c=b.pop()
    x+=c
    z+=1
  ans=max(ans,z)
  c=a.pop()
  x-=c
  z-=1
  if x>k:continue
  ans=max(ans,z)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))[::-1]
x=sum(a)
z=n
ans=0
while a:
  while b and b[-1]+x<=k:
    c=b.pop()
    x+=c
    z+=1
  ans=max(ans,z)
  c=a.pop()
  x-=c
  z-=1
  if x>k:continue
  ans=max(ans,z)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))[::-1]
x=sum(a)
z=n
ans=0
while a:
  c=a.pop()
  x-=c
  z-=1
  if x>k:continue
  ans=max(ans,z)
  while b and b[-1]+x<=k:
    c=b.pop()
    x+=c
    z+=1
  ans=max(ans,z)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,M,K = map(int, input().split())
Nnums = list(map(int, input().split()))
Mnums = list(map(int, input().split()))

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0

#Nのみの場合に何冊読めるか
for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1

#Mを組み入れて最大数を探す
for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    flg = 0
    while chkSum > K:
      if Ncnt >= 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
        flg = 1
      else:
        if flg == 0:
          #chkSum -= Ml
          chkCnt -= 1
          AnsCnt -= 1
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
#  if (Ncnt < 0):
  if (chkSum > K):
    break
    
print(AnsCnt)

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]

real_ans = 0;
for i in range(1,n+1):
    if a[i] > k:
        break;
    else:
        tmp_k = k - a[i]
        ans = 0
        L = 1
        R = m
        while L <= R:
            mid = L + (R-L)//2
            if b[mid] <= tmp_k:
                ans = max( ans, mid)
                L = mid+1
            else:
                R = mid-1
        real_ans = max( real_ans, i + ans )

        

print(real_ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A,B=[0],[0]
for x in map(int,input().split()):
  A.append(A[-1]+x)
for x in map(int,input().split()):
  B.append(B[-1]+x)
ans,j=0,m
for i in range(n):
    if A[i]>k:
        break
    while A[i]+B[j]>k:
        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 = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ReadA = [0]*(N+1)
ReadB = [0]*(M+1)
for TA in range(0,N):
    ReadA[TA+1] = ReadA[TA]+A[TA]
for TB in range(0,M):
    ReadB[TB+1] = ReadB[TB]+B[TB]
MAXTB = M
MAX = 0
for TA in range(0,N+1):
    if ReadA[TA]>=K:
        break
    else:
        for TB in range(MAXTB,-1,-1):
            if ReadA[TA]+ReadB[TB]<=K:
                MAXTB = TB
                if MAX<TA+TB:
                    MAX = TA+TB
                break
print(MAX)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A,B=[0],[0]
for x in map(int,input().split()): A.append(A[-1]+x)
for x in map(int,input().split()):B.append(B[-1]+x)
ans,j=0,m
for i in range(n):
    if A[i]>k: break
    while A[i]+B[j]>k: j-=1
    ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate
n,m,k=map(int,input().split())
a=list(accumulate(map(int,input().split())))
b=list(accumulate(map(int,input().split())))
ans=0
j=bisect.bisect_right(b,k)
ans=max(ans,j)
for i,x in enumerate(a):
    y=k-x
    if y>0:
        j=bisect.bisect_right(b,y)
        ans=max(ans,i+j+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n):
    if a[i]>=k:
        break
    while b[j]>k-a[i] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
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()))
i=0
mx=0
lol=0
while i<n and a[i]<=k:
    k-=a[i]
    i+=1
    mx+=1
    lol=1
j=0
while j<m and b[j]<=k:
    k-=b[j]
    j+=1
    mx+=1
cou=mx
if(lol):
    i-=1
while i>=0 and j<m:
    k+=a[i]
    i-=1
    cou-=1
    while j<m and b[j]<=k:
        k-=b[j]
        cou+=1
        j+=1
    mx=max(cou,mx)
print(mx)

Submission status: Wrong Answer

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

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

for i in range(1, len(A)):
  A[i] = A[i] + A[i - 1]
  
for i in range(1, len(B)):
  B[i] = B[i] + B[i - 1]
  
#print(A)
#print(B)
import bisect
ans = 0
for i in range(len(A)):
  rest = K - A[i]
  # あとrest分大丈夫
  ind = bisect.bisect_left(B, rest)
  if ind != 0:
    if (i + 1) + (ind) > ans:
      ans = (i + 1) + (ind)

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K =  [int(x) for x in input().split()]

stackA = [int(x) for x in input().split()]
stackB = [int(x) for x in input().split()]

books = 0

while True:
    if len(stackB) == 0:
        if len(stackA) == 0:
            break

        K -= stackA.pop(0)

    elif len(stackA) == 0:
        K -= stackB.pop(0)

    else:
        test = 0
        while len(stackB) - 1 > test < len(stackA) - 1 and stackA[test] == stackB[test]:
            test += 1
          
        if stackA[test] > stackB[test]:
            K -= stackB.pop(0)

        else:
            K -= stackA.pop(0)        

    if K < 0:
        break
        
    books += 1

print(books)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n):
    if a[i]>k:
        break
    while b[j]>k-a[i] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n):
    if a[i]>k:
        break
    while b[j]>k-a[i] and j>0:
        j-=1
    ans=max(ans,i+j+2)
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()))
ans=0
if k < min(A[0],B[0]):
    print(0)
elif k == min(A[0],B[0]):
    print(1)
else:
    for i in range(len(A)+len(B)):
        if A[0] == min(A[0],B[0]):
            k-=A.pop(0)
            ans+=1
            if len(A)==0:
                while k > len(B)+1:
                    k-=B.pop(0)
                    ans+=1
                else:
                    print(ans)
                break
            elif k < min(A[0],B[0]):
                print(ans)
                break 
            else:
                if  k==min(A[0],B[0]):
                    ans+=1
                    print(ans)
                    break
        else:
            k-=B.pop(0)
            ans+=1
            if len(B)==0:
                while k > len(B)+1:
                    k-=A.pop(0)
                    ans+=1
                else:
                    print(ans)
                break
            elif k < min(A[0],B[0]):
                print(ans)
                break 
            else:
                if  k==min(A[0],B[0]):
                    ans+=1
                    print(ans)
                    break

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate
n,m,k=map(int,input().split())
a=list(accumulate([0] + list(map(int,input().split()))))
b=list(accumulate([0] + list(map(int,input().split()))))
ans=0
for i,x in enumerate(a):
    y=k-x
    if y>0:
        j=bisect.bisect_right(b,y)
        ans=max(ans,i+j-1)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ma = 0
    a2 = [0]
    b2 = [0]
    for i in range(len(a)):
        a2.append(a[i]+a2[i])
    for i in range(len(b)):
        b2.append(b[i]+b2[i])

    for i in range(len(a2)):
        #print(i)
        
        #sum = a2[i]
        #cnt = i
        if(a2[i]>k):
            break
        for j in range(len(b2)-1,0,-1):
            #print("i:{},j:{},b2[j]:{}".format(i,j,b2[j]))
            if(a2[i]+b2[j]<=k):
                #cnt += j
                ma = max(ma,i+j)
                break
        #ma = max(ma,cnt)
        #print("ma:",ma)

    print(ma)
            
main()