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.append(K)
B.append(K)

sumA = []
sumB = []

sumAi = 0
for i in range(N+1):
    sumAi += A[i]
    if sumAi > K:
        break
    else:
        sumA.append(sumAi)
AA = A[:i]

sumBj = 0
for j in range(M+1):
    sumBj += B[j]
    if sumBj > K:
        break
    else:
        sumB.append(sumBj)
BB = B[:j]

NN = len(AA)
MM = len(BB)

        
if NN == 0:
    ans = MM
else:
    ans = NN+MM
    time = sumA[-1]+sumB[-1]
    AA_rem = []
    BB_rem = []
    if time > K:
        for i in range(NN+MM):
            if AA[-1]>BB[-1]:
                nozoku = AA.pop(-1)
                AA_rem.append(nozoku)
                time -= nozoku
                ans -= 1
                last_nozo="A"
            else:
                nozoku = BB.pop(-1)
                BB_rem.append(nozoku)
                time -= nozoku
                ans -= 1
                last_nozo = "B"
            if time <= K:
                break
            
        if last_nozo == "A":
            for j in range(len(BB)):
                modosu = BB.pop(0)
                if time + modosu <= K:
                    time += modosu
                    ans += 1
                else:
                    break
        else:
            for i in range(len(AA)):
                modosu = AA.pop(0)
                if time + modosu <= K:
                    time += modosu
                    ans += 1
                else:
                    break

print(ans)

Submission status: Wrong Answer

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

A = [0]
B = [0]

A += [int(x) for x in input().split()]
B += [int(x) for x in input().split()]

TIME = 0
ans = 0

Ta = 0
Tb = 0

for i in range(N + 1):
    if Ta > K:
        break
    Ta += A[i]

    if i == 0:
        Tb = 0
        for j in range(M+1):
            Tb += B[j]
            if (Ta + Tb) > K:
                break
            else:
                TB = Tb
                ans = max(ans, i + j)
    else:
        if Ta == 0:
            break
        if (Ta + Tb) > K :            
            while (Ta + Tb) > K:
                if j > 0:
                    j -= 1
                    Tb -= B[j]
                else:
                    break
        if j > 0:
            ans = max(ans, i+j)
print(ans)

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

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

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

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

for k in range(1, len(L)+1):
    if L[-k] >= K:
        print(len(L)-k)
        break

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(100000000000)
b.append(100000000000)
i, j, ans = 0, 0, 0
while 1:
    if i == n and j == m: break
    if a[i] < b[j]:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k >= 0:
        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(" ")))
 
 
time=0
 
 
ok_list=[]
for i in range(1,N+1):
  for j in range(1,M+1):
    if sum(A[:i])+sum(B[:j]) <=K:
      ok_list.append(i+j)
    else:
      break
 
if len(ok_list)==0:
  print(0)
else:
   print(max(ok_list))

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,K=nm()
INF=10**18
A=nl()
B=nl()
A.append(INF)
B.append(INF)
A_c=0
B_c=0
ans=0
sum_l_A=[INF]*(N+2)
sum_l_B=[INF]*(M+2)

sum_l_A[0]=0
sum_l_B[0]=0
for i in range(1,N+2):
    sum_l_A[i]=sum_l_A[i-1]+A[i-1]

for i in range(1,M+2):
    sum_l_B[i]=sum_l_B[i-1]+B[i-1]



ans=0
a_c=0
b_c=0
now_resume=0
for j in range(N+M+4):
    resume=0
    a_c+=1
    while(1):
        now_resume=sum_l_A[a_c]+sum_l_B[b_c]
        if(now_resume>(sum_l_A[a_c-1]+sum_l_B[b_c+1])):
            a_c-=1
            b_c+=1
        else:
            break
    resume=sum_l_A[a_c]+sum_l_B[b_c]
    if(K<resume):
        print(ans)
        sys.exit(0)
    ans+=1
    now_resume=resume

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
from collections import deque
an= deque(map(int, input().split()))
bm= deque(map(int, input().split()))
ans =0
count = 0
while k>0 and len(an)+len(bm)>0:
    ans+=1
    if len(an)>0 and len(bm)>0:
        if an[0] >= bm[0]:
            mini = bm.popleft()
            k -= mini
            if 0 >k:
                ans -=1

        else:
            mini = an.popleft()
            k -= mini
            if 0 > k:
                ans -= 1


    elif len(bm)==0:
        mini = an.popleft()
        k -= mini
        if 0 > k:
            ans -= 1
    elif len(an)==0:
        mini = bm.popleft()
        k -= mini
        if 0 > k:
            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()))
count = 0
ANS = 0

for i in range(len(A)):
    count += A[i]
    if count > K:
        del A[i:]
        count=0
        ANS += len(A)
        break

for i in range(len(B)):
    count += B[i]
    if count > K:
        del B[i:]
        count=0
        ANS += len(B)
        break

count = sum(A) + sum(B)




while count > K:
    if A[-1] > B[-1]:
        count -= A[-1]
        del A[-1]
        ANS -= 1
    else:
        count -= B[-1]
        del B[-1]
        ANS -= 1

print(ANS)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from bisect import bisect_right

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

    a_acc, b_acc = A[:], B[:]
    for i in range(1, N):
        a_acc[i] += a_acc[i-1]
    
    for i in range(1, M):
        b_acc[i] += b_acc[i-1]
    
    res = 0
    for i, a in enumerate(a_acc):
        if a > K:
            break
        left = K - a
        j = bisect_right(b_acc, left)
        res = max(res, i + 1 + j)

    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Ans = []
chk_time = 0
chk_cnt = 0
if sum(A)+sum(B) <= k:
    print(n+m)
    exit()
for i in range(n):
    if chk_time+A[i] <= k:
        chk_time += A[i]
        chk_cnt += 1
    chk_time_b = chk_time
    chk_cnt_b = chk_cnt
    for j in range(m):
        if chk_time_b+B[j] <= k:
            chk_time_b += B[j]
            chk_cnt_b += 1
        else:
            Ans.append(chk_cnt_b)
            break
print(max(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()))
count = 0
ANS = 0

for i in range(len(A)):
    count += A[i]
    if count > K:
        del A[i:]
        count=0
        ANS += len(A)
        break

for i in range(len(B)):
    count += B[i]
    if count > K:
        del B[i:]
        count=0
        ANS += len(B)
        break
print(A, B, ANS)
count = sum(A) + sum(B)




while count > K:
    if A[-1] > B[-1]:
        count -= A[-1]
        del A[-1]
        ANS -= 1
    else:
        count -= B[-1]
        del B[-1]
        ANS -= 1

print(ANS)

Submission status: Wrong Answer

Solution code:
NMK=input().split(" ")
N=int(NMK[0])
M=int(NMK[1])
K=int(NMK[2])

def list2int(List):
    out=[]
    for i in range(len(List)):
        out.append(int(List[i]))
    return out

A=list2int(input().split(" "))
B=list2int(input().split(" "))

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

result=0
j=M

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

print(result)

Submission status: Wrong Answer

Solution code:
nmk = input().split(" ")
nv = [int(i) for i in input().split(" ")]
mv = [int(i) for i in input().split(" ")]

buf = 0
nv_i = 0
mv_i = 0
c = 0

while True:
  nv_i = min(nv_i, int(nmk[0])-1)
  mv_i = min(mv_i, int(nmk[1])-1)
  
  if nv[nv_i] < mv[mv_i]:
    chace = nv[nv_i]
    nv_i += 1
  else:
    chace = mv[mv_i]
    mv_i += 1
    
  if int(nmk[2]) > buf+chace:
    buf += chace
    c+=1
  else:
    break
print(c)

Submission status: Wrong Answer

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

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

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

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

ans = 0
flag = 0
for i in range(n):
    if k - a[i] < 0:
        flag = 1
        if ans < i:
            ans = i   
        break
    for j in range(m):
        if k - a[i] - b[j] < 0:
            flag = 1
            if ans < i + 1 + j:
                ans = i + 1 + j
            break

if flag == 0:
    print(n+m)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:

import bisect
import numpy

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

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

left_max = bisect.bisect_left(cost_a, k)

ans = 0
j = len(cost_b) - 1
for i in range(left_max):
    for j in range(j , -1, -1):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
            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()))

count = 0
ar = [0] * (N + 1)
br = [0] * (M + 1)

for i, v in enumerate(A):
    ar[i+1] = ar[i] + v

for i, v in enumerate(B):
    br[i+1] = br[i] + v

max_read = 0
for i in range(N+1):
    rest = K - ar[i]
    if rest <= 0:
        break
    j = -1
    for v in br:
        if rest - v < 0:
            break
        j += 1
    max_read = max(max_read, i+j)

print(max_read)

Submission status: Wrong Answer

Solution code:
from collections import deque

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


consumptions_A = []
for i in range(len(A) + 1):
    consumptions_A.append(sum(A[:i]))

consumptions_B = []
for i in range(len(B) + 1):
    consumptions_B.append(sum(B[:i]))

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
        num_books = i + j
        answer = max(answer, num_books)

print(answer)

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

mat = [[None] * (m+1) for _ in range(n+1)]

acc = 0
for i in range(n):
    mat[i+1][0] = (i+1, acc + ns[i])
    acc += ns[i]

acc = 0
for i in range(m):
    mat[0][i+1] = (i+1, acc + ms[i])
    acc += ms[i]

mx = 0
for i in range(1, n+1):
    for j in range(1, m+1):
        i2, c2 = mat[i][j-1]
        mat[i][j] = (i2 + 1,  c2 + ms[j-1])
        if mat[i][j][1] > k:
            break
        mx = max(mx, mat[i][j][0])

print(mx)

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:
        s+=B[y]
        num +=1
        y +=1
    elif y>=M:
        s+=A[x]
        num +=1
        x +=1
    else:
        break
print(num)

Submission status: Wrong Answer

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

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

    ans = 0
    for i in range(n):
        if a_sum[i] > k:
            continue
        for j in range(m):
            if a_sum[i] + b_sum[j] <= k:
                ans = max(ans, i + j)
            else:
                break

    print(ans)


if 'unittest' not in globals():
    resolve()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))+[10**9+1]*m
b = list(map(int,input().split()))+[10**9+1]*n
Sum = 0
ans = 0
a_i = 0
b_i = 0
N = n+m

for i in range(N):
    if a[a_i] < b[b_i]:
        Sum += a[a_i]
        a_i += 1
    elif a[a_i] > b[b_i]:
        Sum += b[b_i]
        b_i += 1
    else:
        for j in range(1,N-i-1):
            if a[a_i+j] < b[b_i+j]:
                Sum += a[a_i]
                a_i += 1
                break
            elif a[a_i+j] > b[b_i+j]:
                Sum += b[b_i]
                b_i += 1
                break
    if Sum > k:
        ans = i
        break
else:
    ans = N

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# a = int(input())
# w = list(map(int, input().split()))
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
arui = [0]
for i in range(n):
    arui.append(arui[i]+a[i])

brui = [0]
for i in range(m):
    brui.append(brui[i]+b[i])

ans = 0
for i in range(1, n+1):
    if arui[i] > p:
        break
    bmax = p-arui[i]
    for j in range(m, -1, -1):
        # print(arui[i])
        if bmax >= brui[j]:
            if ans <= i+j:
                ans = i+j
                break

#print(arui)
#print(brui)
print(ans)

Submission status: Wrong Answer

Solution code:
NMK = input().split()
A = input().split()
B = input().split()
count = 0
time = int(NMK[2])
while True:  
  if (time < int(A[0])) and (time < int(B[0])):
    break
  if int(A[0]) <= int(B[0]):
    time -= int(A.pop(0))
    count += 1
  else:
    time -= int(B.pop(0))
    count += 1
  if A == []:
    A.append(10**10)
  if B == []:
    B.append(10**10)
print(count)

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]*N, [0]*M
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:
n,m,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))

from itertools import accumulate
a_acc=list(accumulate(a))
b_acc=list(accumulate(b))

cnt=0

import bisect
for i in range(n):
    nokori=k-a_acc[i]
    if nokori<b[0]:
        break
    b_i=bisect.bisect_right(b_acc,nokori)
    cnt=max(cnt,(i+1)+b_i)
    # print(nokori,i,b_i)

print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools as it
def main():
    n,m,k=map(int,input().split())
    Aa = list(map(int,input().split()))
    Bb = list(map(int, input().split()))
    a, b = [0],[0]
    for i in range(n):
        a.append(a[i] + Aa[i])
    for i in range(m):
        b.append(b[i] + Bb[i])
    M = m
    ans = 0
    for A in range(n,-1,-1):
        aa = a[A]
        Kaa = k-aa
        for B in range(M,-1,-1):
            if b[B] <= Kaa:
                ans = max(ans, A+B)
                M = B
    print(ans)

if __name__ == '__main__':
    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()))
A = A[::-1]
B = B[::-1]

cnt = 0
time = 0
A_s = sum(A)
B_s = sum(B)

if A_s + B_s <= k:
  print(len(A)+len(B))
  
elif A[-1] > k and B[-1] > k:
  print(0)
  
else:
  while time <= k:
      if A[-1] >= B[-1]:
          time += B[-1]
          B.pop()
          cnt += 1
          if len(B) == 0:
              B.append(10000000000)
      else:
         time += A[-1]
         A.pop()
         cnt += 1
         if len(A) == 0:
             A.append(10000000000)
  print(cnt-1)

Submission status: Wrong Answer

Solution code:
import random
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=random.randint(0,n+m)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# a = int(input())
# w = list(map(int, input().split()))
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
arui = [0]
for i in range(n):
    arui.append(arui[i]+a[i])

brui = [0]
for i in range(m):
    brui.append(brui[i]+b[i])

ans = 0
for i in range(1, n+1):
    if arui[i] > p:
        break
    bmax = p-arui[i]
    for j in range(m, -1, -1):
        # print(arui[i])
        if bmax >= brui[j]:
            if ans <= i+j:
                ans = i+j
                break

print(arui)
print(brui)
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()))

AL = []
BL = []
a = 0
for i in A:
    a += i
    AL.append(a)
a = 0
for i in B:
    a += i
    BL.append(a)

#print(AL)
#print(BL)

a = 0
for i in range(len(AL)):
    if AL[i] > k:
        a = i+1
        break
else:
    a = len(AL)

b = 0
for i in range(len(BL)):
    if BL[i] > k:
        b = i+1
        break
else:
    b = len(BL)

#print(a,b)

m = a
u = 0
for j in reversed(range(a)):
#    print(j,u)
    t = k-AL[j]
    for i in range(u,b):
#        print(i)
        if t-BL[i]>=0:
            if m < j+1 + i +1:
                m = j+1 + i +1
#                print(m)
        else:
            if i >0:
                u = i-1
            break
        
    if j+1+b<m:
        break
if a == 0 and b > 0:
    m = b
print(m)

Submission status: Wrong Answer

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

from itertools import accumulate
a_acc=list(accumulate(a))
b_acc=list(accumulate(b))

cnt=0

import bisect
for i in range(n):
    nokori=k-a_acc[i]
    if nokori<b[0]:
        break
    b_i=bisect.bisect_right(b_acc,nokori)
    cnt=max(cnt,(i+1)+b_i)
    print(nokori,i,b_i)

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

S_A = [0] * (N + 1)
S_B = [0] * (M + 1)
for i in range(N):
  S_A[i+1] = S_A[i] + A[i]

for i in range(M):
  S_B[i+1] = S_B[i] + B[i]
  
ans = 0
a = 0
for i in range(M, -1, -1):
  s = S_B[i]
  while a<N:
    if s + S_A[a + 1]<=K:
      a += 1
    else:
      break
  ans = max(ans, i + a)
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]

j = M
ans = 0

for i in range(N):
    a.append(A[i] + a[i])
for i in range(M):
    b.append(B[i] + b[i])

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

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(y) for y in input().split()]
a = 0
b = 0
hon = 0
C = []
D = []
x = M

for p in range(0,N):
    if p == 0:
        C += [int(A[0])]
    else:
        C += [int(A[p])+int(C[p-1])]
for q in range(0,M):
    if q == 0:
        D += [int(B[0])]
    else:
        D += [int(B[q])+int(D[q-1])]

for p in range(0,N):
    for q in reversed(range(0,x)):
        if C[p]+D[q] <= K:
            hon = max(p+q+2,hon)
            break
        else:
            x = q 
print(hon)





"""
while K >= A[a] or K >= B[b]:
    if K >= A[a] and A[a] <= B[b]:
        K -= A[a]
        a += 1
        hon += 1
    if K >= B[b] and B[b] <= A[a]:
        K -= B[b]
        b += 1
        hon += 1
print(hon)
"""

Submission status: Wrong Answer

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

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

ans = 0
j = m
for i in range(1, 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:
N, M, K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ind_A = 0
ind_B = 0
ans = 0
time = 0

while time <= K:
    if ind_A >= N and ind_B >= M:
        ans += 1
        break

    if (ind_B >= M and ind_A < N): # Bを読み終わったからAの本を読む
        time += A[ind_A]
        ind_A += 1
        ans += 1
    elif (ind_A >= N and ind_B < M) : # Aを読み割ったからBの本を読む
        time += B[ind_B]
        ind_B += 1
        ans += 1
    elif  A[ind_A] <= B[ind_B]: #Aの方が先に読み終わるからAの本を読む
        time += A[ind_A]
        ind_A += 1
        ans += 1
    elif A[ind_A] > B[ind_B]: #Bの方が先に読み終わるからBの本を読む
        time += B[ind_B]
        ind_B += 1
        ans += 1
    
print(ans - 1)

Submission status: Wrong Answer

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

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

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1
    else:
        for i in range(1, min(len(a), len(b))):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    if k < a[0]:
                        break
                    k -= a.popleft()
                    cnt += 1
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    if k < b[0]:
                        break
                    k -= b.popleft()
                    cnt += 1
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    if k < a[0]:
                        break
                    k -= a.popleft()
                    cnt += 1
            else:
                for i in range(len(b)):
                    if k < b[0]:
                        break
                    k -= b.popleft()
                    cnt += 1
    if a == deque([]):
        for i in range(len(b)):
            if k < b[0]:
                break
            k -= b.popleft()
            cnt += 1
        break
    if b == deque([]):
        for i in range(len(a)):
            if k < a[0]:
                break
            k -= a.popleft()
            cnt += 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()))

Sa = [0]*N
Sb = [0]*M
Sa[0] = A[0]
Sb[0] = B[0]
for i in range(1, N):
    Sa[i] = Sa[i-1] + A[i]
for i in range(M):
    Sb[i] = Sb[i-1] + B[i]
ans = 0
for i in range(N):
    if Sa[i] > K:
        break
    for j in range(M-1, -1, -1):
        if Sa[i]+Sb[j] <= K:
            ans = max(ans, i+1+j+1)
            M = j+1
            break
    else:
        ans = max(ans, i+1)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, 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 sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,K=nm()
INF=10**18
A=nl()
B=nl()
A.append(INF)
B.append(INF)
A_c=0
B_c=0
ans=0
sum_l_A=[INF]*(N+2)
sum_l_B=[INF]*(M+2)

sum_l_A[0]=0
sum_l_B[0]=0
for i in range(1,N+2):
    sum_l_A[i]=sum_l_A[i-1]+A[i-1]

for i in range(1,M+2):
    sum_l_B[i]=sum_l_B[i-1]+B[i-1]



ans=0
a_c=0
b_c=0
now_resume=0
for j in range(N+M+4):
    resume=0
    a_c+=1
    while(1):
        now_resume=sum_l_A[a_c]+sum_l_B[b_c]
        if(now_resume>sum_l_A[a_c-1]+sum_l_B[b_c+1]):
            a_c-=1
            b_c+=1
        else:
            break
    resume=sum_l_A[a_c]+sum_l_B[b_c]
    if(K<resume):
        print(ans)
        sys.exit(0)
    ans+=1
    now_resume=resume

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

Sa = [0]*N
Sb = [0]*M
Sa[0] = A[0]
Sb[0] = B[0]
for i in range(1, N):
    Sa[i] = Sa[i-1] + A[i]
for i in range(M):
    Sb[i] = Sb[i-1] + B[i]
ans = 0
for i in range(N):
    if Sa[i] > K:
        break
    for j in range(M-1, -1, -1):
        if Sa[i]+Sb[j] <= K:
            ans = max(ans, i+1+j+1)
            break
    else:
        ans = max(ans, i+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
n, M, k = map(int,input().split())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
read_a = [0]*n
read_b = [0]*M
time = 0
ans = 0
memo = 0
for j in range(n):
    if time + a_l[j] <= k:
        time += a_l[j]
        read_a[j] = 1
        memo = j
        ans = j+1
    else:
        break

kotae = [ans]


def dfs(i,a,t,m):
    global kotae
    if i < M:
        if b_l[i] + t <= k:
            tt = t + b_l[i]
            aa = a + 1
            kotae.append(aa)
            ii = i+1
            mm = m
            #print(aa)
            dfs(ii,aa,tt,mm)
            
        else:
            if m >= 0:
                tt = t - a_l[m]
                mm = m - 1
                aa = a - 1
                ii = i
                dfs(ii,aa,tt,mm)
            


dfs(0,ans,time,memo)


print(max(kotae))

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect

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)
l = [0]

for i in range(n):
    if bisect.bisect_right(bc, k - ac[i]) > 0:
        l.append(bisect.bisect_right(bc, k - ac[i]) + i + 1)
print(max(l))