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),*A,=[list(map(int,i.split())) for i in open(0)]
a=A[0]
b=A[1]

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

ans=0

for i in range(1,n+1):
    if aa[i]>k:
        break
    while bb[m]>k-aa[i]:
        m-=1
    ans=max(ans,m+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()))
tt = 0
a = 0
if (K >= (sum(A)+sum(B))):
    print(N+M)
elif (A[0]>K)and(B[0]>K):

    print(0)
else:
    Bmax = 0
    j = 0
    while (Bmax <= K):
        Bmax += B[j]
        j += 1
        if j ==M:
            break
    a = j
    best = j
    for i in range (N):
        if A[i]>K:
            break
        tt += A[i]
        max = K - tt
        m = 0
        Bm = Bmax
        while (Bm > max):
            Bm -= B[j-1 - m]
            if m==j:
                break
            m += 1
            
        b = i+1+j-m
        if b > a:
            a = b
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = [int(x) for x in input().split()]
A = [float(x) for x in input().split()]
B = [float(x) for x in input().split()]
 
AB = list()
a = 0
b = 0
for i in range(N+M):
  if ((a < N) and (b < M)):
    if(A[a] == B[b]):
      AB.append(A[a])
      a += 1
      AB.append(B[b])
      b += 1
    elif(A[a] < B[b]):
      AB.append(A[a])
      a += 1
    else:
      AB.append(B[b])
      b += 1
  elif(a == N):
    for j in range(M-b):
      AB.append(B[b])
      b += 1
    break
  elif(b == M):
    for j in range(N-a):
      AB.append(A[a])
      a += 1
    break
    
ans = 0
K = float(K)
while K > 0:
  K -= AB[ans]
  ans += 1
  if((ans == (N+M))and(K >= 0)):
    print(N+M)
    sys.exit()
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
import itertools as it
input = sys.stdin.readline

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

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    j = M
    while j > 0 and j > max - i:
        b = BS[j]
        if a + b <= K:
            if max < i + j:
                max = i + j
            break
        j -= 1

print(max)

Submission status: Wrong Answer

Solution code:
(n,m,k),*A,=[list(map(int,i.split())) for i in open(0)]
a=A[0]
b=A[1]

aa=[0]
bb=[0]
for i in range(n):
    aa.append(aa[-1]+a[i])
for i in range(m):
    bb.append(bb[-1]+b[i])

ans=0

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

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = [int(x) for x in input().split()]
A = [float(x) for x in input().split()]
B = [float(x) for x in input().split()]
 
AB = list()
a = 0
b = 0
for i in range(N+M):
  if ((a < N) and (b < M)):
    if(A[a] == B[b]):
      AB.append(A[a])
      a += 1
      AB.append(B[b])
      b += 1
    elif(A[a] < B[b]):
      AB.append(A[a])
      a += 1
    else:
      AB.append(B[b])
      b += 1
  elif(a == N):
    for j in range(M-b):
      AB.append(B[b])
      b += 1
    break
  elif(b == M):
    for j in range(N-a):
      AB.append(A[a])
      a += 1
    break
    
ans = 0
K = float(K)
while K > 0:
  K -= AB[ans]
  ans += 1
  if((ans == (N+M))and(K == 0)):
    print(N+M)
    sys.exit()
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
'''
Created on 2020/06/27

@author: harurun
'''
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
s=0
num=0
x=0
y=0
for i in range(N+M):
    if K<s:
        num -=1
        break
    if x<N and y<M:
        if A[x]>B[y]:
            s += B[y]
            num+=1
            y += 1
        else:
            s += A[x]
            num +=1
            x += 1
    elif x>=N and y<M:
        s+=B[y]
        num +=1
        y +=1
    elif y>=M and x <N:
        s+=A[x]
        num +=1
        x +=1
    else:
        break
print(num)

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=0
    while K>=sumA[i]+sumB[j]:
        ans=max(ans,i+j+2)
        if j==M-1:
            break
        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()))
c=0
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  if M!=0:
    for j in reversed(range(M)):
      if K-A[i]>=B[j]:
        if c<i+j+2:
          c=i+j+2
        M=j+1
        break
  elif K-A[i]>=0 and c<i+1:
    c=i+1
    M=0
print(c)

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()))
ac = [0]
bc = [0]
for _a in a:
    ac.append(ac[-1] + _a)
for _b in b:
    bc.append(ac[-1] + _b)

ans = 0

if k < ac[1] and k < bc[1]:
    print(0)
    exit()

for i in range(n):
    if k < ac[i]:
        break
    time = k - ac[i]
    j = bisect_right(bc, time)
    # print(time)
    # print(i)
    # print(j)
    # print("--------")
    ans = max(ans, j + i)

print(ans)

Submission status: Wrong Answer

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

nss = [0]
for i, v in enumerate(ns): nss.append(nss[i] + ns[i])
mss = [0]
for i, v in enumerate(ms): mss.append(mss[i] + ms[i])

from bisect import bisect_left

mx = 0
for i in range(n + 1):
    if nss[i] > k:
        break

    v = k - nss[i]
    j = bisect_left(mss, v)
    #print(i, nss, j, mss, k)
    if j < m and mss[j] != v:
        j -= 1

    mx = max(mx, i + j)

print(mx)

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

atime = 0

maxcnt = 0

times = []

for ai in range(n):
    atime += a[ai]
    if atime == k:
        times.append(atime)
        maxcnt = ai + 1
        break
    elif atime > k:
        maxcnt = ai
        break
    else:
        times.append(atime)

acnt = 0
for time in times:
    tmpmaxcnt = 0
    acnt += 1
    btime = 0
    for bi in range(m):
        btime += b[bi]
        
        if time + btime == k:
            tmpmaxcnt = acnt + bi + 1
            if tmpmaxcnt > maxcnt:
                maxcnt = tmpmaxcnt
            break
        elif time + btime > k:
            tmpmaxcnt = acnt + bi
            if tmpmaxcnt > maxcnt:
                maxcnt = tmpmaxcnt
            break
    
print(maxcnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
tmpA = list(map(int,input().split()))
tmpB = list(map(int,input().split()))
A = [tmpA[0]] if tmpA[0] < k else []
B = [tmpB[0]] if tmpB[0] < k else []
# 読むのにかかる時間の累計和のリスト
if A:
    for i in range(1, n):
        tmp = A[i-1] + tmpA[i]
        if tmp > k:
            break
        else:
            A.append(tmp)
if B:
    for i in range(1, m):
        tmp = B[i-1] + tmpB[i]
        if tmp > k:
            break
        else:
            B.append(tmp)
a = len(A)
b = len(B)
if a == 0:
    print(b)
elif b == 0:
    print(a)
else:
    while True:
        if a == 0 or b == 0 or A[-1] + B[-1] <= k:
            break
        if A[-1] > B[-1]:
            A.pop()
            a -= 1
        elif A[-1] == B[-1]:
            if a > b:
                A.pop()
                a -= 1
            else:
                B.pop()
                b -= 1
        else:
            B.pop()
            b -= 1
    print(a + b)

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_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])
    
ans = 0  
for i in range(n+1):
  rest = k-A_cum[i]
  if rest<=0:
    continue
  
  ans = max(ans, bisect.bisect_right(B_cum, rest)-1+i)
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = [int(n) for n in input().split()]
A = deque([int(n) for n in input().split()])
B = deque([int(n) for n in input().split()])

t = 0
for i in range(n+m+1):
    if not B and A or A and B and A[0] < B[0]:
        t += A.popleft()
    elif B:
        t += B.popleft()
    else:
        break
    if t > k:
        break
print(i)

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

aa = [0]
bb = [0]

for i in range(n):
    aa.append(a[i] + aa[i])

for i in range(m):
    bb.append(b[i] + bb[i])

ans = 0
flag = 0
mstart = 0
for i in range(n+1):
    if k - aa[i] < 0:
        flag = 1
        break
    for j in range(mstart,m+1):
        if k - aa[i] - bb[j] < 0:
            flag = 1
            mstart = j-1
            break
    if ans < i + j - 1:
        ans = i + j - 1


if flag == 0:
    print(i+j)
    exit()
print(ans)

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

A2 = [0] * (N + 1)
for i in range(1, N + 1):
  A2[i] = A2[i - 1] + A[i - 1]

B2 = [0] * (M + 1)
for i in range(1, M + 1):
  B2[i] = B2[i - 1] + B[i - 1]

#print(A2, B2)
#print(bisect.bisect_left(B2, 300))
ans = 0
for i in range(N + 1):
  time = K - A2[i]
  if time < 0:
    print(ans)
    quit()
  else:
    index = bisect.bisect_left(B2, time) - 1
    #print(index, time, B2)
    ans = max(ans, i + index)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
bka=[0]*N
bkb=[0]*M
bka[0]=A[0]
bkb[0]=B[0]

for i in range(1,N):
    bka[i]+=bka[i-1]+A[i]
for j in range(1,M):
    bkb[j]+=bkb[j-1]+B[j]
ans=bisect.bisect_left(bka,K)
for i in range(N):
    count=i+1
    k=K-bka[i]
    if k<0:continue
    c = bisect.bisect_left(bkb,k)
    if c!=M:
        if bkb[c]==k:
            c+=count+1
        else:c+=count
    else:c+=count

    # print(bkb,k,c,count)
    ans=max(ans,c)
print(ans)

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

rui_A = [0 for _ in range(N)]
rui_B = [0 for _ in range(M)]



rui_A[0] = A[0]
for i in range(N-1):
    rui_A[i+1] = rui_A[i] + A[i]

rui_B[0] = B[0]
for i in range(M-1):
    rui_B[i+1] = rui_B[i] + B[i]

rui_A.insert(0,0)

max_book = 0
for i in range(len(rui_A)):
    nokori = K - rui_A[i]
    if nokori >= 0:
        B_posi = bisect.bisect_right(rui_B,nokori)
        if max_book < B_posi + i:
            max_book = B_posi + i
print(max_book)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [10**10] + list(map(int, input().split()))[::-1]
B = [10**10] + list(map(int, input().split()))[::-1]

t = K
cnt = 0
while True:
    if t >= A[-1] and A[-1] <= B[-1]:
        t -= A.pop()
        cnt += 1
    elif t >= B[-1] and B[-1] <= A[-1]:
        t -= B.pop()
        cnt += 1
    else:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

def solve():
   n, m, k = map(int, input().split())
   a = cumsum(list(map(int, input().split())))
   b = cumsum(list(map(int, input().split())))

   ans = 0
   for a_num, v in enumerate(a):
      tmp = 0
      if k >= v:
         b_num = bisect.bisect_right(b, k - v) - 1
         tmp = a_num + b_num
      ans = max(ans, tmp)
   print(ans)

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

   # bの累積和
   b_sums = cumsum(b)
   ans = 0
   a = [0] + a

   j = len(b_sums) - 1
   a_sum = 0
   for i, v in enumerate(a):
      a_sum += v
      if not 0 <= j <= len(b_sums) - 1:
         ans = max(ans, i + j)
         continue
      while a_sum + b_sums[j] > k:
         j -= 1
         if j < 0:
            break
      ans = max(ans, i + j)
   print(ans)


solve2()

Submission status: Wrong Answer

Solution code:
#n = int(input())
n,m,k = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
time = 0
i = j = 0
while (time<=k and i<n and j<m):
      if (a[i]>b[j]):
            time += a[i]
            i+=1
      else:
            time += b[j]
            j+=1
while (i<n and time<=k):
      time += a[i]
      i+=1
while (j<n and time<=k):
      time += a[j]
      j+=1
print(i+j)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
tmpA = list(map(int,input().split()))
tmpB = list(map(int,input().split()))
A = [tmpA[0]] if tmpA[0] < k else []
B = [tmpB[0]] if tmpB[0] < k else []
# 読むのにかかる時間の累計和のリスト
if A:
    for i in range(1, n):
        tmp = A[i-1] + tmpA[i]
        if tmp > k:
            break
        else:
            A.append(tmp)
if B:
    for i in range(1, m):
        tmp = B[i-1] + tmpB[i]
        if tmp > k:
            break
        else:
            B.append(tmp)

if A == []:
    print(len(B))
elif B == []:
    print(len(B))
else:
    a = len(A)
    b = len(B)
    while True:
        if a == 0 or b == 0 or A[-1] + B[-1] <= k:
            break
        if A[-1] > B[-1]:
            A.pop()
            a -= 1
        elif A[-1] == B[-1]:
            if a > b:
                A.pop()
                a -= 1
            else:
                B.pop()
                b -= 1
        else:
            B.pop()
            b -= 1
    print(a + b)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

N, M, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = [0]*(M+1)
i = 0
while i < M:
  R_B[i+1] = R_B[i]+B[i]
  i += 1 
ans = 0
i = 0
while i < N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx-1)
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
Asum = [0]*(n+1)
Bsum = [0]*(m+1)

a_s = 0
for i in range(1,n+1):
    a_s += A[i-1]
    Asum[i] = a_s
b_s = 0
for i in range(1,m+1):
    b_s += B[i-1]
    Bsum[i] = b_s

t = 0
a_i=0
b_i=0
cnt = 0
while(t < k):
    
    if(a_i==(n+1) and b_i==(m+1)):
        break
    if(a_i==0 and b_i==0):
        if(Asum[a_i+1]<Bsum[b_i+1]):
            a_i += 1
        else:
            b_i += 1
    
    if(b_i==m):
        t = Asum[a_i] + Bsum[m]
        if(t > k):
            break
        a_i += 1
        cnt += 1    
        continue
    if(a_i==n):
        t = Asum[n] + Bsum[b_i]
        if(t > k):
            break
        b_i += 1
        cnt += 1 
        continue
    if(Asum[a_i]>Bsum[b_i]):
        
        t = Asum[a_i] + Bsum[b_i]
        
        if(t > k):
            break
        b_i += 1
        cnt += 1
    else:
        t = Asum[a_i] + Bsum[b_i]
        
        if(t > k):
            break
        a_i += 1
        cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  for j in reversed(range(M)):
    if K-A[i]>=B[j]:
      if c<i+j+2:
        c=i+j+2
      break
  if K-A[i]>=0 and c<i+1:
    c=i+1
print(c)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
time = 0
cnt = 0
idx_a = 0
idx_b = 0
for a in A:
    if time + a > K:
        idx_a = cnt-1
        break
    else:
        time += a
        cnt += 1
for b in B:
    if time + b > K:
        idx_b = cnt-N
        break
    else:
        time += b
        cnt += 1
minus_A = A[0:idx_a:][::-1]
add_B = B[idx_b:]
hist = []
ans = cnt
for a in minus_A:
    time -= a
    cnt -= 1
    for b in add_B:
        if time + b > K:
            ans = max(ans,cnt)
            break
        else:
            time += b
            cnt += 1
print(ans)

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_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])
    
ans = 0  
for i in range(n+1):
  rest = k-A_cum[i]
  if rest<=0:
    continue
  ans = max(ans, bisect.bisect_left(B_cum, rest)+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()))
 
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:
from bisect import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = [0]*(M+1)
i = 0
while i < M:
  R_B[i+1] = R_B[i]+B[i]
  i += 1 
ans = 0
i = 0
while i < N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx)
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
bka=[0]*N
bkb=[0]*M
bka[0]=A[0]
bkb[0]=B[0]

for i in range(1,N):
    bka[i]+=bka[i-1]+A[i]
for j in range(1,M):
    bkb[j]+=bkb[j-1]+B[j]
ans=bisect.bisect_left(bka,K)
for i in range(N):
    count=i+1
    k=K-bka[i]
    if k<0:continue
    c = bisect.bisect_left(bkb,k)
    if c!=M:
        if bkb[c]==k:
            c+=count+1
    else:c+=count

    # print(bkb,k,c,count)
    ans=max(ans,c)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
# = int(input())
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
Atotal = [0]*N
Btotal = [0]*M

Atotal[0] = A[0]
Btotal[0] = B[0]
greatest = Atotal[0]+Btotal[0]
icount = 0
jcount = 0

for i in range(1,N):
    Atotal[i] = Atotal[i-1] + A[i]
for j in range(1,M):
    Btotal[j] = Btotal[j-1] + B[j]

Atotal.insert(0, 0)
Btotal.insert(0, 0)

for i in range(N+1):
    for j in range(M+1):
        if Atotal[i] + Btotal[j] <= K and Atotal[i] + Btotal[j] >= greatest:
            greatest = Atotal[i] + Btotal[j]
            icount = i
            jcount = j
        elif Atotal[i] + Btotal[j] > K:
            break

print(icount+jcount)

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

atime = 0

maxcnt = 0

times = []

for ai in range(n):
    atime += a[ai]
    if atime == k:
        times.append(atime)
        maxcnt = ai + 1
        break
    elif atime > k:
        maxcnt = ai
        break
    else:
        times.append(atime)

acnt = 0
for time in times:
    tmpmaxcnt = 0
    acnt += 1
    btime = 0
    for bi in range(m):
        btime += b[bi]
        
        if time + btime == k:
            tmpmaxcnt = acnt + bi + 1
            if tmpmaxcnt > maxcnt:
                maxcnt = tmpmaxcnt
            break
        elif time + btime > k:
            tmpmaxcnt = acnt + bi
            if tmpmaxcnt > maxcnt:
                maxcnt = tmpmaxcnt
            break
    
print(maxcnt)

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 bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A2 = [0] * (N + 1)
for i in range(1, N + 1):
  A2[i] = A2[i - 1] + A[i - 1]

B2 = [0] * (M + 1)
B2[0] = B[0]
for i in range(1, M + 1):
  B2[i] = B2[i - 1] + B[i - 1]

#print(A2, B2)
#print(bisect.bisect_left(B2, 300))
ans = 0
for i in range(N + 1):
  time = K - A2[i]
  if time < 0:
    print(ans)
    quit()
  else:
    index = bisect.bisect_left(B2, time)
    #print(index, time)
    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()))
ans = 0
tmp = 0

for j in range(m):
    tmp = tmp + b[j]
    if tmp <= k:
        ans = j + 1


for i in range(n):
    tmp = sum(a[:i+1])
    #print(suma)
    for j in range(m):
        tmp = tmp + b[j]
        #print(tmp,i,j)
        if tmp <= k:
            if ans < i + j + 2:
                ans = i + j + 2
        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_right

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

ac = np.cumsum(a)
bc = np.cumsum(b)
ans = 0

if k < ac[0]:
    print(bisect_right(bc, k))
    exit()

for i in range(n):
    if k < ac[i]:
        break
    time = k - ac[i]
    j = bisect_right(bc, time)
    ans = max(ans, j + i + 1)

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

asum = [0]
bsum = [0]

for i in range(n):
    asum.append(asum[i] + a[i])
for i in range(m):
    bsum.append(bsum[i] + b[i])

best = m
answer = 0
for i in range(n+1):
    check = 0
    j = best
    while 1:
        if bsum[j] <= (k - asum[i]):
            best = j
            answer = i + j
            break
        j -= 1
        if j < 0:
            break

print(answer)

Submission status: Wrong Answer

Solution code:
import bisect


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

    ans = 0
    A_d = [0]
    B_d = [0]
    for a in A:
        if A_d[-1] + a > K:
            break
        A_d.append(A_d[-1]+a)
    tmp = 0
    for b in B:
        if B_d[-1] + b > K:
            break
        B_d.append(B_d[-1]+b)

    ans = 0
    for i in range(1, len(A_d)):
        tmp = K - A_d[-1*i]
        pos = bisect.bisect_left(B_d, tmp+1) - 1
        pos += len(A_d) - i
        if pos > ans:
            ans = pos
    print(ans)


if __name__ == "__main__":
    main()

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_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])
    
ans = 0  
for i in range(n):
  rest = k-A_cum[i]
  if rest<=0:
    continue
  ans = max(ans, bisect.bisect_left(B_cum, rest)+i)
  
print(ans)

Submission status: Wrong Answer

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

total_A_minutes = sum(A_minutes)
total_B_minutes = sum(B_minutes)

# すべて読める場合
if total_A_minutes + total_B_minutes <= K:
    print(N + M)
    exit()

# 冊数
ans = 0
# Kを超える最小のi
limitover_A_index = 0
# Aの合計が超えた場合
if total_A_minutes > K:
    tmp_total_A_minutes = 0
    for i in range(N):
        tmp_total_A_minutes = tmp_total_A_minutes + A_minutes[i]
        if tmp_total_A_minutes > K:
            limitover_A_index = i
            # Kを超過したindex が Kを超過しない冊数となる
            ans = i
            break
# Aの合計が超えない場合
else:
    limitover_A_index = N
    ans = N

best_b_index = 0
while limitover_A_index >= 0:
    tmp_total_minute = sum(A_minutes[:limitover_A_index])
    # tmp_ans = limitover_A_index
    tmp_ans = limitover_A_index + best_b_index

    # Bを1冊ずつ確認
    # for B_minute in B_minutes:
    for i in range(best_b_index, M):
        # Bの冊数を足したことでK分を超えるなら
        if tmp_total_minute + sum(B_minutes[:i]) > K:
            best_b_index = i - 1
            break

        #tmp_total_minute = tmp_total_minute + B_minutes[i]
        tmp_ans = tmp_ans + 1

        # Bの最大冊数まで到達の場合
        if i == M - 1:
            print(limitover_A_index + M)
            exit()

    # 最大冊数の記録を超えたら更新する
    if ans < tmp_ans:
        ans = tmp_ans

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

L = [float("inf") for _ in range(N+M+1)]
L[0] = 0

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

Submission status: Wrong Answer

Solution code:
def Tsun(A,B,N,M,K):
  sumA = [0]*N
  sumB = [0]*M
  SAC = 0
  SBC = 0
  for i in range(N):
    if i == 0:
      sumA[i] = A[i]
    else:
      sumA[i] = sumA[i-1] + A[i]
    if sumA[i] <= K:
      SAC += 1
    else:
      break
  for i in range(M):
    if i == 0:
      sumB[i] = B[i]
    else:
      sumB[i] = sumB[i-1] + B[i]
    if sumB[i] <= K:
      SBC += 1
    else:
      break
  X = SAC
  for i in range(SAC):
    for j in range(SBC):
      if X <= i+j+2 and sumA[i] + sumB[j] <= K:
        X = i+j+2
  return X
  


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

print(Tsun(A,B,N,M,K))

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_right

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

ac = np.cumsum(a)
bc = np.cumsum(b)
ans = 0

for i in range(n):
    if k < ac[i]:
        break
    time = k - ac[i]
    j = bisect_right(bc, time)
    ans = max(ans, j + i + 1)
print(ans)

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_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])
    
ans = 0  
for i, a in enumerate(A_cum):
  rest = k-a
  if rest<=0:
    continue
  ans = max(ans, bisect.bisect_left(B_cum, rest)+i)
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

def solve():
   n, m, k = map(int, input().split())
   a = cumsum(list(map(int, input().split())))
   b = cumsum(list(map(int, input().split())))

   ans = 0
   for a_num, v in enumerate(a):
      tmp = 0
      if k >= v:
         b_num = bisect.bisect_right(b, k - v) - 1
         tmp = a_num + b_num
      ans = max(ans, tmp)
   print(ans)

def solve2():
   n, m, k = map(int, input().split())
   a = list(map(int, input().split()))
   b = list(map(int, input().split()))
   sum_b = sum(b)

   ans = 0
   j = m-1
   while k < sum_b:
      if j < 0:
         break
      sum_b -= b[j]
      j -= 1
   ans = j + 1
   sum_a = 0

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


solve2()

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
tmp = 0

for j in range(m):
    tmp = tmp + b[j]
    if tmp <= k:
        ans = j + 1


for i in range(n):
    tmp = sum(a[:i+1])
    #print(suma)
    for j in range(m):
        tmp = tmp + b[j]
        #print(tmp,i,j)
        if tmp <= k:
            if ans < i + j + 2:
                ans = i + j + 2

print(ans)