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 = 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])
 
num,x = 0,m
 
for i in range(len(a)-1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)

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

num,x = 0,m

for i in range(len(a)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)

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(len(a)):
  A.append(a[i] + A[i])
for i in range(len(b)):
  B.append(b[i] + B[i])

loop = False
num = 0
x = m 

for i in range(1,len(A)):
  while A[i] + B[x] > k and x > 0 and A[i] <= k:
    x -= 1
    loop = True
    
  if loop:
    num = max(num, i + x)


print(num)

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)

count=0
cal=0
while True:
  if K-count>=min(A[0],B[0]):
    count+=min(A[0],B[0])
    cal+=1
    if A[0]>=B[0]:
      del B[0]
    else:
      del A[0]
  else:
    break
print(cal)

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(len(a)):
  A.append(a[i] + A[i])
for i in range(len(b)):
  B.append(b[i] + B[i])

num = 0

for i in range(1,len(A)):
  for j in range(1,len(B)):
    if A[i] + B[j] <= k:
      num = max(num, i + j)
    else:
      break

print(num)

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(len(a)):
  A.append(a[i] + A[i])
for i in range(len(b)):
  B.append(b[i] + B[i])


if A[len(A) - 1] + B[len(B) - 1] <= k:
  print(len(A) - 1 + len(B) - 1)
  exit()

num = 0

for i in range(1,len(A)):
  for j in range(1,len(B)):
    if A[i] + B[j] < k:
      num = max(num, i + j)
    else:
      break

print(num)

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(len(a)):
  A.append(a[i] + A[i])
for i in range(len(b)):
  B.append(b[i] + B[i])


if A[len(A) - 1] + B[len(B) - 1] <= k:
  print(len(A) - 1 + len(B) - 1)
  exit()

num = 0

for i in range(1,len(A)):
  for j in range(1,len(B)):
    if A[i] + B[j] < k:
      num = max(num, i + j)

print(num)

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()))
sum = 0
count = 0

while sum + a[0] <= k or sum + b[0] <= k:
  if a[0] < b[0]:
    count += 1
    sum += a[0]
    a.pop(0)   
    if len(a) == 0:
      while sum + b[0] <= k:
        count += 1
        sum += b[0]
        b.pop(0)
        if len(b) == 0 or sum > k:
          print(count)
          exit()

  if b[0] < a[0]:
    count += 1
    sum += b[0]
    b.pop(0)
    if len(b) == 0:
      while sum + a[0] <= k:
        count += 1
        sum += a[0]
        a.pop(0)
        if len(b) == 0 or sum > k:
          print(count)
          exit()

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N, M, K = map(int, input().split())
A=[0]+list(accumulate(map(int,input().split())))
B=[0]+list(accumulate(map(int,input().split())))

Y_num = [0]*(N+1)

II = 0

for i in range(N+1):
    if A[i] <= K:
        Y_num[II] += i
        for j in range(M+1):
            if K - A[II] - B[j] < 0:
                Y_num[II] += j - 1
                break
            elif j == M:
                Y_num[II] += M
    else:
        break

print(max(Y_num))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left

ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0

pA = [0] + list(accumulate(A))
pB = [0] + list(accumulate(B))

ans = 0
for i, a in enumerate(pA):
    r = K - a
    if r > 0:
        j = bisect_left(pB, r)
        if j != len(pB):
            if pB[j] > r:
                j -= 1
            ans = max(ans, i + j)
    else:
        ans = max(ans, i if r > 0 else 0)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left

ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0

pA = [0] + list(accumulate(A))
pB = [0] + list(accumulate(B))

ans = 0
for i, a in enumerate(pA):
    r = K - a
    if r > 0:
        j = bisect_left(pB, r)
        if j != len(pB):
            if pB[j] > r:
                j -= 1
            ans = max(ans, i + j)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left

ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0

pA = [0] + list(accumulate(A))
pB = [0] + list(accumulate(B))

ans = 0
for i, a in enumerate(pA):
    r = K - a
    j = bisect_left(pB, r)
    if j != len(pB) and pB[j-1] <= r:
        j = j if pB[j] == r else j - 1
        ans = max(ans, i + j)

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
assert len(A) == N
assert len(B) == M
# K分以内に読む数の最大化
import numpy as np
cumA = np.cumsum([0] + A)
cumB = np.cumsum([0] + B)
maximum = 0
for maxA,timeA in enumerate(cumA):
  if timeA > K:
     break
  timeB = K - timeA
  maxB = np.sum(timeA + cumB <= K)
  maximum = max(maximum, maxA + maxB)
print(maximum)

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()))
assert len(A) == N
assert len(B) == M
# K分以内に読む数の最大化

cumA = []
cumB = []
sumA = 0
sumB = 0
for a in A:
  sumA += a
  cumA.append(sumA)
for b in B:
  sumB += b
  cumB.append(sumB)

maximum = 0
for maxA,timeA in enumerate([0]+cumA):
  if timeA > K:
     break
  timeB = K - timeA
  for maxB,timeB in enumerate([0]+cumB):
     if timeA + timeB > K:
        break
  else:
    maximum = max(maximum, maxA + maxB)
print(maximum)

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()))
assert len(A) == N
assert len(B) == M
# K分以内に読む数の最大化

cumA = []
cumB = []
sumA = 0
sumB = 0
for a in A:
  sumA += a
  cumA.append(sumA)
for b in B:
  sumB += b
  cumB.append(sumB)

maximum = 0
for maxA,timeA in enumerate([0]+cumA):
  timeB = K - timeA
  maxB = [i for i,b in enumerate(cumB) if b <= timeB]
  maxB = max(maxB) + 1 if len(maxB) else 0
  maximum = max(maximum, maxA + maxB)
print(maximum)

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()))
assert len(A) == N
assert len(B) == M
# K分以内に読む数の最大化

cumA = []
cumB = []
sumA = 0
sumB = 0
for a in A:
  sumA += a
  cumA.append(sumA)
for b in B:
  sumB += b
  cumB.append(sumB)

maximum = 0
for n in range(10, K+1, 10):
  timeA = n
  timeB = K - n
  maxA = [i for i,cum in enumerate(cumA) if cum <= timeA]
  maxB = [i for i,cum in enumerate(cumB) if cum <= timeB]
  maxA = (max(maxA) + 1) if len(maxA) else 0
  maxB = (max(maxB) + 1) if len(maxB) else 0
  maximum = max(maximum, maxA + maxB)
print(maximum)

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()))
assert len(A) == N
assert len(B) == M
# K分以内に読む数の最大化

cumA = []
cumB = []
sumA = 0
sumB = 0
for a in A:
  sumA += a
  cumA.append(sumA)
for b in B:
  sumB += b
  cumB.append(sumB)

maximum = 0
for n in range(10, K+1, 10):
  timeA = n
  timeB = K - n
  maxA = [i for i,cum in enumerate(cumA) if cum <= timeA]
  maxB = [i for i,cum in enumerate(cumB) if cum <= timeB]
  maxA = (max(maxA) + 1) if len(maxA) else 0
  maxB = (max(maxB) + 1) if len(maxB) else 0
  maximum = max(maximum, maxA + maxB)
print(maximum)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]

for i in range(len(aa)):
    asum.append(asum[i]+aa[i])
for i in range(len(bb)):
    bsum.append(bsum[i]+bb[i])

j = len(bsum)-1
ans = 0
for i in range(len(asum)):
    while j > 0:
        if k > asum[i] + bsum[j]:
            ans = max(ans, i+j)
            break
        else:
            j -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]

for i in range(len(aa)):
    asum.append(asum[i]+aa[i])
for i in range(len(bb)):
    bsum.append(bsum[i]+bb[i])

j = len(bsum)-1
ans = 0
for i in range(len(asum)):
    while j > 0:
        if k >= asum[i] + bsum[j]:
            ans = max(ans, i+j)
            break
        else:
            j -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque

# スペース区切りの整数の入力
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = deque(a)
B = deque(b)

time = 0
count = 0
inf = float('inf')

while time < K:
    if A:
        ta = A[0]
    else:
        ta = inf
    
    if B:
        tb = B[0]
    else:
        tb = inf
    
    if ta == inf and tb == inf:
        break
    
    if ta < tb:
        time += ta
        A.popleft()
    else:
        time += tb
        B.popleft()
    
    if time >K:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 18 19:19:52 2020

@author: ezwry
"""

n,m,k=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
ans=0
answer=[]

a=[];b=[]
a0=0;b0=0
for i in alist:
    a0+=i
    a.append(a0)

for j in blist:
    b0+=j
    b.append(b0)
    
for x in range(len(a)):
    ak=k-a[x]
    for y in range(len(b)):
        if ak-b[y]<=0:
            answer.append(ans)
        else:
            ans=x+y+2

print(max(answer))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 18 19:19:52 2020

@author: ezwry
"""

n,m,k=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
ans=0

while 1:
    if alist==[]:
        if blist==[]:
            break
        else:
            if blist[0]<=k:
                k-=blist[0]
                blist.pop(0)
                ans+=1
            else:
                break
    else:
        if blist==[]:
            if alist[0]<=k:
                k-=alist[0]
                alist.pop(0)
                ans+=1
            else:
                break
        else:
            if alist[0]<=blist[0]:
                k-=alist[0]
                alist.pop(0)
                ans+=1
            else:
                k-=blist[0]
                blist.pop(0)
                ans+=1

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#                               #
    # author : samars_diary #
    # 17-09-2020 │ 20:34:30 #
#                               #

import sys, os.path

if(os.path.exists('input.txt')):
    sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    n,m,k=mii();d=i=j=l=0
    a=lii();b=lii()
    while len(a)!=0 and len(b)!=0 and i!=-1:
        if a[0]<=b[0] and a[0]<=k:
            k-=a[0];a.remove(a[0]);d+=1
        elif a[0]>b[0] and b[0]<=k:
            k-=b[0];b.remove(b[0]);d+=1
        else:
            i=-1
    while len(b)==0 and len(a)!=0 and j!=-1:
        if a[0]<=k:
            k-=a[0];a.remove(a[0]);d+=1
        else:
            j=-1
            break
    while len(b)!=0 and len(a)==0 and l!=-1:
        if b[0]<=k:
            k-=b[0];b.remove(b[0]);d+=1
        else:
            l=-1
            break
    print(d)
for _ in range(1):
    solve()

Submission status: Wrong Answer

Solution code:
#                               #
    # author : samars_diary #
    # 17-09-2020 │ 20:34:30 #
#                               #

import sys, os.path

if(os.path.exists('input.txt')):
    sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    n,m,k=mii();d=i=j=l=0
    a=lii();b=lii()
    while len(a)!=0 and len(b)!=0 and i!=-1:
        if a[0]<=b[0] and a[0]<=k:
            k-=a[0];a.remove(a[0]);d+=1
        elif a[0]>b[0] and b[0]<=k:
            k-=b[0];b.remove(b[0]);d+=1
        else:
            i=-1
    while len(b)==0 and len(a)!=0 and j!=-1:
        while len(a)!=0:
            if a[0]<=k:
                k-=a[0];a.remove(a[0]);d+=1
            else:
                j=-1
                break
    while len(b)!=0 and len(a)==0 and l!=-1:
        while len(b)!=0:
            if b[0]<=k:
                k-=b[0];b.remove(b[0]);d+=1
            else:
                l=-1
                break
    print(d)
for _ in range(1):
    solve()

Submission status: Wrong Answer

Solution code:
#                               #
    # author : samars_diary #
    # 17-09-2020 │ 20:34:30 #
#                               #

import sys, os.path

#if(os.path.exists('input.txt')):
    #sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    n,m,k=mii();d=0
    a=lii();b=lii()
    c=sorted(a+b)
    for x in c:
        if x<=k:
            d+=1
            k-=x
        else:
            break
    print(d)
    

for _ in range(1):
    solve()

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

if N<M:
    for i in range(N,M+1):
        A.append(pow(10,10))
if N>M:
    for i in range(M,N+1):
        B.append(pow(10,10))
A.append(pow(10,10))
B.append(pow(10,10))
t=0
count=0
A_count=0
B_count=0
while t<=K:
    if A[A_count]<=B[B_count]:
        t+=A[A_count]
        A_count+=1
        count+=1
    else:
        t+=B[B_count]
        B_count+=1
        count+=1
print(count-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()))

if N<M:
    for i in range(N,M+1):
        A.append(pow(10,10))
if N>M:
    for i in range(M,N+1):
        B.append(pow(10,10))
A.append(pow(10,10))
B.append(pow(10,10))
t=0
count=0
A_count=0
B_count=0
while t<=K:
    if A[A_count]<=B[B_count]:
        t+=A[A_count]
        A_count+=1
        count+=1
    else:
        t+=B[B_count]
        B_count+=1
        count+=1
    print(t)
print(count-1)

Submission status: Wrong Answer

Solution code:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

n,m,k=sep()
a=lis()
b=lis()
from bisect import bisect_right
a_c=[a[0]]
b_c=[b[0]]
for i in range(1,n):
    a_c.append(a_c[-1]+ a[i])
for i in range(1,m):
    b_c.append(b_c[-1] + b[i])

m=-1
for i in range(n):
    if a_c[i]<=k:
        t=k-a_c[i]
        t2=bisect_right(b_c,t)
        m=max(i+1+t2,m)
    else:
        break
print(max(0,m))

Submission status: Wrong Answer

Solution code:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

n,m,k=sep()
a=lis()[::-1]
b=lis()[::-1]
c=0
while((a or b) and k>0):
    if a and b:
        if a[-1]<b[-1]:
            if k>=a[-1]:
                c+=1
                k -= a[-1]
                a.pop()

            else:
                break
        else:
            if k>=b[-1]:
                c+=1
                k -= b[-1]
                b.pop()

            else:
                break
    elif a:
        if k >= a[-1]:
            c += 1
            k-=a[-1]
            a.pop()
        else:
            break
    elif b:
        if k >= b[-1]:
            c += 1
            k-=b[-1]
            b.pop()
        else:
            break
print(c)

Submission status: Wrong Answer

Solution code:
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB

for i in range(1,len(A)):
  A[i] += A[i-1]
for i in range(1, len(B)):
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time >= 0:
    numb = bisect_right(B, rest_time)
    anstmp = i + 1 + numb 
    ans = max(ans, anstmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB

for i in range(1,len(A)):
  A[i] += A[i-1]
for i in range(1, len(B)):
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time > 0:
    numb = bisect_right(B, rest_time)
    anstmp = i + 1 + numb 
    ans = max(ans, anstmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB

for i in range(1,len(A)):
  A[i] += A[i-1]
for i in range(1, len(B)):
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time < 0:
    break
  numb = bisect_right(B, rest_time)
  anstmp = i + 1 + numb 
  ans = max(ans, anstmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB

for i in range(1,len(A)):
  A[i] += A[i-1]
for i in range(1, len(B)):
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time < 0:
    break
  numb = bisect_left(B, rest_time)
  anstmp = i + 1 + numb 
  ans = max(ans, anstmp)
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()))

total = 0
c = 0
while total <= k:
    c += 1
    if n > 0 and m > 0:
        if A[0] > B[0]:
            total += B.pop(0)
            m -= 1
        else:
            total += A.pop(0)
            n -= 1
    elif n == 0 and m > 0:
        total += B.pop(0)
        m -= 1
    elif n == 0 and m > 0:
        total += A.pop(0)
        n -= 1
    else:
        break

print(c-1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
# i冊読むための最小所要時間dp[i] = min(dp[i-1]+li_a[0], dp[i-1]+li_b[0])
dp = [0] * (n+m)
found = 0

for i in range(1,n+m):
    a_len = len(li_a)
    b_len = len(li_b)

    if a_len>0 and li_a < li_b:
        dp[i] = dp[i-1] + li_a[0]
        li_a = li_a[1:]

    elif b_len>0 and li_a > li_b:
        dp[i] = dp[i-1] + li_b[0]
        li_b = li_b[1:]

    elif a_len==0 and b_len!=0:
        dp[i] = dp[i-1] + li_b[0]
        li_b = li_b[1:]

    elif a_len!=0 and b_len==0:
        dp[i] = dp[i-1] + li_a[0]
        li_a = li_a[1:]

    if dp[i] > k:
        found = 1
        print(i-1)
        break

if not found:
    print(n+m)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
imput = sys.stdin.readline

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(aa[i] + a[i])
    
for i in range(m):
    bb.append(bb[i] + b[i])
    
ans = 0

for i in range(n):
    time = k - aa[i]
    cnt = i
    for j in range(m):
        if bb[j] <= time < bb[j+1]:
            cnt += j
            break
    if ans < cnt:
        ans = cnt
        
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()))

check = 0
i = 0
while i < N:
    if K >= (check + A[i]):
        check += A[i]
        i += 1
    else:
        break
cnt = i

cnt_ans = cnt
j = 0
stock = K - check
for i in range(cnt):
    while j < M:
        if stock >= B[j]:
            stock -= B[j]
            j += 1
        else:
            break
    cnt_ans = max(cnt_ans, cnt - i + j)

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

i = 0
check = 0
while i < N:
    if K >= check + A[i]:
        check += A[i]
        i += 1
    else:
        break

A = A[:i] + [0]
keep = check
cnt = i
for j in range(i):
    keep -= A[-(j + 1)]

    k = 0
    check = keep
    while k < M:
        if K >= check + B[k]:
            check += B[k]
            k += 1
        else:
            break
    cnt = max(cnt, i - j + k)
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.append(10**10);b.append(10**10) #guard
i=0;j=0 #counter for comparison
ans=0
for _ in range(n+m):
  if a[i]<=b[j] and a[i]<=k:
    k-=a[i]
    i+=1
    ans+=1
  elif a[i]>=b[j] and b[j]<=k:
    k-=b[j]
    j+=1
    ans+=1
  if k<=0: 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.append(10**10);b.append(10**10) #guard
i=0;j=0 #counter for comparison
ans=0
for _ in range(n+m):
  if a[i]<b[j] and a[i]<=k:
    k-=a[i]
    i+=1
    ans+=1
  elif b[j]<=k:
    k-=b[j]
    j+=1
    ans+=1
  if k<=0: break
print(ans)

Submission status: Wrong Answer

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

cnt = 0
i = 0
j = 0
while ((i < N) | (j < M)) & (K >= min(A[i], B[j])):

    if A[i] < B[j]:
        K -= A[i]
        i += 1
    else:
        K -= B[j]
        j += 1

    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
i = j = 0
while ((i < N) | (j < M)) & (K >= min(A[i], B[j])):

    if A[i] < B[j]:
        K -= A[i]
        i += 1
    else:
        K -= B[j]
        j += 1

    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
i = j = 0
while ((i < N) | (j < M)) & (K >= min(A[i], B[j])):

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

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
# i冊読むための最小所要時間dp[i] = min(dp[i-1]+li_a[0], dp[i-1]+li_b[0])
dp = [0] * (n+m)
found = 0

for i in range(1,n+m):
    a_len = len(li_a)
    b_len = len(li_b)

    if a_len==0 and b_len!=0:
        dp[i] = dp[i-1] + li_b[0]
        li_b = li_b[1:]

    elif a_len!=0 and b_len==0:
        dp[i] = dp[i-1] + li_a[0]
        li_a = li_a[1:]

    elif a_len>0 and li_a < li_b:
        dp[i] = dp[i-1] + li_a[0]
        li_a = li_a[1:]

    elif b_len>0 and li_a > li_b:
        dp[i] = dp[i-1] + li_b[0]
        li_b = li_b[1:]

    if dp[i] > k:
        found = 1
        print(i-1)
        break

if not found:
    print(n+m)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect_right
from itertools import accumulate

n,m,k=nii()
a=lnii()
b=lnii()
ar=[0]+list(accumulate(a))
br=[0]+list(accumulate(b))

ans=0
for i in range(n+1):
  time=ar[i]
  if time>k:
    break
  t_ans=i
  inx=bisect_right(br,k-time)-1
  t_ans+=inx
  ans=max(ans,t_ans)
print(t_ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect_right
from itertools import accumulate

n,m,k=nii()
a=lnii()
b=lnii()
ar=[0]+list(accumulate(a))
br=list(accumulate(b))
ans=0
for i in range(n+1):
  time=ar[i]
  if time>k:
    break
  t_ans=i
  inx=bisect_right(br,k-time)
  t_ans+=inx
  ans=max(ans,t_ans)

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

from itertools import accumulate
import bisect
cumsum_a = list(accumulate(a))
cumsum_b = list(accumulate(b))

ans = 0
for i in range(n+1):
    cnt_a = bisect.bisect(cumsum_a[:i], k)
    time = k - cumsum_a[cnt_a - 1]
    if time <= 0:
        break
    
    cnt_b = bisect.bisect(cumsum_b, time)
    
    ans = max(ans, cnt_a + cnt_b)

for i in range(m+1):
    cnt_b = bisect.bisect(cumsum_b[:i], k)
    time = k - cumsum_b[cnt_b - 1]
    if time <= 0:
        break

    cnt_a = bisect.bisect(cumsum_a, time)
    
    ans = max(ans, cnt_a + cnt_b)

print(ans)

Submission status: Wrong Answer

Solution code:
memo = {}

def get(self, a: list, b: list):
    pass

def main():
    line1 = input()
    line2 = input()
    line3 = input()
    
    n, m, k = list(map(int, line1.split()))
    a = list(map(int, line2.split()))
    b = list(map(int, line3.split()))
    memo[(0,0)] = 0
    book = 0
    for i in range(len(a)):
        memo[(i+1,0)] = memo[(i,0)] + a[i]
    for i in range(len(b)):
        memo[(0,i+1)] = memo[(0,i)] + b[i]
    for i in range(len(a)):
        for j in range(len(b)):
            if memo[(0,j+1)] + memo[(i+1,0)] <= k:
                if i + j + 2 > book:
                    book = i + j + 2
            else:
                break
    print(book)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

cum_a = []
rui = 0
for i in alist:
    rui += i
    cum_a.append(rui)
    
cum_b = []
rui = 0
for i in blist:
    rui += i
    cum_b.append(rui)
    
cum_a.insert(0,0)
cum_b.insert(0,0)


awork_list = []
for ina, a in enumerate(cum_a):
    for inb, b in enumerate(cum_b):
        #print(ina, inb, ina+inb,a+b)
        awork_list.append([ina, inb, ina+inb,a+b])
bwork_list = []
for inb, b in enumerate(cum_b):
    for ina, a in enumerate(cum_a):
        #print(inb, ina, ina+inb,a+b)
        bwork_list.append([inb, ina, ina+inb,a+b])
        
awork = []
for a in awork_list:
    if a[3] <= k:
        awork.append(a)
bwork = []
for b in bwork_list:
    if b[3] <= k:
        bwork.append(b)
        
max_v = 0
ans_a = 0
for a in awork:
    ans_a = max(max_v, a[2])
#print(ans_a)
max_v = 0
ans_b = 0
for b in awork:
    ans_b = max(max_v, b[2])
#print(ans_b)
print(max(ans_a, ans_b))