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

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):
      #print(i,j,time)
      if (a[i]<b[j]):
            if (time+a[i]<=k):
                  time += a[i]
                  i+=1
            else:
                  break
      else:
            if (time+b[j]<=k):
                  time += b[j]
                  j+=1
            else:
                  break
while (i<n and time<=k):
      #print(i,j,time)
      if (time+a[i]<=k):
                  time += a[i]
                  i+=1
      else:
            break
while (j<m and time<=k):
      if (time+b[j]<=k):
                  time += b[j]
                  j+=1
      else:
            break
      #print(i,j,time)
print(i+j)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
e=1
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:
    if c<i+1:
      c=i+1
  elif d<0:
    break
  for j in reversed(range(M)):
    if d>=B[j]:
      if c<i+j+2:
        c=i+j+2
      M=j+1
      e=0
      break
  if e==1:
    M=0
print(c)

Submission status: Wrong Answer

Solution code:

from collections import deque


def hash(a, b, n, c):
    return "".join(map(str, a+b))+str(n)+str(c)


def f(q, k, hash_table):
    a, b, n, c = q.popleft()
    n += 1

    if len(a) != 0:
        c1 = c + a[-1]
        item_1 = (a[:-1], b, n, c1)
        hash_1 = hash(*item_1)

        if (hash_1 not in hash_table) and (c1 <= k):
            hash_table.append(hash_1)
            q.append(item_1)

    if len(b) != 0:
        c2 = c + b[-1]
        item_2 = (a, b[:-1], n, c2)
        hash_2 = hash(*item_2)

        if (hash_2 not in hash_table) and (c2 <= k):
            hash_table.append(hash_2)
            q.append(item_2)

    if len(q) == 0:
        return 0
    if (len(a) == 0 and len(b) == 0) or len(q) == 1:
        _, _, n, _ = q.popleft()
        return n
    else:
        return f(q, k, hash_table)


if __name__ == "__main__":
    n, m, k = map(int, input().split(" "))
    a = list(map(int, input().split(" ")))[::-1]
    b = list(map(int, input().split(" ")))[::-1]
    q = deque()
    q.append((a, b, 0, 0))

    n = f(q, k, [])
    print(n)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K = map(int, input().split())
a = np.array(list(map(int, input().split())),dtype=np.int64)
b = np.array(list(map(int, input().split())),dtype=np.int64)

asum = a.cumsum()
bsum = b.cumsum()

ans = 0
for ind,i in enumerate(asum):
    mx = np.searchsorted(bsum, K-i ,side='right')
    if mx == 0:
        continue
    ans = max(ans, ind+1 + mx,)
    #print(mx, ans)

print(ans)

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
    # 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:
            break
    if ans < (i+1)+(j+1):
        ans = (i+1)+(j+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()))
ans = 0
A_cumulative_sum = [A[0]]
B_cumulative_sum = [B[0]]
for i in range(1, N):
    A_cumulative_sum.append(A[i] + A_cumulative_sum[i - 1])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1])

for i in range(N):
    if K <= A_cumulative_sum[i]:
        remaining_time = K
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, idx)
        break
    else:
        remaining_time = K - A_cumulative_sum[i]
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, i + 1 + idx)
print(ans)

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:
            tmp = j
            break
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

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

from collections import deque

an = list(map(int, input().split()))

bn = list(map(int, input().split()))

accum_a = [0]
accum_b = [0]

for a_i in range(0, len(an)):
    a_i = accum_a[-1] + an[a_i]
    if a_i > k:
        break
    accum_a.append(a_i)

for b_i in range(0, len(bn)):
    i_ = accum_b[-1] + bn[b_i]
    if i_ > k:
        break
    accum_b.append(i_)

ans = 0
for a_i in range(len(accum_a)):

    sumCandidate = accum_a[a_i]
    rest = k - sumCandidate

    j = (len(accum_b)) // 2
    finalBIndex = j
    while True:
        if j == 0:
            finalBIndex = j
            break
        if j == len(accum_b) - 1:
            finalBIndex = j
            break
        elif accum_b[j] <= rest < accum_b[max(0, j + 1)]:
            finalBIndex = j
            break
        elif accum_b[j] > rest:
            j = j // 2
        else:
            j = (len(accum_b) - j) // 2 + j

    ans = max(ans, a_i  + finalBIndex)

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

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0]*N
b=[0]*M
a[0]=A[0]
b[0]=B[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i+1]
for i in range(M-1):
    b[i+1]=b[i]+B[i+1]
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)

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()))
 
a = sum(As)
b = sum(Bs)

t = 0
tmp = 0
rlt = 0

if a+b <= K:
  print(N+M)
  exit()

i = -1
j = -1
t = 0
while t <= K and i+1 < N:
  i += 1
  t += As[i]
if t > K:
  t -= As[i]
  i -= 1
while t <= K:
  j += 1
  t += Bs[j]
t -= Bs[j]
j -= 1
  
tmp = i + j + 2
rlt = tmp

if tmp == 0:
  print(tmp)
  exit()

while i > -1:
  t -= As[i]
  i -= 1
  while t <= K and j+1 < M:
    j += 1
    t += Bs[j]
  if t > K:
    t -= Bs[j]
    j -= 1
    tmp = i + j + 2
    rlt = max(tmp, rlt)
  elif j == N:
    tmp = i + j + 1
    rlt = max(tmp, rlt)
    break
  
print(rlt)

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 M!=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>=0:
    if c<i+1:
      c=i+1
      M=0
  elif d<0:
    break
print(c)

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:
            tmp = j
            ans = max(ans, i + j)
            break
print(ans)

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

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(a)
# print(b)


ans = 0

for i_n in range(n + 1):
    if a[i_n] > k:
        break

    for j_n in range(m + 1):
        if a[i_n] + b[j_n] < k:
            ans = max(ans, i_n + j_n)

print(ans)

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):
    for j in range(tmp, 0, -1):
        if SA[i] + SB[j] <= k:
            tmp = j
            ans = max(ans, i + j)
            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()))

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

from collections import deque

an = list(map(int, input().split()))

bn = list(map(int, input().split()))

accum_a = [0]
accum_b = [0]


for b_i in range(0,len(bn)):
    i_ = accum_b[-1] + bn[b_i]
    if i_ > k:
        break
    accum_b.append(i_)

ans = 0
for a_i in range(len(an)):

    sumCandidate = accum_a[-1] + an[a_i]
    if sumCandidate > k:
        break
    accum_a.append(sumCandidate)

    rest = k - sumCandidate

    j = (len(accum_b)) // 2
    finalBIndex = j
    while True:
        if j == 0:
            finalBIndex = j
            break
        if j == len(accum_b) - 1:
            finalBIndex = j
            break
        elif accum_b[j] <= rest < accum_b[max(0, j - 1)]:
            finalBIndex = j
            break
        elif accum_b[j] > rest:
            j = j // 2
        else:
            j = (len(accum_b) - j) // 2 + j

    ans = max(ans, a_i+1+finalBIndex)

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 True:
  K -= AB[ans]
  if(K == 0):
    print(ans+1)
    sys.exit()
  elif(K < 0):
    print(ans)
    sys.exit()
  elif(ans+1 == (N+M)):
    print(N+M)
    sys.exit()
  ans += 1
  
print(ans)
print(ans-1)

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()))
n -= -1
m -= -1
a.insert(0, 0)
b.insert(0, 0)
for i in range(1, n): a[i] += a[i - 1]
for i in range(1, m): b[i] += b[i - 1]
ans = 0
for i in range(n):
    lo, hi = 0, m - 1
    tmp = a[i]
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        if tmp + b[mid] > k: hi = mid - 1
        else: lo = mid
    if tmp + b[hi] <= k: lo = hi
    ans = max(ans, i + lo)
print(ans)

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:
            break
    tmp = j
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    N, M, K = LI()
    A = LI()
    B = LI()

    a = [0]+list(accumulate(A))
    b = [0]+list(accumulate(B))

    ans = 0

    for i in range(N + 1):
        if a[i] > K:
            continue
        rest = K - a[i]
        j = bisect.bisect_left(b, rest)
        ans = max(ans, i + j - 1)

    print(ans)

main()

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 i in range(len(A)):
    t = cumsum_A[i]
    if t > K:
        continue
    if t == K:
        ans = max(ans, i + 1)
        continue
    idx = bisect_left(cumsum_B, K - t)
    # print('K - t, idx, i + idx', K - t, idx, i + 1 + idx)
    ans = max(ans, i + 1 + idx)
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 i in range(len(A)):
    t = cumsum_A[i]
    if t > K:
        continue
    # if t == K:
    #     ans = max(ans, i + 1)
    #     continue
    idx = bisect_left(cumsum_B, K - t)
    # print('K - t, idx, i + idx', K - t, idx, i + 1 + idx)
    ans = max(ans, i + 1 + idx)
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 = deque([0])
b_sum = deque([0])
atmp = 0
btmp = 0

for i in a:
    atmp += i
    a_sum.append(atmp)

for i in b:
    btmp += i
    b_sum.append(btmp)


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

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()))
a=0
b=0
t=0
ans=0
while t<K:
  if a<len(A) and b<len(B):
    if A[a]>B[b]:
      ans+=1
      t+=A[a]
      a+=1
    else:
      ans+=1
      t+=B[b]
      b+=1
  elif a>=len(A) and b<len(B):
    ans+=1
    t+=B[b]
    b+=1
  elif a<len(A) and b>=len(B):
    ans+=1
    t+=A[a]
    a+=1
  else:
    print(ans)
    exit()
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):
  d=K-A[i]
  if M!=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>=0 and c<i+1:
    c=i+1
    M=0
  elif d<0:
    break
print(c)

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

    ans = max_a + bisect.bisect_left(sum_b_s, k - max(sum_a_s))
    for i in range(1, max_a + 1):
        get_time = k - sum_a_s[max_a - i]
        ans = max(ans, bisect.bisect_left(sum_b_s, get_time) - 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 tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        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:
n, m, k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int, input().split()))
 
ans_list = []
ans_list.append(0)

sum_a = 0
for i in range(len(a)):
  sum_a += a[i]
  if sum_a > k:
    break
  if sum_a == k:
    ans_list.append(i+1)
    break
  start = max(ans_list)-i
  sum_b = sum(b[0:start])
  for j in range(start,len(b)):
    sum_b += b[j]
    if (sum_a + sum_b) < k:
      ans_list.append(i+1+j)
    if (sum_a + sum_b) > k:
      ans_list.append(i+1+j-1)
      break
    if (sum_a + sum_b) == k:
      ans_list.append(i+1+j+1)
      break
      
sum_b = 0
for i in range(len(b)):
  sum_b += b[i]
  sum_a = 0
  if sum_b > k:
    break
  if sum_b == k:
    ans_list.append(i+1)
    break
  start = max(ans_list)-i
  sum_a = sum(a[0:start])
  for j in range(start,len(a)):
    sum_a += a[j]   
    if (sum_a + sum_b) < k:
      ans_list.append(i+1+j)
    if (sum_a + sum_b) > k:
      ans_list.append(i+1+j-1)
      break
    if (sum_a + sum_b) == k:
      ans_list.append(i+1+j+1)
      break
      
print(max(ans_list))

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

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
    while b_sum[j] > K - a_sum:
        j-=1
        if j < 0:
            break
    if ans < (i+1)+(j+1):
        ans = (i+1)+(j+1)
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])

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

    while mss[j] > k - nss[i]:
        j -= 1
    
    print(i, j)

    mx = max(mx, i + j)

print(mx)

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 True:
  K -= AB[ans]
  if(K <= 0):
    break
  ans += 1
  if((ans == (N+M))and(K >= 0)):
    print(N+M)
    sys.exit()
  
print(ans)

Submission status: Wrong Answer

Solution code:
# Problem C - Tsundoku

# input
N, M, K = map(int, input().split())
a_nums = list(map(int, input().split()))
b_nums = list(map(int, input().split()))

# initialization
max_count = 0
b_i = M
a_cums = [0]*N
b_cums = [0]*M
for i in range(N):
    if i>=1:
        a_cums[i] = a_cums[i-1] + a_nums[i]
    else:
        a_cums[i] = a_nums[i]
for i in range(M):
    if i>=1:
        b_cums[i] = b_cums[i-1] + b_nums[i]
    else:
        b_cums[i] = b_nums[i]

for i in range(N):
    if a_cums[i]<=K:
        while b_i!=0 and a_cums[i]+b_cums[b_i-1]>K:
            b_i -= 1
        if i+1+b_i>max_count:
            max_count = i+1+b_i

# output
print(max_count)

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:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    N, M, K = LI()
    A = LI()
    B = LI()

    a = [0]+list(accumulate(A))
    b = [0]+list(accumulate(B))

    ans = 0

    for i in range(N + 1):
        if a[i] > K:
            continue
        rest = K - a[i]
        p = bisect.bisect_left(b, rest)
        ans = max(ans, i + p)

    print(ans)
    
main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y=[0],[0]
for i in range(n):
    x.append(a[i]+x[i])
for j in range(m):
    y.append(b[j]+y[j])

ans=0
j=m
for i in range(n+1):
    if x[i]>k:
        break
    while y[j]>k-x[i]:
        j-=1
    ans=max
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):
  d=K-A[i]
  if M!=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>=0 and c<i+1:
    c=i+1
    M=0
print(c)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
from collections import deque
a= deque(map(int, input().split()))
b= deque(map(int, input().split()))
ans =0

while k >=0 and len(a) + len(b) >=1:
    if len(a)>0 and len(b)>0:
        if a[0] >= b[0]:
            k -= b.popleft()
            if k >= 0:
                ans += 1
        else:
            k -= a.popleft()
            if k >= 0:
                ans += 1
    elif len(a) == 0 and len(b) > 0:
        k -= b.popleft()
        if k >= 0:
            ans += 1
    elif len(b) == 0 and len(a) > 0:
        k -= a.popleft()
        if k >= 0:
            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()))

suba=[0]
subb=[0]

for i in range(n):
    suba.append(a[i]+suba[i])
for j in range(m):
    subb.append(b[j]+subb[j])

ans=0
j=m
for i in range(n+1):
    while True:
        #print(i,j)
        if k<suba[i]:
            break

        if subb[j]<=k-suba[i]:
            break
        j-=1
    ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def binary_search(l, r, pred):
    while l < r:
        mid = (l + r) // 2
        if pred(mid):
            r = mid
        else:
            l = mid + 1
    return l


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    ans = 0
    cA = [0] * (N + 1)
    cB = [0] * (M + 1)
    for i, a in enumerate(A):
        cA[i + 1] = cA[i] + a
    for i, b in enumerate(B):
        cB[i + 1] = cB[i] + b
    if cA[-1] + cB[-1] <= K:
        print(N + M)
        return
    def min_time(x):
        # x個選んだときの最小時間
        return min((cA[i] + cB[x - i] for i in range(N) if 0 <= x - i <= M))

    ans = binary_search(0, N + M, lambda x: min_time(x) > K) - 1
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)


if __name__ == "__main__":
    main()

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_s = [0]
    B_s = [0]
    for a in A:
        if A_s[-1] + a > K:
            break
        A_s.append(A_s[-1]+a)
    tmp = 0
    for b in B:
        if B_s[-1] + b > K:
            break
        B_s.append(B_s[-1]+b)

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


if __name__ == "__main__":
    main()