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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

A=list(map(int,stdin.readline().split()))
N=A[0]
M=A[1]
K=A[2]
KK=K
B=list(map(int,stdin.readline().split()))  #N
C=list(map(int,stdin.readline().split()))  #M

Nlist=list()
Mlist=list()
sum=0

for u in B:
    sum+=u
    if sum>K:
        break
    Nlist.append(sum)


sum=0
O=0

for v in C:
    sum+=v
    if sum>K:
        break
    Mlist.append(sum)

if len(Mlist)==0 and len(Nlist)==0:
    print(0)
    O=1

if O==0:
    if len(Mlist)==0:
        print(len(Nlist))
        O=1
    if len(Nlist)==0:
        print(len(Mlist))
        O=1
    if Mlist[len(Mlist)-1]+Nlist[len(Nlist)-1]<=K:
        print(len(Mlist)+len(Nlist))
        O=1

MAX=2
mbegin=0
mend=len(Mlist)-1
archive=0
# print(Nlist)
# print(Mlist)



if O==0:

    for u in range(len(Nlist)-1,-1,-1):
        mend=len(Mlist)-1
        K=KK
        K=K-Nlist[u]
        MAX=max(MAX,u+1)
        #print(K)
        #binary search
        if Mlist[mbegin]<=K:
            UU = (mbegin + mend) // 2
            while mbegin!=UU:
                UU = (mbegin + mend) // 2
                if Mlist[UU]<=K:
                    K-=Mlist[UU]
                    mbegin=UU
                else:
                    mend=UU

            if mbegin==archive:
                #print('hh')
                if mbegin==0:
                    #print(MAX)
                    MAX=max(MAX,u+2)
                    #print(MAX)
                break

            MAX=max(MAX,u+mbegin+2)
            print(MAX)
            archive=mbegin

if O==0:
   print(MAX)

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[i - 1])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B[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:
root = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))    
minute=0
books=0
ai=0
bi=0

while minute <= root[2]:
    if len(a) == ai:
        while len(b) < bi and minute <= root[2]:
            minute += b[bi]
            books += 1
            bi += 1
        break
    if len(b) == bi:
        while len(a) < ai and minute <= root[2]:
            minute += a[ai]
            books += 1
            ai += 1
        break
    if a[ai] < b[bi]:
        minute += a[ai]
        books += 1
        ai += 1
    elif b[bi] < a[ai]:
        minute += b[bi]
        books += 1
        bi += 1
    else:
        if len(a) == ai and len(b) == bi:
            books += 1
            break
        if len(a) > ai:
            minute += a[ai]
            books += 1
            ai += 1
        elif len(b) > bi:
            minute += b[bi]
            books += 1
            bi += 1
            
        
print(books-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()))

C=[]
while len(A)!=0 and len(B)!=0:
    if A[0]>=B[0]:
        C.append(B.pop(0))
    elif A[0]<B[0]:
        C.append(A.pop(0))

if len(A)!=0 and len(B)==0:
    C+=A
if len(A)==0 and len(A)==0:
    C+=B 


time=0
count=0
for i in range(len(C)):
  time+=C[i]
  if time<=k:
    count+=1
  else:
    break
print(count)

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

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

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

ans = 0
for i in range(n):
    for j in range(m):
        t = A[i] + B[j]
        if t > k:
            break
        else:
            ans = max(ans, i + j + 2)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
from bisect import bisect_right
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A_ = list(accumulate(A))
    B_ = list(accumulate(B))

    init = bisect_right(A_, k)
    if init != 0:
        res = init
        for i in range(init):
            t = k - A_[init - i - 1]
            idx = bisect_right(B_, t)
            res = max(res, init - i + idx)
    else:
        res = bisect_right(B_, k)

    print(res)


if __name__ == '__main__':
    resolve()

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[i - 1])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B[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, i + 1 + 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:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def ruiseki(mydata):
    res = [0]*(len(mydata)+1)
    for i in range(len(mydata)):
        res[i+1] = res[i] + mydata[i]
    return res

n, k , m = MI()
a = ruiseki(LI())
b = ruiseki(LI())
a = a
b = b

result = 0
for i, ii in enumerate(a):
    if ii > m:
        break
    for j in range(len(b)-1):
        tempb = b[k-j]
        if tempb + ii <= m:
            result = max(result, i+k-j)
            break
print(result)

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

total = 0
for i in range(N):
    total += A[i]
    a[i] = total

a = [0] + a

total = 0
for i in range(M):
    total += B[i]
    b[i] = total

b = [0] + b

ans, j = 0, M
for i in range(N):
    if a[i] > K:
        break
    while b[j] + a[i] > 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(x) for x in input().split()]

i ,j = 0,0 
tot =0
ans =0
while i<n and j<m:
    if a[i] <= b[j]:
        if tot + a[i] <= k :
            tot+=a[i]
            ans+=1 
            i+=1 
        else:
            break 
    else:
        if tot + b[j] <= k :
            tot+=b[j]
            ans+=1 
            j+=1 
        else:
            break 
while i < n:
    if tot + a[i] <= k :
        tot+=a[i]
        ans+=1 
        i+=1 
    else:
        break 
while j < m:
    if tot + b[j] <=k:
        tot+=b[j]
        ans+=1 
        j+=1 
    else:
        break 
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
K2 =K
count = 0
numa = 0
numb = 0
count2 = 0
for i in range(N):
    count += A[i]
    A[i] = count
#累積和
B = list(map(int,input().split()))
count = 0
for i in range(M):
    count += B[i]
    B[i] = count
#累積和

for i in range(N):#Aに対してBを探す
    K = K2
    if A[i] <= K:
        K -= A[i]
        if bisect.bisect_right(B, K) != 0:
            
            if count2 < i+1 + bisect.bisect_right(B, K):
                count2 = i+1 + bisect.bisect_right(B, K) 
    else:
        break
print(count2)

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:
    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:
import sys
from itertools import accumulate
import bisect
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


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

    aa = list(accumulate(A))
    bb = list(accumulate(B))
    ans = 0
    for i in range(len(aa)):
        if aa[i] <= K:
            tmp = bisect.bisect_right(bb, K - aa[i]) + i + 1
        else:
            tmp = 0
        ans = max(ans, tmp)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(N):
    if K < A_cumulative_sum[i]:
        break
    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 = 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
j = M
for i in range(N+1):
    rest = K - ar[i]
    if rest <= 0:
        break
    while br[j] > K - ar[i]:
        j -= 1
    max_read = max(max_read, i+j)

print(max_read)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

sum_A = [0]
sum_B = [0]
for n in range(N):
    sum_A.append(sum_A[n]+A[n])
for m in range(M):
    sum_B.append(sum_B[m]+B[m])

max_j = M
max_book = 0
for i in range(N+1):
    # Aの机でi冊読んだときのBの机で読む最大値
    for j in range(max_j,-1,-1):
        if sum_A[i]+sum_B[j] <= K:
            max_j = j
            break
        else:
            max_j = 0
    max_book = max(max_book, i+max_j)

print(max_book)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(i) for i in input().split(' ')]
a_s = [int(i) for i in input().split(' ')]
b_s = [int(i) for i in input().split(' ')]
pa = 0
pb = 0

#積み上げ
def acc(a):
  r = []
  s = 0
  for i in a:
    s += i
    if s > k:
      break
    r.append(s)
  return r
a_c = acc(a_s)
b_c = acc(b_s)

def mincost(a_acc, p, room):
  mc = k + 1
  mi = 0
  ms = k + 1
  if p == 0:
    gnd = 0
  else:
    gnd = a_acc[p-1] 
  for i in range(p, len(a_acc)):
    s = a_acc[i] - gnd
    if s > room:
      break
    c = s / (i - p + 1)
    if mc > c:
      mc = c
      mi = (i - p + 1)
      ms = s
  return (mc, mi, ms)

room = k

while True:
  (amc, ami, ams) = mincost(a_c, pa, room)  
  (bmc, bmi, bms) = mincost(b_c, pb, room)
  if ami == 0 and bmi == 0:
    break

  if amc < bmc:
    pa += ami
    room -= ams
  else:
    pb += bmi
    room -= bms

print(pa + pb)

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[i - 1])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B[i - 1])

for i in range(N):
    if K < A_cumulative_sum[i]:
        break
    remaining_time = K - A_cumulative_sum[i]
    idx = bisect.bisect_left(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 = [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)):
        x = q
        if C[p]+D[q] <= K:
            hon = max(p+q+2,hon)
            break
        
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, 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
j = m
for i in range(1, n+1):
    if arui[i] > p:
        break
    bmax = p-arui[i]
    while brui[j] > bmax:
        j -= 1
    if ans <= i+j:
        ans = i+j
    

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    
    if a[0] > K and b[0] > K:
        return 0

    a2=[0]
    for i in a:
        if a2[-1] >= K:
            break 
        a2.append(a2[-1]+i)
    a2 = a2[1:]
    b_sum = sum(b)
    bi = len(b)
    max_ij = len(a2)

    val = K
    for i in range(len(a2) + 1):
        while val < b_sum:
            bi -= 1
            b_sum -= b[bi]
        max_ij = max(max_ij, i + bi)
        if i == len(a2):
            break
        if a2[i] > K:
            break
        val = K - a2[i]
    return max_ij

if __name__ == '__main__':
    print(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, b = [0], [0]
for i in range(0, N):
    a.append(a[i] + A[i])
for j in range(0, M):
    b.append(b[j] + B[j])

ans = 0
j = M
for i in range(0, N):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j = 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()))

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
        break
else:
    a = len(AL)

b = 0
for i in range(len(BL)):
    if BL[i] > k:
        b = i
        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 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()))
ans=0
aindex=n
bindex=m
acumsum = [0]
bcumsum = [0]

ab =0
for aa in range(n):
  ab += a[aa]
  acumsum.append(ab)# = ab
  if ab>k:
    aindex= aa
    break

ab =0
for bb in range(m):
  ab += b[bb]
  bcumsum.append(ab)
  if ab>k:
    bindex= bb
    break

j= bindex
for i in range(aindex+1):
  if acumsum[i] >k:
    break
  while bcumsum[j] > k-acumsum[i]:
    j -=1
  ans = max(ans, i+j)

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)
ans = 0

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

sum_A = [0]
sum_B = [0]
for n in range(N):
    sum_A.append(sum_A[n]+A[n])
for m in range(M):
    sum_B.append(sum_B[m]+B[m])

max_j = M
max_book = 0
for i in range(N+1):
    # Aの机でi冊読んだときのBの机で読む最大値
    for j in range(max_j,-1,-1):
        if sum_A[i]+sum_B[j] <= K:
            max_j = j
            break
        else:
            max_j = 0
    print(i, max_j)
    max_book = max(max_book, i+max_j)

print(max_book)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
check = []

tmp = 0
for i in range(N):
    if tmp + A[i] <= K:
        tmp += A[i]
    else:
        check.append(i)
        break
else:
    check.append(i+1)
tmp2 = tmp
tmp = 0

for i in range(M):
    if tmp + B[i] <= K - tmp2:
        tmp += B[i]
    else:
        check.append(i)
        break
else:
    check.append(i+1)

tmp = 0
for i in range(M):
    if tmp + B[i] <= K:
        tmp += B[i]
    else:
        check.append(i)
        break
else:
    check.append(i+1)

tmp2 = tmp
tmp = 0
for i in range(N):
    if tmp + A[i]<= K - tmp2:
        tmp += A[i]
    else:
        check.append(i)
        break
else:
    check.append(i+1)
print(max(sum(check[:2]),sum(check[2:])))

Submission status: Wrong Answer

Solution code:
import itertools
n, m, k = [int(i) for i in input().split()]
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]

a_acc = [0]
a_acc.extend(list(itertools.accumulate(a_list)))
b_acc = [0]
b_acc.extend(list(itertools.accumulate(b_list)))

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

    while b_acc[j] > k - a_acc[i]:
        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
        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:

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)

ans = 0
j =  len(cost_b) -1
for i in range(len(cost_a)):
    for j in range( j, 0, -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:
import sys
from itertools import accumulate
from bisect import bisect_right
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A_ = list(accumulate(A))
    B_ = list(accumulate(B))

    init = bisect_right(A_, k)
    res = init
    for i in range(init):
        t = k - A_[init - i - 1]
        idx = bisect_right(B_, t)
        res = max(res, init - i + idx)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

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

a = [0] + a
b = [0] + b

ans = 0

for i in range(n+1):
    can = k - a[i]
    if can <= 0:
        break
    j = bisect.bisect_right(b, can)
    ans = max(ans, i+j-1)
print(ans)

Submission status: Wrong Answer

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

lsAN = []
sumA = 0
for i in range(N):
    sumA += lsA[i]
    lsAN.append(sumA)
lsBN = []
sumB = 0
for i in range(M):
    sumB += lsB[i]
    lsBN.append(sumB)   
maxij = [0]
for i in range(N):
    for j in range(M):        
        if K - lsAN[i] >= lsBN[M-j-1]:
            maxij.append(i+1+(M-j))
            break
print(max(maxij))

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):
                    if k < a[0]:
                        break
                    k -= a.popleft()
                    cnt += 1
                break
            elif a[i] > b[i]:
                for t in range(0, i):
                    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:
import itertools
import numpy as np 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

acc = np.array(acc)
#print(acc)
bcc = np.array(bcc)

checkA = np.where(acc <= k)
chA = checkA[0]
checkB = np.where(bcc <= k)
chB = checkB[0]

if (len(chA) > len(chB)):
  a1 = chA
  b1 = chB
  aa = acc
  bb = bcc
else:
  a1 = chB
  b1 = chA
  aa = bcc
  bb = acc

if (len(a1) == 0):
  print(0)
  exit()

ans = 0
#print(acc[3])
for i in range(len(a1) -1, -1, -1):
  #print(i, acc[a1[i]])
  #print(i)
  rest = k - aa[int(a1[i])]
  tar = np.where(bb <= rest)
  if (len(tar[0]) == 0):
    num = 0
  else:
    num = tar[0][-1]

  #print('num', num)
  ans = max(num + i + 2, ans)
    

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

sumA=[0]
sumB=[0]


for i in range(N):
  sumA.append(sumA[-1]+A[i])
for i in range(M):
  sumB.append(sumB[-1]+B[i])

  
total=0
for a in range(len(sumA)):
  for b in range(len(sumB)):
    if sumA[a]+sumB[b]<=K:
      total=a+b
    else:
      break
  if sumA[a]>K:
    break
    
print(total)

Submission status: Wrong Answer

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

n = 0
i = 0
while n < K:
    if len(list_A) == 0 and len(list_B) == 0:
        break
    else:
        if len(list_A) == 0:
            n += list_B.pop(0)
        elif len(list_B) == 0:
            n += list_A.pop(0)
        elif list_A[0] <= list_B[0]:
            n += list_A.pop(0)
        else:
            n += list_B.pop(0)

        if n < K:
            i += 1


print(i)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

A_acum = list(itertools.accumulate(A))
B_acum = list(itertools.accumulate(B))

ans = 0
for i in range(N-1, -1, -1):
    if A_acum[i] > K:
        continue
    else:
        p = K - A_acum[i]
        c = bisect.bisect(B_acum, p)
        ans = max(ans, i+c+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 = -1
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(kotae)

Submission status: Wrong Answer

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

n = 0
i = 0
while n < K:
    if len(list_A) == 0 and len(list_B) == 0:
        break
    else:
        if len(list_A) == 0:
            n += list_B.pop(0)
        elif len(list_B) == 0:
            n += list_A.pop(0)
        elif list_A[0] <= list_B[0]:
            n += list_A.pop(0)
        else:
            n += list_B.pop(0)

        if N < K:
            i += 1


print(i)