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:
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sum_time = 0
now_read_book = 0
ans = 0
now_A = 0

for i in range(N):
  if sum_time + A[i] <= K:
    sum_time += A[i]
    now_read_book += 1
    now_A = i
  else:
    break
ans = now_read_book

for i in range(M):
  if sum_time + B[i] > K:
    while sum_time + B[i] > K and now_A != 0:
      sum_time -= A[now_A]
      now_A -= 1
      now_read_book -= 1
  if sum_time + B[i] <= K:
    sum_time += B[i]
    now_read_book += 1
  if now_read_book > ans:
    ans = now_read_book
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sum_time = 0
now_read_book = 0
ans = 0
now_A = 0

for i in range(N):
  if sum_time + A[i] <= K:
    sum_time += A[i]
    now_read_book += 1
    now_A = i
  else:
    break
ans = now_read_book

for i in range(M):
  if sum_time + B[i] > K:
    while sum_time + B[i] > K and now_A != 0:
      sum_time -= A[now_A]
      now_A -= 1
      ans -= 1
  if sum_time + B[i] <= K:
    sum_time += B[i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
temp = t = 0
for ai in range(n):
    if t + a_list[ai] > k:
        ai -= 1
        break
    t += a_list[ai]
    temp += 1
ans = temp
for bi in range(m):
    while t + b_list[bi] > k:
        if ai < 0:
            break
        t -= a_list[ai]
        ai -= 1
        temp -= 1
    else:
        t += b_list[bi]
        temp += 1
        if temp > ans:
            ans = temp
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()))

c=[0]
d=[0]

for i in range(n):
  c.append(c[-1]+a[i])
  
for j in range(m):
  d.append(d[-1]+b[j])

ans=0
for x in range(n+1):
  l=c[x]
  B=0
  if l<=k:
    h=k-l
    mi=0
    ma=m+1
    while ma-mi>1:
      mid=(mi+ma)//2
      if d[mid]<=h:
        mi=mid
      elif d[mid]>h:
        ma=mid
    B=mi
        
  ans=max(ans,x+B)
    
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()))

c=[0]
d=[0]

for i in range(n):
  c.append(c[-1]+a[i])
  
for j in range(m):
  d.append(d[-1]+b[j])

ans=0
for x in range(n):
  l=c[x]
  B=0
  if l<=k:
    h=k-l
    mi=0
    ma=m+1
    while ma-mi>1:
      mid=(mi+ma)//2
      if d[mid]<=h:
        mi=mid
      elif d[mid]>h:
        ma=mid
    B=mi
        
  ans=max(ans,x+B)
    
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()))

c=[0]
d=[0]

for i in range(n):
  c.append(c[-1]+a[i])
  
for j in range(m):
  d.append(d[-1]+b[j])

ans=0
for x in range(n):
  l=c[x+1]-c[x]
  B=0
  if l<=k:
    h=k-l
    mi=0
    ma=m+1
    while ma-mi>1:
      mid=(mi+ma)//2
      if d[mid]<=h:
        mi=mid
      elif d[mid]>h:
        ma=mid
    B=mi
        
  ans=max(ans,x+1+B)
    
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()))

c=[0]
d=[0]

for i in range(n):
  c.append(c[-1]+a[i])
  
for j in range(m):
  d.append(d[-1]+b[j])

ans=0
for x in range(n):
  l=c[x+1]-c[x]
  B=0
  if l<=k:
    h=k-l
    mi=0
    ma=m+1
    while ma-mi>1:
      mid=(mi+ma)//2
      if d[mid]<=h:
        mi=mid
      elif d[mid]<h:
        ma=mid
    B=mi
        
  ans=max(ans,x+1+B)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
ans = t = 0
for ai in range(n):
    if t + a_list[ai] > k:
        ai -= 1
        break
    t += a_list[ai]
    ans += 1
for bi in range(m):
    while t + b_list[bi] > k:
        if ai == 0:
            break
        t -= a_list[ai]
        ai -= 1
        ans -= 1
    else:
        t += b_list[bi]
        ans += 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()))

c=[0]
d=[0]

for i in range(n):
  c.append(c[-1]+a[i])
  
for j in range(m):
  d.append(d[-1]+b[j])

ans=0
for x in range(n):
  l=c[x+1]-c[x]
  B=0
  if l<=k:
    h=k-l
    mi=0
    ma=m+1
    while ma-mi>1:
      mid=(mi+ma)//2
      if d[mid]<=h:
        mi=mid
      elif d[mid]<h:
        mi=mid
    B=mi
        
  ans=max(ans,x+1+B)
    
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]
ans = 0
max_num = 0
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
for i in range(N+1):
    j = M
    while b[j] > K - a[i]:
        j -=1
        if j <0:
            break
    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()))
k=0
ans=0
a=0
b=0
for i in range(N+M+1):
  if a==N and b==M:
    break
  elif a==N:
    k+=B[b]
    b+=1
  elif b==M:
    k+=A[a]
    a+=1
  else:
    if A[a]>=B[b]:
      k+=B[b]
      b+=1
    else:
      k+=A[a]
      a+=1
  if k<=K:
    ans+=1
  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()))
Time_=0
ans=0
a=0
b=0
for i in range(N+M+1):
  if a==N and b==M:
    break
  elif a==N:
    Time_+=B[b]
    b+=1
  elif b==M:
    Time_+=A[a]
    a+=1
  else:
    if A[a]>=B[b]:
      Time_+=B[b]
      b+=1
    else:
      Time_+=A[a]
      a+=1
  if Time_<=K:
    ans+=1
  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()))
ans,right=0,0

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])
for i in range(m+1):
  if k<B[i] or i==m:
    right=i-1
    ans=right
    break

for j in range(0,n):
  if k<a[j]:
    break
  k-=a[j]
  while k<B[right]:
    right-=1
  ans=max(ans,right+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()))
ans,right=0,0

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])
for i in range(m+1):
  if k<B[i] or i==m:
    right=i
    ans=right
    break

for j in range(0,n):
  if k<a[j]:
    break
  k-=a[j]
  while k<B[right]:
    right-=1
  ans=max(ans,right+j+1)
  print(j,right)
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()))
Time=0
ans=0
a=0
b=0
for i in range(N+M+1):
  if a==N and b==M:
    break
  elif a==N:
    Time+=B[b]
    b+=1
  elif b==M:
    Time+=A[a]
    a+=1
  else:
    if A[a]>=B[b]:
      Time+=B[b]
      b+=1
    else:
      Time+=A[a]
      a+=1
  if Time<=K:
    ans+=1
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

    for i in range(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n + 1):
        j = max(ans - i, 0)
        if j > m or A[i] + B[j] > k: continue
        while j < m:
            if A[i] + B[j] > k:
                j -= 1
                break
            j += 1
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()

Submission status: Wrong Answer

Solution code:
def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

    for i in range(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n+1):
        j = max(ans - i, 0)
        if j > m: continue
        while j < m:
            if A[i] + B[j] > k:
                j -= 1
                break
            j += 1
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()

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

for i in range(N+M):
    if len(A) == 0:
        time += B[0]
        B.remove(B[0])
        cnt += 1
        if time > K:
            cnt -= 1
            break
        elif time == K:
            break
    elif len(B) == 0:
        time += A[0]
        A.remove(A[0])
        cnt += 1
        if time > K:
            cnt -= 1
            break
        elif time == K:
            break
    else:
        if A[0] <= B[0]:
            time += A[0]
            A.remove(A[0])
            cnt += 1
            if time > K:
                cnt -= 1
                break
            elif time == K:
                break
        else:
            time += B[0]
            B.remove(B[0])
            cnt += 1
            if time > K:
                cnt -= 1
                break
            elif time == K:
                break

print(cnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ans = [0]
time_sum = 0
i, j = 0, 0

flag_a = True
flag_b = True
flag = False
for i in range(0, len(aa)+1):
    for j in range(0, len(bb)+1):
        asum, bsum = sum(aa[:i]), sum(bb[:j])
        if k < asum or k < bsum:
            flag = True
            break
        else:
            time_total = asum + bsum
            if time_total > k:
                break
            else:
                ans.append(i+j)
    if flag:
        break

print(max(ans))

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(A_ls) - 1):
    A_ls[i + 1] += A_ls[i]

B_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(B_ls) - 1):
    B_ls[i + 1] += B_ls[i]

b_cnt,result = M, 0
for a_cnt in range(N):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -= 1
    result = max(result, a_cnt + b_cnt)
print(result)

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,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])

for j in range(n+1):
  K=k-A[j]
  if K<0:
    break
  else:
    ans=max(ans,bisect.bisect_left(B,K)+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()))

A.reverse()
B.reverse()

books = []
for i in range(N+M):
    if A and B :
        if A[-1] <= B[-1]:
            books.append(A.pop())
        else:
            books.append(B.pop())
    elif A:
        books.append(A.pop())
    else:
        books.append(B.pop())

books.reverse()
# print(books)

time = 0
c = 0
for _ in range(N+M):
    if time + books[-1] <= K:
        time += books.pop()
        c += 1
    else:
        break

print(c)

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]*n
B=[0]*m
A[0]=a[0]
B[0]=b[0]
ans=0

for i in range(1,n):
  A[i]=A[i-1]+a[i]
for i in range(1,m):
  B[i]=B[i-1]+b[i]

for j in range(n):
  K=k-A[j]
  if K<0:
    break
  left=0
  right=m
  while left<right:
    mid=(left+right)//2
    if B[mid]>K:
      right=mid
    else:
      left=mid+1
  ans=max(ans,j+left+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()))
kouho=[]
aa=[]
aa.append(0)
aa.append(a[0])
for i in range(len(a)-1):
  aa.append(aa[i+1]+a[i+1])
bb=[]
bb.append(0)
bb.append(b[0])
for i in range(len(b)-1):
  bb.append(bb[i+1]+b[i+1])
#print(aa)
#print(bb)
for i in range(len(aa)):
  nokori=k-aa[i]
  #print(nokori)
  for j in range(len(bb)):
    if bb[j]>nokori:
      kouho.append(i+j-1)
      break
    if j==len(bb)-1:
      kouho.append(i+j)
print(max(kouho))
#print(kouho)

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

T = 0

###Aだけなら何冊読めるか
a = 0
for i in range(N):
    if T + A[i]> K:
        break
    T += A[i]
    a += 1

m = a
count = a
num = 0

while a >= 0 and num < M:
    #print(m,a,T)
    while num < M and K-T >= B[num]:
        T += B[num]
        count += 1
        num += 1
    
    m = max(m,count)

    if a == 0:
        break
    T -= A[a-1]
    count -= 1

print(m)

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

T = 0

###Aだけなら何冊読めるか
a = 0
for i in range(N):
    if T + A[i]> K:
        break
    T += A[i]
    a += 1

m = a
count = a
num = 0

while a-1 >= 0 and num < M:
    #print(m,a,T)
    while num < M and K-T >= B[num]:
        T += B[num]
        count += 1
        num += 1
    
    m = max(m,count)

    T -= A[a-1]
    count -= 1

print(m)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

A = deque(A)
B = deque(B)

KK = K
count = 0
while KK > 0 and (A or B):
    if A and (B==deque([]) or A[0] <= B[0]) and A[0] <= KK:
        count += 1
        a = A.popleft()
        KK -= a
        continue
    elif B and (A==deque([]) or B[0] <= A[0]) and B[0] <= KK:
        count += 1
        b = B.popleft()
        KK -= b
        continue
    break

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

A = deque(A)
B = deque(B)

KK = K
count = 0
while KK > 0:
    if A and (list(B)==[] or A[0] <= B[0]) and A[0] <= KK:
        count += 1
        a = A.popleft()
        KK -= a
        continue
    elif B and (list(A)==[] or B[0] <= A[0]) and B[0] <= KK:
        count += 1
        b = B.popleft()
        KK -= b
        continue
    break

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=input().split()
b=input().split()
for i in a:
  i=int(i)
for i in b:
  i=int(i)
tim=0
count=0
while tim<=k:
  if len(a)==0 or len(b)==0:
    break
  if int(a[0])>=int(b[0]):
    tim+=int(b[0])
    if tim>k:
      break
    del b[0]
  else:
    tim+=int(a[0])
    if tim>k:
      break
    del a[0]
  count+=1
if len(a)==0:
  while tim<=k:
    if len(b)==0:
      break
    tim+=int(b[0])
    if tim>k:
      break
    count+=1
    del b[0]
if len(b)==0:
  while tim<=k:
    if len(a)==0:
      break
    tim+=int(a[0])
    if tim>k:
      break
    count+=1
    del a[0]
    
print(count)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1, aae in enumerate(aa):
        if aae > k:
            break
        else:
            time_remain = k - aae
            b_num = bisect(ba, time_remain)
            r = max(r, i1 + 1 + b_num)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a,b,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

from bisect import bisect, bisect_left,bisect_right
from itertools import accumulate

A = list(accumulate(A))
B = list(accumulate(B))

idxa = bisect(A,k)
idxb = bisect(B,k)
#print(A,B,idxa,idxb)
if idxa == 0 or idxb == 0:
    print(max(idxa,idxb))
    exit()
    
ans = 0  
for i in range(idxa):
    idx = bisect_right(B,k-A[i])
    ans = max(ans,i+1+idx)
    
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

from bisect import bisect, bisect_left
from itertools import accumulate

A = list(accumulate(A))
B = list(accumulate(B))

idxa = bisect(A,k)
idxb = bisect(B,k)
#print(A,B,idxa,idxb)
if idxa == 0 or idxb == 0:
    print(max(idxa,idxb))
    exit()
    
ans = 0  
for i in range(idxa):
    idx = bisect(B,k-A[i])
    ans = max(ans,i+1+idx)
    
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 = [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 + 1):
  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:
import itertools
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A_=list(itertools.accumulate(A))
B_=list(itertools.accumulate(B))

ans=0
j=M-1
for i in range(N):
    a=A_[i]
    K_ai=K-a
    while (j>=0 and B_[j]>K_ai):
        j-=1
    if a+B_[j]<=K:
        ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=sum(b)
i=0
j=m
ls=[]

if sum(a)==k:
  print(n)
  sys.exit()
  
elif sum(b)==k:
  print(m)
  sys.exit()

while (i<n and j>0):
  if count>k:
    j-=1
    count-=b[j]
    
  elif count<=k:
    if count==k:
      ls.append(i+j)
      i+=1
      
    else:
      count+=a[i]
      i+=1
      if count<=k:
        ls.append(i+j)

z=-1
if i==0:
  i=n
  count=sum(a)
  while i>0:
    if count>k:
      count-=a[z]
      z-=1
      i-=1
      
    else:
      ls.append(i)
      i-=1
    
print(max(ls) if len(ls)>0 else 0)

Submission status: Wrong Answer

Solution code:
import sys

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=sum(b)
i=0
j=m
ls=[]

if sum(a)==k:
  print(n)
  sys.exit()
  
elif sum(b)==k:
  print(m)
  sys.exit()

while (i<n and j>0):
  if count>k:
    j-=1
    count-=b[j]
    
  elif count<=k:
    if count==k:
      ls.append(i+j)
      j-=1
      
    else:
      count+=a[i]
      i+=1
      if count<=k:
        ls.append(i+j)
    
print(max(ls) if len(ls)>0 else 0)

Submission status: Wrong Answer

Solution code:
import sys

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=sum(b)
i=0
j=m
ls=[]

if sum(a)==n:
  print(n)
  sys.exit()
  
elif sum(b)==m:
  print(m)
  sys.exit()

if sum(b)==k:
  ls.append(m)
  
elif sum(a)==k:
  ls.append(n)

while (i<n and j>0):
  if count>k:
    j-=1
    count-=b[j]
    
  elif count<=k:
      count+=a[i]
      i+=1
      
      if count<=k:
        ls.append(i+j)
    
print(max(ls) if len(ls)>0 else 0)

Submission status: Wrong Answer

Solution code:
import sys

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=sum(b)
i=0
j=m
ls=[]

if sum(a)==n:
  print(n)
  sys.exit()
  
elif sum(b)==m:
  print(m)
  sys.exit()

while (i<n and j>0):
  if count>k:
    j-=1
    count-=b[j]
    
  elif count<=k:
    if count==k:
      print(i+j)
      sys.exit()
      
    else:
      count+=a[i]
      i+=1
      
      if count<=k:
        ls.append(i+j)
    
print(max(ls) if len(ls)>0 else 0)

Submission status: Wrong Answer

Solution code:
import sys

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=sum(b)
i=0
j=m
ls=[]
if sum(a)==k:
  print(n)
  sys.exit()
  
elif sum(b)==k:
  print(m)
  sys.exit()

while (i<n and j>0):
  if count>k:
    j-=1
    count-=b[j]
    
  elif count<=k:
    count+=a[i]
    i+=1
    if count<=k:
      ls.append(i+j)
    
print(max(ls) if len(ls)>0 else 0)

Submission status: Wrong Answer

Solution code:
import sys

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=sum(b)
i=0
j=m
ls=[]
if sum(a)==k:
  print(n)
  sys.exit()

while (i<n and j>0):
  if count>=k:
    j-=1
    count-=b[j]
    
  elif count<k:
    count+=a[i]
    i+=1
    if count<=k:
      ls.append(i+j)
    
print(max(ls) if len(ls)>0 else 0)

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=sum(b)
i=0
j=m
ls=[]

while (i<n and j>0):
  if count>=k:
    j-=1
    count-=b[j]
    
  elif count<k:
    count+=a[i]
    i+=1
    if count<=k:
      ls.append(i+j)
    
print(max(ls) if len(ls)>0 else 0)

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=sum(b)
i=0
j=m
ls=[]

while (i<n and j>0):
  if count>k:
    j-=1
    count-=b[j]
    
  elif count<=k:
    count+=a[i]
    i+=1
    if count<=k:
      ls.append(i+j)
    
print(max(ls) if len(ls)>0 else 0)

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()))
c1,c2,ac,bc=0,0,0,0
ls=[]

for i in a:
  c1+=1
  ac+=i
  for j in b:
    c2+=1
    bc+=j
    if ac+bc<=k:
      ls.append(c1+c2)
      
    else:
      c2=0
      bc=0
      break
      
  c2=0
  bc=0
  
print(max(ls) if len(ls)>0 else 0)

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()))
n1=[0]
n2=[0]
c=0

for i in a:
  c=n1[-1]+i
  if c<=k:
    n1.append(c)
    
  else:
    break
    
for i in b:
  c=n2[-1]+i
  if c<=k:
    n2.append(c)
    
  else:
    break
    
del n1[0]
del n2[0]
c1,c2=0,0
ls=[]

for i in n1:
  c1+=1
  for j in n2:
    c2+=1
    if i+j<=k:
      ls.append(c1+c2)
      
    else:
      c2=0
      break
      
  c2=0
      
print(max(ls) if len(ls)>0 else 0)

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

Ai = max_A = max_SA = 0
Bi = max_B = max_SB = 0

for i in range(N):
    if Ai + A[i] <= K:
        Ai += A[i]
        max_SA = Ai
        max_A = i
    else:
        break

for i in range(M):
    if Bi + B[i] <= K:
        Bi += B[i]
        max_SB = Bi
        max_B = i
    else:
        break

# 局所探索でより効率的な解がないかを探す
cursol_A = max_A #ここまで探索した
cursol_B = 0 #ここから探索する
tmp_K = max_SA
ans = max_A
if max_A != 0:
    ans += 1

# cursol_B = 0 でどこまで動かせるか
tmp = 0
for j in range(max_B+1):
    if tmp_K + B[j] <= K:
        tmp_K += B[j]
        tmp += 1
    else:
        break

cursol_B = tmp #ここから探索する
ans += tmp

# cursol_B > 0でAを1個ずつ減らしていってどれだけ増分できるか
for i in range(cursol_A - 1, -1, -1):
    tmp_K -= A[i]
    # cursol_Bをどこまで進められるか
    tmp = 0
    for j in range(cursol_B, max_B+1):
        if tmp_K + B[j] <= K:
            tmp_K += B[j]
            tmp += 1
        else:
            break
        
    ans = max(ans, ans + tmp - 1)
    cursol_B += tmp

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

Ai = max_A = max_SA = 0
Bi = max_B = max_SB = 0

for i in range(N):
    if Ai + A[i] <= K:
        Ai += A[i]
        max_SA = Ai
        max_A = i
    else:
        break

for i in range(M):
    if Bi + B[i] <= K:
        Bi += B[i]
        max_SB = Bi
        max_B = i
    else:
        break

# 局所探索でより効率的な解がないかを探す
cursol_A = max_A #ここまで探索した
cursol_B = 0 #ここから探索する
tmp_K = max_SA
ans = max_A
if max_A != 0:
    ans += 1

# cursol_B = 0 でどこまで動かせるか
tmp = 0
for j in range(max_B+1):
    if tmp_K + B[j] <= K:
        tmp_K += B[j]
        tmp += 1
    else:
        break

cursol_B = tmp #ここから探索する
ans += tmp

# cursol_B > 0でAを1個ずつ減らしていってどれだけ増分できるか
for i in range(cursol_A - 1, -1, -1):
    tmp_K -= A[i]
    # cursol_Bをどこまで進められるか
    tmp = 0
    for j in range(cursol_B, max_B+1):
        if tmp_K + B[j] <= K:
            tmp_K += B[j]
            tmp += 1
        else:
            break
        
    ans += tmp
    cursol_B += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import random
import bisect
from collections import deque

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret

x = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n, m, time = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

a_pos = bisect.bisect_left(a_sum, time+0.1)
b_pos = bisect.bisect_left(b_sum, time+0.1)
read = 0
for i in range(a_pos):
    bpos = bisect.bisect_left(b_sum, time-a_sum[i]+.1)
    read = max(read, i+bpos+1)

print (read)

Submission status: Wrong Answer

Solution code:
import sys
import random
import bisect
from collections import deque

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret

x = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n, m, time = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

a_pos = bisect.bisect_left(a_sum, time)
b_pos = bisect.bisect_left(b_sum, time)
read = 0
for i in range(a_pos):
    bpos = bisect.bisect_left(b_sum, time-a_sum[i]+.1)
    read = max(read, i+bpos+1)

print (read)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

x = input().split()
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))

n, m, time = int(x[0]), int(x[1]), int(x[2])

read = []

while True:
    k = time - sum(read)
    if len(a)==0 and len(b)==0:
        break # read everything
    elif len(a)==0 and len(b)>0:
        if b[0]<=k:
            read.append(b.popleft())
        else:
            break # nothing can be read
    elif len(b)==0 and len(a)>0:
        if a[0]<=k:
            read.append(a.popleft())
        else:
            break # nothing can be read
    elif a<=b and a[0]<=k:
        read.append(a.popleft())
    elif b<=a and b[0]<=k:
        read.append(b.popleft())
    else:
        break

print (len(read))

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

Ai = max_A = max_SA = 0
Bi = max_B = max_SB = 0

for i in range(N):
    if Ai + A[i] <= K:
        Ai += A[i]
        max_SA = Ai
        max_A = i
    else:
        break

for i in range(M):
    if Bi + B[i] <= K:
        Bi += B[i]
        max_SB = Bi
        max_B = i
    else:
        break

# 局所探索でより効率的な解がないかを探す
cursol_A = max_A #ここまで探索した
cursol_B = 0 #ここから探索する
tmp_K = max_SA
ans = max_A
if max_A != 0:
    ans += 1

# cursol_B = 0 でどこまで動かせるか
tmp = 0
for j in range(max_B+1):
    if tmp_K + B[j] <= K:
        tmp_K += B[j]
        tmp += 1
    else:
        break

cursol_B = tmp #ここから探索する
ans += tmp

# cursol_B > 0でAを1個ずつ減らしていってどれだけ増分できるか
for i in range(cursol_A - 1, -1, -1):
    tmp_K -= A[i]
    # cursol_Bをどこまで進められるか
    tmp = 0
    for j in range(cursol_B, max_B+1):
        if tmp_K + B[j] <= K:
            tmp_K += B[j]
            tmp += 1
        else:
            break
        
    ans = max(ans, ans + tmp -1)
    cursol_B = min(max_B, cursol_B + tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

x = input().split()
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))

n, m, time = int(x[0]), int(x[1]), int(x[2])

read = []

while True:
    k = time - sum(read)
    if len(a)==0 and len(b)==0:
        break # read everything
    elif len(a)==0 and len(b)>0:
        if b[0]<=k:
            read.append(b.popleft())
        else:
            break # nothing can be read
    elif len(b)==0 and len(a)>0:
        if a[0]<=k:
            read.append(a.popleft())
        else:
            break # nothing can be read
    elif a<b and a[0]<=k:
        read.append(a.popleft())
    elif b<=a and b[0]<=k:
        read.append(b.popleft())
    else:
        break

print (len(read))