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:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
len_A = len(A)
len_B = len(B)
it = 200000 * 2
k = 0
count = 0
select = list()
choice = 'A'
for i in range(it):
  if len_A == 0 and len_B == 0:
    break
  elif len_A == 0 and len_B != 0:
    # Bの本のみ
    select = B
    choice = 'B'
  elif len_B == 0 and len_A != 0:
    # Aの本のみ
    select = A
    choice = 'A'
  elif A[0] <= B[0]:
    # BよりもAの方が早く読める(同じも含む)
    select = A
    choice = 'A'
  elif A[0] > B[0]:
    select = B
    choice = 'B'
  k += select[0]
  if k <= K:
    count += 1
  else:
    break
  if choice == 'A':
    len_A -= 1
  else:
    len_B -= 1
  select.pop(0)
print(count)

Submission status: Wrong Answer

Solution code:
def INPUT():return list(int(i) for i in input().split())
n,m,k=INPUT()
A=INPUT()
B=INPUT()
Sa=[0]*(n+1)
Sb=[0]*(m+1)
for i in range(1,n+1):
    Sa[i]+=Sa[i-1]+A[i-1]
for j in range(1,m+1):
    Sb[j]+=Sb[j-1]+B[j-1]
for i in range(n+1):
    if Sa[i]>k:
        break
    else:
        x=i
for j in range(m+1):
    if Sb[j]>k:
        break
    else:
        y=j
sum=Sa[x]+Sb[y]
# print(sum)
# print(Sa)
# print(Sb)
ans=x+y
while(sum>k):
    if A[x-1]<B[y-1]:
        sum-=B[y-1]
        y-=1
        ans-=1
    else:
        sum-=A[x-1]
        x-=1
        ans-=1
    #print(sum)
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()))

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0
j=M-1
for i in range(N):
    if sumA[i]>=K:
        break
    while K<sumA[i]+sumB[j] 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()))
A.append(10**9)
B.append(10**9)

Ac = 0
Bc = 0
Time = 0
for _ in range(N+M):
    if A[Ac] > B[Bc]:
        Time += B[Bc]
        Bc += 1
        if Time > K:
            Bc -= 1
            Time -= B[Bc]
            break
    else:
        Time += A[Ac]
        Ac += 1
        if Time > K:
            Ac -= 1
            Time -= A[Ac]
            break
            
print(Ac+Bc)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(300000)
from itertools import accumulate
from bisect import bisect_right

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

def bi(A, x):
    l = -1
    r = len(A)
    while l + 1 < r:
        p = (l + r) // 2
        if x < A[p]:
            r = p
        else:
            l = p
    return r

N, M, K = MI()
A = LMI()
B = LMI()

accA = list(accumulate([0, *A]))
accB = list(accumulate(B))
ans = 0
for i in range(N + 1):
    left = K - accA[i]
    if left <= 0:
        break
    a = i + bi(accB, left)
    ans = max(ans, a)
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()))

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0
j=M-1
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>0:
        j-=1
    ans=max(ans,i+j+2)
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()))

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(300000)
from itertools import accumulate
from bisect import bisect_right

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M, K = MI()
A = LMI()
B = LMI()

accA = list(accumulate([0, *A]))
accB = list(accumulate(B))
ans = 0
for i in range(N + 1):
    left = K - accA[i]
    if left <= 0:
        break
    a = i + bisect_right(accB, left)
    ans = max(ans, a)
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()))

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0
j=M-1
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    if i==0:
        best=j
    ans=max(ans,i+j+2)
    j=best
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m,k=map(int,input().split())
n+=1
A=list(map(int,input().split()))
A = [0]+A
B= list(map(int,input().split()))
S = sum(B)
ind = m-1
data=[0]*n
tmp = 0
for i in range(n):
  tmp += A[i]
  while tmp + S > k and ind>=0:
    S -= B[ind]
    ind-=1
  if ind == -1:data[i] = -inf
  else:data[i] = ind

for i in range(n):
  ans = max(ans,i+data[i]+1)
    
print(ans)
# print(data)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

N, M, lim = mi()
A = li()
B = li()

A = [0] + list(accumulate(A))
ans = 0

for i in range(N+1):
    if lim < A[i]:
        continue
    right = 0
    cnt = 0
    wa = 0
    left = 0

    while right < M and wa + B[right] <= lim - A[i]:
        wa += B[right]
        right += 1

    cnt = right - left

    if cnt > 0:
        ans = max(ans, cnt+i)

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
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        if i == 0:
            for j in range(m):
                if b[j] > k:
                    break;
                c = j+1
            break;
        else:
            break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    c = max(c, i+m+1)
    if m == 0:
        break;
print(c)

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

for i in range(1,n):
  a_list[i]=a_list[i-1]+a_list[i]
for i in range(1,m):
  b_list[i]=b_list[i-1]+b_list[i]

max_ = 0
for i in range(n):
  if k < a_list[i]:
    break
  
  for j in range(m):
    if b_list[m-j-1]>k-a_list[i]:
      pass
    else:
      max_ = max(len(a_list[:i+1])+len(b_list[:m-j]), max_)
      break
print(max_)

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
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        if i == 0:
            for j in range(m):
                c = j
                if b[j] > k:
                    break;
            break;
        else:
            break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    c = max(c, i+m+1)
    if m == 0:
        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()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        if i == 0:
            for j in range(m):
                if b[j] > k:
                    break;
                c = j
            break;
        else:
            break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    c = max(c, i+m+1)
    if m == 0:
        break;
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))

minutes = 0
books = 0
an_read_time = A.popleft()
bn_read_time = B.popleft()

def a_read(minutes, an_read_time, books):
    minutes += an_read_time
    an_read_time = A.popleft()
    books += 1
    return minutes, an_read_time, books

def b_read(minutes, bn_read_time, books):
    minutes += bn_read_time
    bn_read_time = B.popleft()
    books += 1
    return minutes, an_read_time, books
 
while minutes <= K:
    if len(A)==0 and len(B)==0:
        books += 2
        break
    if len(A) == 0 or len(B) == 0:
        if len(A) == 0:
            while len(B) != 0:
                minutes, bn_read_time, books = b_read(minutes, bn_read_time, books)
        if len(B) == 0:
            while len(A) != 0:
                minutes, an_read_time, books = a_read(minutes, an_read_time, books)
        break
    if an_read_time <= bn_read_time:
        minutes, an_read_time, books = a_read(minutes, an_read_time, books)
    elif bn_read_time > bn_read_time:
        minutes, bn_read_time, books = b_read(minutes, bn_read_time, books)
                
print(books - 1)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

a_sum = [0]
for i in range(len(A)):
    a_sum.append(a_sum[-1]+A[i])
    
b_sum = [0]
for i in range(len(B)):
    b_sum.append(b_sum[-1]+B[i])

max_time = 0
for i in range(len(a_sum)):
    for j in range(len(b_sum)-1, -1, -1):
        if a_sum[i]+b_sum[j] <= K:
            max_time = i+j
            break
print(max_time)

Submission status: Wrong Answer

Solution code:
import bisect

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]+a[i-1]
for j in range(1,m+1):
  b[j] = b[j]+b[j-1]

book_cnt=0
for a_cnt in range(n+1):
  if a[a_cnt]>=k:
    continue
  rest=k-a[a_cnt]
  b_cnt=bisect.bisect(b,rest)-1
  book_cnt=max(book_cnt,a_cnt+b_cnt)

print(book_cnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k and i > 0:
        break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    c = max(c, i+m+1)
    if m == 0:
        break;
print(c)

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

asum=[0]
bsum=[0]

for i in range(n):
  asum.append(asum[i]+A[i])
  
for j in range(m):
  bsum.append(bsum[j]+B[j])

ans=0
ko=m
for i in range(n+1):
  if asum[i]>k:
    break
  while asum[i]+bsum[ko]>k:
    ko-=1
  ans=max(ans,i+ko)
  
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from itertools import accumulate

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

a_book = [0] + list(accumulate([int(x) for x in input().split()]))
b_book = [0] + list(accumulate([int(x) for x in input().split()]))

check = {}

max_books = 0

for i, a in enumerate(a_book):
    b_pos = bisect_right(b_book, K - a)

    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i

print(max_books)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Acc=list(accumulate(B))
ans=0
time=0
a_cnt=0
for a in A:
    time+=a
    a_cnt+=1
    remain=k-time
    if remain<0:
        break
    b_cnt=bisect_right(Acc,remain)
    ans=max(ans,a_cnt+b_cnt)
remain=k-time
if remain>=0:
    b_cnt=bisect_right(Acc,remain)
    ans=max(ans,a_cnt+b_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)

ans = 0
na = len(A)
nb = len(B)
for i in range(na):
    a = A[i]
    j = bisect_right(B, k-a)
    b = B[-1]
    if j < nb: b = B[j]
    # print('i',i,'a',a,'k-a',k-a,'j',j,'b',b,'i+j-1',i+j-1)
    ans = max(ans, i+j-1)

# print(k)
# print(A)
# print(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
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    c = max(c, i+m+1)
    if m == 0:
        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()))
c=0
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  d=K-A[i]
  if d>=0:
    for j in reversed(range(M)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        M=j+1
        break
    if d<B[0]:
      if c<i+1:
        c=i+1
  else:
    for j in reversed(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    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()))
m = 0
def calc(T):
  c = 0
  S = 0
  while c in range(M):
    S += B[c]
    if S<=T:
      pass
    elif S>T:
      break
    c += 1
  return c
t = 0
while t in range(N):
  K -= A[t]
  if K<0:
    break
  else:
    e = calc(K)
    m = max(m, t+e+1)
    t += 1
print(m)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum = list(accumulate(a))
bsum = list(accumulate(b))

ans = 0
for i, v in enumerate(asum, start=1):
    if v > k:
        break
    index = bisect.bisect_right(bsum, k-v)
    ans = max(ans, i + index)
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
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    if m == 0:
        break;
    c = max(c, i+m+1)
print(c)

Submission status: Wrong Answer

Solution code:
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 27/06/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n, m, k = iia()
arr = sorted(iia() + iia())
res = 0
for i in arr:
    if i <= k:
        res += 1
        k -= i
    else:
        break
print(res)

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

read = 0

c = k
for i in range(0, n):
    d = c
    for j in range(0, m):
        read=c
# read += 0 if d-a[-1]<0 else 1
print(read)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import numpy as np
N, M, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

cumsum_A = [0] + A.cumsum()
cumsum_B = [0] + B.cumsum()
print('cusmum_A', cumsum_A)
print('cusmum_B', cumsum_B)

ans = 0
for num_A, t in enumerate(cumsum_A, start=1):
    if t > K:
        break
    if t == K:
        ans = max(ans, num_A)
    num_B = bisect_left(cumsum_B, K - t)
    # print('K - t, num_B, num_A + num_B', K - t, num_B, num_A + num_B)
    ans = max(ans, num_A + num_B)

for num_B, t in enumerate(cumsum_B, start=1):
    if t <= K:
        ans = max(ans, num_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()))
ans = 0
min = 0
i = 0
j = 0
while min <= K:
	if (i < N) or (j < M):
		if (i < N) and (j < M):
			if A[i]<=B[j]:
				min = min+A[i]
				i = i+1
				ans = ans+1
			else:
				min = min+B[j]
				j = j+1
				ans = ans+1
		elif (i == N):
				min = min+B[j]
				j = j+1
				ans = ans+1
		else:
				min = min+A[i]
				i = i+1
				ans = ans+1
	else:
		ans = ans+1
		break
ans = ans-1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import numpy as np
N, M, K = map(int, input().split())
A = np.array([0] + list(map(int, input().split())))
B = np.array([0] + list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

cumsum_A = A.cumsum()
cumsum_B = B.cumsum()
# print('cusmum_A', cumsum_A)
# print('cusmum_B', cumsum_B)

ans = 0
for num_A in range(len(cumsum_A)):
    t = cumsum_A[num_A]
    if t > K:
        break
    if t == K:
        ans = max(ans, num_A)
        continue
    num_B = bisect_left(cumsum_B, K - t) - 1
    # print('num_A, num_B', num_A, num_B)
    ans = max(ans, num_A + num_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()))
ans = 0

req = 0

while True:
    al = len(a)
    bl = len(b)
    if al*bl > 0:
        if a[0] < b[0]:
            req += a[0]
            a.pop(0)
        else:
            req += b[0]
            b.pop(0)
    elif al > 0:
        req += a[0]
        a.pop(0)
    elif bl > 0:
        req += b[0]
        b.pop(0)
    else:
        break

    if req > k:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys
input=sys.stdin.readline
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
idA,idB=0,0
cnt,time=0,0
mx=10000000000
while(True):
  if(idA>=N and idB>=M):
    break
  if(idA==N):
    A.append(mx)
  if(idB==M):
    B.append((mx))
  if(time+min(A[idA],B[idB])>K):
    break
  elif(A[idA]<B[idB]):
    time+=A[idA]
    idA+=1
  else:
    time+=B[idB]
    idB+=1
  cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans, tmp = 0, m
for i in range(n + 1):
    if SA[i] > k:
        break
    for j in range(tmp, 0, -1):
        if SA[i] + SB[j] <= k:
            ans = max(ans, i + j)
            break
    tmp = 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=[0]+A
B=[0]+B
import numpy as np
a=np.cumsum(A)
b=np.cumsum(B)

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

Submission status: Wrong Answer

Solution code:
import math
from queue import Queue

n, m, k = map(int, input().split(" "))
aLi = list(map(int, input().split(" ")))
bLi = list(map(int, input().split(" ")))

a = [0 for _ in range(n + 1)]
b = [0 for _ in range(m + 1)]

aMax = k
bMax = k
for i in range(n):
    a[i + 1] = a[i] + aLi[i]
    if (a[i + 1] >= k):
        aMax = i + 1
        break
for i in range(m):
    b[i + 1] = b[i] + bLi[i]
    if (b[i + 1] >= k):
        bMax = i + 1
        break

_max = 0
for i, ai in enumerate((a[:aMax])):
    for j, bi in enumerate((b[:bMax])):
        if ai + bi <= k:
            _max = max(_max, i + j)

print(_max)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import numpy as np
N, M, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

cumsum_A = [0] + A.cumsum()
cumsum_B = [0] + B.cumsum()
print('cusmum_A', cumsum_A)
print('cusmum_B', cumsum_B)

ans = 0
for num_A, t in enumerate(cumsum_A, start=1):
    if t > K:
        continue
    if t == K:
        ans = max(ans, num_A)
    num_B = bisect_left(cumsum_B, K - t)
    # print('K - t, num_B, num_A + num_B', K - t, num_B, num_A + num_B)
    ans = max(ans, num_A + num_B)

for num_B, t in enumerate(cumsum_B, start=1):
    if t <= K:
        ans = max(ans, num_B)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit
import copy
# import numpy as np
from collections import deque

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

cnt = 0

a_sum = [0]
b_sum = [0]

a_sum.extend(a)
b_sum.extend(b)


for i in range(1, n+1):
    a_sum[i] += a_sum[i-1]

for i in range(1, m+1):
    b_sum[i] += b_sum[i-1]


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] > k and a_sum[i] + b_sum[j-1] < k:
            cnt = max(cnt, i + j-1)
            break

print(cnt)

Submission status: Wrong Answer

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

b_sum=[0]*M
for i in range(M):
    if i==0:
        b_sum[i]=Bs[i]
    else:
        b_sum[i]=b_sum[i-1]+Bs[i]

a_sum=0
j=M-1
ans=0
for i in range(N):
    a_sum += As[i]
    if a_sum > K:
        break
    if j<0:
        if ans < i+1:
            ans = i+1
            continue
    # a_sum < K, K-a_sum>0
    # b_sum <= K-a_sum <-> a_sum + b_sum <= K
    # b_sum > K-a_sum <-> a_sum + b_sum > K
    while b_sum[j] > K - a_sum:
        j-=1
        if j < 0:
            j=-1
            break
    if ans < (i+1)+(j+1):
        ans = (i+1)+(j+1)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import numpy as np
N, M, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

cumsum_A = A.cumsum()
cumsum_B = B.cumsum()
# print('cusmum_A', cumsum_A)
# print('cusmum_B', cumsum_B)

ans = 0
for num_A, t in enumerate(cumsum_A, start=1):
    if t > K:
        continue
    if t == K:
        ans = max(ans, num_A)
    num_B = bisect_left(cumsum_B, K - t)
    # print('K - t, num_B, num_A + num_B', K - t, num_B, num_A + num_B)
    ans = max(ans, num_A + num_B)

for num_B, t in enumerate(cumsum_B, start=1):
    if t <= K:
        ans = max(ans, num_B)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import numpy as np
N, M, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

cumsum_A = A.cumsum()
cumsum_B = B.cumsum()
# print('cusmum_A', cumsum_A)
# print('cusmum_B', cumsum_B)

ans = 0
for num_A, t in enumerate(cumsum_A, start=1):
    if t > K:
        continue
    num_B = bisect_left(cumsum_B, K - t)
    # print('K - t, num_B, num_A + num_B', K - t, num_B, num_A + num_B)
    ans = max(ans, num_A + num_B)

for num_B, t in enumerate(cumsum_B, start=1):
    if t <= K:
        ans = max(ans, num_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
for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B

for k in range(N+1):
    if AA[k] <= K:
        if ans-k+1 >=0:
            for j in range(ans-k+1, M+1):
                if K >= AA[k] + BB[j]:
                    ans = max(k+j, ans)
                    break
                else:
                    continue
        if K >= AA[k] + BB[M]:
            ans = max(k+M, ans)
    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()))

cnt = 0
while K >= 0:
    if len(a)==0 or len(b)==0:
        if len(a)==0 and len(b)==0:
            cnt += 1
            break
        elif len(a) == 0:
            K -= b.pop(0)
        elif len(b) == 0:
            K -= a.pop(0)
    else:
        if a[0] >= b[0]:
            K -= b.pop(0)
        else:
            K -= a.pop(0)
    cnt += 1
print(cnt - 1)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os
import bisect

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n, m, k = map(int, input().split())
    a_s = list(map(int, input().split()))
    b_s = list(map(int, input().split()))

    # 1次元リストの累積和を求める(漸化式風)
    sum_a_s = [a_s[0]] + [a_s[i - 1] + a_s[i] for i in range(1, len(a_s[1:]) + 1)]
    sum_b_s = [b_s[0]] + [b_s[i - 1] + b_s[i] for i in range(1, len(b_s[1:]) + 1)]

    max_a = bisect.bisect_left(sum_a_s, k)

    if max_a == 0:
        print(bisect.bisect_left(sum_b_s, k))
        return

    remain_time = k - sum_a_s[max_a - 1]
    ans = max_a + bisect.bisect_left(sum_b_s, remain_time)
    for i in range(1, max_a + 1):
        remain_time += a_s[max_a - 1]
        ans = max(ans, bisect.bisect_left(sum_b_s, remain_time) + max_a- i)

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3 4 240
60 90 120
80 150 80 150"""
        output = """3"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 4 730
60 90 120
80 150 80 150"""
        output = """7"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000"""
        output = """0"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_input_1(self):
        test_input = """2 3 100
90 10
10 10 10"""
        output = """3"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0
j=M
for i in range(N):
    if sumA[i]>K:
        break
    j-=1
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    if i==0:
        best=j
    ans=max(ans,i+j+2)
    j=best+1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=list(accumulate(A))
b=list(accumulate(B))
diff=2*10**9
count=0
for i in range(N):
    j=bisect.bisect_right(b,K-a[i])-1
    if 0<=K-(a[i]+b[j])<=diff:
        diff=K-(a[i]+b[j])
        count=max(count,(i+1)+(j+1))
print(count)