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 bisect
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
for i in range(N):
  if A[i]+a[i] <=K:
    A.append(A[i]+a[i])
  else:
    break

for i in range(M):
  if B[i]+b[i] <=K:
    B.append(B[i]+b[i])
  else:
    break

if len(A)==1 and len(B)==1:
  print(0)
  exit()
for i in range(len(A)):
  j = bisect.bisect(B,K-A[i]-0.1)
  if ans <i+j:
    ans=i+j
    #print(i,j)
  else:
    break
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()))

count=0
k=0
i=0
j=0
while k<=K:
  if i<N and j<M and A[i]<B[j]:
    k+=A[i]
    i+=1
    #print(k)
    count+=1
  elif j<M and i<N and A[i]>B[j]:
    k+=B[j]
    j+=1
    #print(k)
    count+=1
  elif j<M-1 and i<N-1 and A[i]==B[j]:
    if A[i+1]<=B[i+1]:
      k+=A[i]
      i+=1
      #print(k)
      count+=1
    else:
      k+=B[j]
      j+=1
      #print(k)
      count+=1
  elif i<N and j<M and A[i]==B[j]:
    k+=A[i]
    i+=1
    #print(k)
    count+=1
  elif i<N and j>=M:
    k+=A[i]
    i+=1
    #print(k)
    count+=1
  elif i>=N and j<M:
    k+=B[j]
    j+=1
    #print(k)
    count+=1
  else:
    count+=1
    break
print(count-1)

Submission status: Wrong Answer

Solution code:
NMK = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_time = 0
counter_A = 0
counter_B = 0
howmany = 0

while sum_time < NMK[2]:
  if counter_A<NMK[0] and counter_B<NMK[1]:
    if A[counter_A]<=B[counter_B]:
      sum_time+=A[counter_A]
      counter_A+=1
    else:
      sum_time+=B[counter_B]
      counter_B+=1
    howmany += 1
  elif counter_A>=NMK[0]:
    sum_time+=B[counter_B]
    counter_B+=1
    howmany += 1
  elif counter_B>=NMK[1]:
    sum_time+=A[counter_A]
    counter_A+=1
    howmany += 1
    
if sum_time>NMK[2]:
  print(howmany-1)
else:
  print(howmany)

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, j = 0, 0
while True:
    if i >= N and j >= M:
        break
    elif i >= N:
        if B[j] <= K:
            K -= B[j]
            j += 1
        else:
            break
    elif j >= M:
        if A[i] <= K:
            K -= A[i]
            i += 1
        else:
            break
    else: # i < N, j < M
        if A[i] > K and B[j] > K:
            break
        elif A[i] <= B[j]:
            K -= A[i]
            i += 1
        elif A[i] > B[j]:
            K -= B[j]
            j += 1

print(i+j)

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, j = 0, 0
while True:
    if i >= N and j >= M:
        break
    elif i >= N:
        if B[j] <= K:
            K -= B[j]
            j += 1
        else:
            break
    elif j >= M:
        if A[i] <= K:
            K -= A[i]
            i += 1
        else:
            break
    else: # i < N, j < M
        if A[i] > K and B[j] > K:
            break
        elif A[i] < B[j]:
            K -= A[i]
            i += 1
        elif A[i] >= B[j]:
            K -= B[j]
            j += 1

print(i+j)

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
a_sum = [0] * (n+1)
b_sum = [0] * (m+1)

for i in range(n):
  a_sum[i+1] += a_sum[i] + a[i]
for j in range(m):
  b_sum[j+1] += b_sum[j] + b[j]

for i in range(n):
  for j in range(m):
    if a_sum[i] + b_sum[j] <= k and i + j > ans:
      ans = i + j

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()))
books=0
time=0
while time<=K:
    if len(A)>0 and len(B)>0:
        if A[0]>=B[0]:
            time=time+B[0]
            books+=1
            del B[0]
        else:
            time=time+A[0]
            books+=1
            del A[0]
    elif len(A)>0 and len(B)==0:
        time=time+A[0]
        books+=1
        del A[0]
    elif len(A)==0 and len(B)>0:
        time=time+B[0]
        books+=1
        del B[0]
    else:
        break
if time>K:
    print(books-1)
else:
    print(books)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
import numpy as np
a=np.array(list(map(int,input().split())))
b=np.array(list(map(int,input().split())))
a_s=a.cumsum()
b_s=b.cumsum()
an=0
ans=0
while an<N and a_s[an]<=K:
  bn=0
  while bn<M and a_s[an]+b_s[bn]<=K:
    bn+=1
  if an+bn+1>ans:
    ans=an+bn+1
  an+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
import numpy as np
a=np.array(list(map(int,input().split())))
b=np.array(list(map(int,input().split())))
a_s=a.cumsum()
b_s=b.cumsum()
an=0
bn=0
ans=0
while an<N and a_s[an]<=K:
  while bn<M and a_s[an]+b_s[bn]<=K:
    bn+=1
  if an+bn+1>ans:
    ans=an+bn+1
  an+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  _, _, k = map(int, input().strip().split())
  la = numpy.cumsum(list(map(int, input().strip().split())))
  lb = numpy.cumsum([0] + list(map(int, input().strip().split())) + [10**9+5])
  
  def bs(x):
    s, t = 0, len(lb) - 1
    while t > s + 1:
      m = (s + t) // 2
      if lb[m] == x:
        return m
      if lb[m] > x:
        t = m
      else:
        s = m
    return s
  
  ans = 0
  for i, a in enumerate(la, 1):
    if k - a >= 0:
      ans = max(ans, i + bs((k - a)))
  print(ans)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from bisect import bisect_right

def main():
  _, _, k = map(int, input().strip().split())
  la = numpy.cumsum(list(map(int, input().strip().split())))
  lb = numpy.cumsum(list(map(int, input().strip().split())) + [10**9+5])
  
  ans = 0
  for i, a in enumerate(la, 1):
    if k - a >= 0:
      ans = max(ans, i + bisect_right(lb, (k - a)))
  print(ans)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  _, _, k = map(int, input().strip().split())
  la = numpy.cumsum(list(map(int, input().strip().split())))
  lb = numpy.cumsum(list(map(int, input().strip().split())) + [10**9+5])
  
  def bs(x):
    s, t = 0 , len(lb) - 1
    while t - s >= 2:
      m = (s + t) // 2
      if lb[m] > x:
        t = m
      else:
        s = m
    return s + 1
  
  ans = 0
  for i, a in enumerate(la, 1):
    if k - a >= lb[0]:
      ans = max(ans, i + bs(k - a))
  print(ans)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  _, _, k = map(int, input().strip().split())
  la = numpy.cumsum(list(map(int, input().strip().split())))
  lb = numpy.cumsum(list(map(int, input().strip().split())) + [10**9+5])
  
  def bs(x):
    s, t = 0 , len(lb)
    while t - s >= 2:
      m = (s + t) // 2
      if lb[m] > x:
        t = m
      else:
        s = m
    return s + 1
  
  ans = 0
  for i, a in enumerate(la, 1):
    if k - a >= lb[0]:
      ans = max(ans, i + bs(k - a))
  print(ans)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  _, _, k = map(int, input().strip().split())
  la = numpy.cumsum(list(map(int, input().strip().split())))
  lb = numpy.cumsum(list(map(int, input().strip().split())) + [10**9+5])
  
  def bs(x):
    s, t = 0 , len(lb)
    while t - s >= 2:
      m = (s + t) // 2
      if lb[m] > x:
        t = m
      else:
        s = m
    return s + 1
  
  ans = 0
  for i, a in enumerate(la, 1):
    if k - a >= 0:
      ans = max(ans, i + bs(k - a))
  print(ans)

if __name__=='__main__':
  main()

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_sum = 0
j_max = m
for i in range(m):
	if sum(b[:i]) > k:
		j_max = i
max_count = 0
for i in range(n):
	a_sum += a[i]
	for j in range(j_max):
		b_sum = sum(b[:j_max - j])
		if (a_sum + b_sum <= k) & (a_sum + b_sum > max_count):
			j_max -= j
			max_count = i + j_max + 1
			break
print(max_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()))

a_sum = 0
j_max = m
max_count = 0
for i in range(n):
	a_sum += a[i]
	for j in range(j_max):
		b_sum = sum(b[:j_max - j])
		if (a_sum + b_sum <= k) & (a_sum + b_sum > max_count):
			j_max -= j
			max_count = i + j_max + 1
			break
print(max_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()))

max_count = 0
a_sum = 0
b_sum = 0
for i in range(n):
	a_sum += a[i]
	for j in range(m):
		b_sum += b[j]
		if (a_sum + b_sum <= k) & (a_sum + b_sum > max_count):
			max_count = i + j + 2
print(max_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()))

max_count = 0
for i in range(n):
	a_sum = sum(a[:i + 1])
	for j in range(m):
		b_sum = sum(b[:j + 1])
		if (a_sum + b_sum <= k) & (a_sum + b_sum > max_count):
			max_count = i + j + 2
print(max_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()))

min_count = 0
for i in range(n):
	a_sum = sum(a[:i + 1])
	for j in range(m):
		b_sum = sum(b[:j + 1])
		if a_sum + b_sum <= k:
			min_count = i + j + 2
print(min_count)

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

sum = 0
for i in b:
    sum += i

ans = 0
j = m
for i in range(0, n+1):
    sum += a[i]
    while j > 0 and sum > k:
        sum -= b[j]
        j -= 1
    if j == 0:
        ans = i
        break
    ans = max(ans, i+j)

print(ans)

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

sum = 0
for i in b:
    sum += i

ans = 0
j = m
for i in range(0, n+1):
    sum += a[i]
    while j > 0 and sum > k:
        sum -= b[j]
        j -= 1
    if i == 0 and j == 0:
        ans = 0
        break
    ans = max(ans, i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
N-=1
M-=1
a=list(map(int,input().split()))
b=list(map(int,input().split()))
SUM_TIME=0
SUM_NUMBER=0
if (a[N]<=K)or(b[M]<=K):
    while (SUM_TIME<=K)and(N+M!=-2):
        if (N!=-1)and(M!=-1)and(a[N]<b[M]):
            SUM_TIME+=a[N]
            N-=1
        elif N<0:
            SUM_TIME+=b[M]
            M-=1
        elif M<0:
            SUM_TIME+=a[N]
            N-=1
        else:
            SUM_TIME+=b[M]
            M-=1
        SUM_NUMBER+=1
print(SUM_NUMBER)

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()))
A_sum=[]
for i in range(len(A)):
    if i==0:
        A_sum.append(A[0])
    else:
        A_sum.append(A_sum[i-1]+A[i])

nob=0
l_time=0
for i in range(len(A_sum)):
    if A_sum[i]>K and i==0:
        nob=0
        l_time=K
        break
    elif A_sum[i]>K:
        nob=i
        l_time=K-A_sum[i-1]
        break
    elif i==len(A_sum)-1:
        nob=i+1
        l_time=K-A_sum[i]

x=nob
while len(A):
    while len(B):
        if l_time>=B[0]:
            l_time-=B.pop(0)
            x+=1
        else:
            break
    if x>nob:
        nob=x
    l_time+=A.pop(-1)
    x-=1
print(nob)

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()))
A_sum=[]
B_sum=[]
for i in range(len(A)):
    if i==0:
        A_sum.append(A[0])
    else:
        A_sum.append(A_sum[i-1]+A[i])
for i in range(len(B)):
    if i==0:
        B_sum.append(B[0])
    else:
        B_sum.append(B_sum[i-1]+B[i])
max=0
for i in range(len(A_sum)):
    if A_sum[i]>K:
        break
    else:
        for j in range(len(B_sum)):
            if A_sum[i]+B_sum[j]>K:
                if i+j+1>max:
                    max=i+1+j
                break
            elif i==len(A_sum)-1 and j==len(B_sum)-1:
                max=i+j+2
print(max)

Submission status: Wrong Answer

Solution code:
def Qc():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    books = 0
    while 0 < k:
        # print(f'{a=}')
        # print(f'{b=}')
        # print(f'{k=}')
        # print(f'{books=}')
        if not a:
            k -= b[0]
            b.pop(0)
            books += 1
            continue
        elif not b:
            k -= a[0]
            a.pop(0)
            books += 1
            continue

        if a[0] < b[0]:
            k -= a[0]
            a.pop(0)
            books += 1
            # print('aを読んだ')
        elif b[0] < a[0]:
            k -= b[0]
            b.pop(0)
            books += 1
            # print('bを読んだ')
        elif k < a[0] and k < b[0]:
            break
        else:
            for i, j in zip(a, b):
                if i < j:
                    k -= a[0]
                    a.pop(0)
                    books += 1
                elif j < i:
                    k -= b[0]
                    b.pop(0)
                    books += 1
        if k < 0:
            books -= 1
    print(books)



def Qd():
    pass


if __name__ == '__main__':
    Qc()

Submission status: Wrong Answer

Solution code:
def Qc():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    books = 0
    while 0 < k:
        # print(f'{a=}')
        # print(f'{b=}')
        # print(f'{k=}')
        if k < 0:
            books -= 1
            break
        if len(a) < 1:
            k -= b[0]
            b.pop(0)
            books += 1
            continue
        elif len(b) < 1:
            k -= a[0]
            a.pop(0)
            books += 1
            continue

        if a[0] < b[0]:
            k -= a[0]
            a.pop(0)
            books += 1
        elif b[0] < a[0]:
            k -= b[0]
            b.pop(0)
            books += 1
        elif k < a[0] and k < b[0]:
            break
        else:
            for i, j in zip(a, b):
                if i < j:
                    k -= a[0]
                    a.pop(0)
                    books += 1
                elif j < i:
                    k -= b[0]
                    b.pop(0)
                    books += 1

    print(books)



if __name__ == '__main__':
    Qc()

Submission status: Wrong Answer

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

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

def nibun(L,l,r,target):

  wrk = -(-(l+r)//2)
  
#  print(l,r,target,wrk)
  
  if r == l:
    if r == len(L):
      return 0
    else:
      return wrk + 1
  
  if l == (len(L)-1):
    if L[wrk-1] > target:
      return wrk
    else:
      return 0

  if L[wrk] == target:
    return wrk+1

  elif L[wrk] > target:
    return nibun(L,l,wrk-1,target)

  else:
    return nibun(L,wrk,r,target)

  
s = 0
for i,e in enumerate(B):
  s += e 
  b.append(s)

s = 0
ans = 0
for i in range(len(A)):
#  print(i,'kaime')
#  print(s,i,A[i])
  s += A[i]
  if s > K:
    break
  else:  
    wrk = nibun(b,-1,len(b),K-s)
    
    ans=max(ans,i+1+wrk)
#    print('koko',s,wrk,ans)

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 = []
b = []

def nibun(L,l,r,target):

  wrk = -(-(l+r)//2)
  
#  print(l,r,target,wrk)
  
  if r == l:
    if r == len(L):
      return 0
    else:
      return wrk + 1
  
  if l == (len(L)-1):
    if L[wrk-1] > target:
      return wrk
    else:
      return 0

  if L[wrk] == target:
    return wrk+1

  elif L[wrk] > target:
    return nibun(L,l,wrk-1,target)

  else:
    return nibun(L,wrk,r,target)

  
s = 0
for i,e in enumerate(B):
  s += e 
  b.append(s)

s = 0
ans = 0
for i in range(len(A)):
#  print(i,'kaime')
  s += A[i]
  if s >= K:
    break
  else:  
    wrk = nibun(b,-1,len(b),K-s)
    
    ans=max(ans,i+1+wrk)
#    print('koko',s,wrk,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
li = list(map(int,input().split()))[:n]
li2 = list(map(int,input().split()))[:m]
all = 0
g = 0
i = 0
c = 0
while all < k:
    if n == i:
        all += li2[c]
        c += 1
    elif m == c:
        all += li[i]
        i += 1
    else:
        if li[i] >= li2[c]:
            all += li2[c]
            c += 1
        else:
            all += li[i]
            i += 1
    if all <= k:
        g += 1

print(g)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
li = list(map(int,input().split()))[:n]
li2 = list(map(int,input().split()))[:m]
all = 0
g = 0
i = 0
c = 0
while all < k:
    if n == i:
        all += li2[c]
        c += 1
    elif m == c:
        all += li[i]
        i += 1
    else:
        if li[i] > li2[c]:
            all += li2[c]
            c += 1
        else:
            all += li[i]
            i += 1
    if all <= k:
        g += 1

print(g)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cum = [0]
B_cum = [0]
A_cum[0] = A[0]
for j in range(len(A)-1):
    A_cum.append(A_cum[j]+ A[j+1])
B_cum[0] = B[0]
for l in range(len(B)-1):
    B_cum.append(B_cum[l] + B[l+1])
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    b = bisect.bisect(B_cum,K-k)
    check = i+b+1
    if check>ans:
        ans = check
print(ans)

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()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    B_check = (K-k)-B_cum
    while b - a != 0:
        c = int(round((a+b)/2))
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    if b ==0 and B_check[0] < 0:
        check = i+b+1
    else:
        check = i+b+2
    if check>ans:
        ans = check
print(ans)

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()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    B_check = (K-k)-B_cum
    while b - a != 0:
        c = int(round((a+b)/2))
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    check = i+b+2
    if check>ans:
        ans = check
print(ans)

Submission status: Wrong Answer

Solution code:
def get_cusum(lst):
    cusum = lst
    for i in range(1, len(lst)):
        cusum[i] = cusum[i] + cusum[i-1]
    return cusum

# めぐる式二分探索


def get_purse_index(lst, purse_value):
    left = -1  # max lst[i] < pv
    right = len(lst)  # min  pv < lst[i]

    while abs(right - left) > 1:
        mid = (left + right) // 2
        if lst[mid] >= purse_value:
            right = mid
        else:
            left = mid

    return right


def main():

    n, m, k = map(int, input().split(" "))
    book_a = get_cusum(list(map(int, input().split(" "))))
    book_b = get_cusum(list(map(int, input().split(" "))))
    ans = 0

    for i in range(n):
        if book_a[0] > k or book_b[0] > k:
            ans = max(get_purse_index(book_a, k),
                      get_purse_index(book_b, k))
        else:
            for i in range(n):
                bb = get_purse_index(book_b, k - book_a[i])
                if bb != len(book_b):
                    ans = (2 + i + bb) if book_a[i] + \
                        book_b[bb] <= k else i + 1
                else:
                    continue

    print(ans)


main()

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()))
cnt = 0
while True:
    
    if a[0] <= k or b[0] <= k:
        
        if a[0] > b[0]:
            k -= b.pop(0)
            if len(b) == 0:
                b.append(9999999999)
        else:
            k -= a.pop(0)
            if len(a) == 0:
                a.append(9999999999)
        cnt += 1
    
    if k == 0:
        break
    elif a[0] > k and b[0] > k:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:

from bisect import bisect_left

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

x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
    x[i + 1] = x[i] + A[i]

for i in range(M):
    y[i + 1] = y[i] + B[i]

ans = 0
for i in range(N + 1):
    if x[i] > K:
        continue
    j = bisect_left(y, K - x[i])
    if j < M and y[j] != K - x[i]:
        j -= 1
    ans = max(ans, i + j)
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 = []
b = []

def nibun(L,l,r,target):

  wrk = -(-(l+r)//2)
#  print(L,l,r,target,wrk)
  if l >= r:
#    print('1')
    return wrk+1
  if L[wrk] == target:
#    print('2')
    return wrk+1
  elif L[wrk] > target:
#    print('3')
    return nibun(L,l,wrk-1,target)
  else:
#    print('4')
    return nibun(L,wrk,r,target)

  
s = 0
for i,e in enumerate(B):
  s += e 
  b.append(s)

s = 0
ans = 0
for i in range(len(A)):
#  print(i,'kaime')
  s += A[i]
  if s >= K:
    break
  else:  
    wrk = nibun(b,0,len(b)-1,K-s)
    
    ans=max(ans,i+1+wrk)
#    print('koko',s,wrk,ans)

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 = []
b = []

def nibun(L,l,r,target):

  wrk = -(-(l+r)//2)
#  print(L,l,r,target,wrk)
  if l >= r:
#    print('1')
    return wrk+1
  if L[wrk] == target:
#    print('2')
    return wrk+1
  elif L[wrk] > target:
#    print('3')
    return nibun(L,l,wrk-1,target)
  else:
#    print('4')
    return nibun(L,wrk,r,target)

  
s = 0
for i,e in enumerate(B):
  s += e 
  b.append(s)

s = 0
ans = 0
for i in range(len(A)):
#  print(i,'kaime')
  s += A[i]
  if s > K:
    break
  else:  
    wrk = nibun(b,0,len(b)-1,K-s)
    
    ans=max(ans,i+1+wrk)
#    print('koko',s,wrk,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
enum = enumerate
INF = 1001001001

import collections
import random

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def dist(x1,y1,x2,y2):
	return abs(x1-x2)+abs(y1-y2)

def ran():
	vRan = [chr(i+ord("a")) for i in range(26)]
	random.shuffle(vRan)
	sr = "".join(vRan)
	print(sr)
	return sr

def main():
	N,M,K = linput()
	vA = linput()
	vB = linput()
	
	res = 0
	
	cnt = 0
	t = 0
	for a in vA:
		if t+a<=K:
			t += a
			cnt += 1
		else: break
	
	res = max(res,cnt)
	vJ = vA[0:cnt]
	for b in vB:
		while t+b>K:
			if not vJ: break
			j = vJ.pop()
			t -= j
			cnt -= 1
		else:
			t += b
			cnt += 1
			res = max(res,cnt)
	
	print(res)
	#sT = "No Yes".split()
	#print(sT[res])
	

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
enum = enumerate
INF = 1001001001

import collections
import random

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def dist(x1,y1,x2,y2):
	return abs(x1-x2)+abs(y1-y2)

def ran():
	vRan = [chr(i+ord("a")) for i in range(26)]
	random.shuffle(vRan)
	sr = "".join(vRan)
	print(sr)
	return sr

def main():
	N,M,K = linput()
	vA = linput()
	vB = linput()
	
	res = 0
	
	cnt = 0
	t = 0
	for a in vA:
		if t+a<=K:
			t += a
			cnt += 1
		else: break
	
	res = max(res,cnt)
	vJ = vA[0:cnt:-1]
	for b in vB:
		while t+b>K:
			if not vJ: break
			j = vJ.pop()
			t -= j
			cnt -= 1
		else:
			t += b
			cnt += 1
			res = max(res,cnt)
	
	print(res)
	#sT = "No Yes".split()
	#print(sT[res])
	

if __name__ == "__main__":
	main()

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()))
count = 0
while True:
    if len(A) > 0 and len(B) > 0:
        if A[0] <= B[0]:
            if K - A[0] >= 0:
                K -= A[0]
                count += 1
                A.pop(0)
            else:
                print(count)
                break
        else:
            if K - B[0] >= 0:
                K -= B[0]
                count += 1
                B.pop(0)
            else:
                print(count)
                break
    elif len(A) > 0:
        while True:
            if len(A) > 0:
                if K - A[0] >= 0:
                    K -= A[0]
                    count += 1
                    A.pop(0)
                else:
                    print(count)
                    break
            else:
                print(count)
                break
        break
    elif len(B) > 0:
        while True:
            if len(B) > 0: 
                if K - B[0] >= 0:
                    K -= B[0]
                    count += 1
                    B.pop(0)
                else:
                    print(count)
                    break
            else:
                print(count)
                break
        break
    else:
        print(count)
        break

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()))
count = 0
while True:
    if len(A) > 0 and len(B) > 0:
        if A[0] >= B[0]:
            if K - A[0] >= 0:
                K -= A[0]
                count += 1
                A.pop(0)
            else:
                print(count)
                break
        else:
            if K - B[0] >= 0:
                K -= B[0]
                count += 1
                B.pop(0)
            else:
                print(count)
                break
    elif len(A) > 0:
        while True:
            if len(A) > 0:
                if K - A[0] >= 0:
                    K -= A[0]
                    count += 1
                    A.pop(0)
                else:
                    print(count)
                    break
            else:
                print(count)
                break
        break
    elif len(B) > 0:
        while True:
            if len(B) > 0: 
                if K - B[0] >= 0:
                    K -= B[0]
                    count += 1
                    B.pop(0)
                else:
                    print(count)
                    break
            else:
                print(count)
                break
        break
    else:
        print(count)
        break

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()))
count = 0
while True:
    if K < 0:
        print(count-1)
        break
    if len(A) > 0 and len(B) > 0:
        if A[0] <= B[0]:
            K -= A[0]
            count += 1
            A.pop(0)
        else:
            K -= B[0]
            count += 1
            B.pop(0)
    elif len(A) == 0 and len(B) != 0:
        K -= B[0]
        count += 1
        B.pop(0)
    elif len(A) != 0 and len(B) == 0:
        K -= A[0]
        count += 1
        A.pop(0)
    else:
        print(count)
        break

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
from itertools import accumulate as ac
n,m,k=map(int,input().split())
a=list(ac([0]+list(map(int,input().split()))))
b=list(ac([0]+list(map(int,input().split()))))
l=0
for i in range(n+1):
    if k<a[i]:
        break
    else:
        l=max(l,i+bl(b,k-a[i])-1)
print(l)

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.insert(0,0)
cntB=0
cnt_list=[]

for i in range(n+1):
  timeA=sum(A[:i+1])
  cntA=i
  time=timeA
  if timeA>k:
    break
  for j in range(m):    
    if time+B[j]<=k:
      timeB=sum(B[:j+1])
      time=timeA+timeB    
      cntB=j+1
    else:
      break
  cnt=cntA+cntB
  cnt_list.append(cnt)
  
print(max(cnt_list))