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

time = K
ans = 0
a = 0
b = 0
while True:
    if a >= N:
        if b >= M-1:
            if B[b] == time:
                ans += 1
            break
        time -= B[b]
        b += 1
    elif b >= M:
        if a >= N-1:
            if A[a] == time:
                ans += 1
            break
        time -= A[a]
        a += 1
    else:
        if A[a] > K or B[b] > K:
            break
        if(A[a] < B[b]):
            time -= A[a]
            a += 1
        else:
            time -= B[b]
            b += 1
    if time <= 0:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

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

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

if N == 1 and M == 1:
    if K >= A[0] + B[0]:
        print(2)
    elif K >= min(A[0], B[0]):
        print(1)
    else:
        print(0)
    exit()

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

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

ans = 0

for i, a in enumerate(A):
    time = K - a
    if time < 0:
        continue
    cnt = i + 1
    cnt += bisect(B, time)
    ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
count = 0
output = 0
for i in range(N):
    count += A_list[i]
    if count > K:
        break
for j in range(i + 1):
    alcount = sum(A_list[:j + 1])
    for h in range(M):
        alcount += B_list[h]
        if alcount > K:
            break
        if j + h + 2 > output:
            output = j + h + 2
    
#        print(j,h,alcount)
print(output)

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.sort()
b.sort()

time = 0
ia = 0
ib = 0

while time <= k:
    if ia >= len(a) and ib >= len(b):
        break
    elif ia >= len(a):
        time += b[ib]
        ib += 1
    elif ib >= len(b):
        time += a[ia]
        ia += 1
    
    elif a[ia] <= b[ib]:
        time += a[ia]
        ia += 1
    else:
        time += b[ib]
        ib += 1

if time > k:
    print(ia + ib - 1)
else:
    print(ia + ib)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(1000000000000000000000)
B.append(1000000000000000000000)
A.reverse()
B.reverse()


ans = 0
c = 0
while True:
  if sum(A[-2:]) >= sum(B[-2:]):
    b = B.pop()
    if ans+b > X:
      break
    ans += b
    c += 1
  else:
    a = A.pop()
    if ans+a > X:
      break
    ans += a
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
AStr = input().split()
BStr = input().split()

A = []
B = []

tmp = 0
for i in AStr:
    tmp += int(i)
    if (tmp > K):
        break
    A.append(int(i))

tmp = 0
maxB = 0
for i in BStr:
    tmp += int(i)
    if (tmp > K):
        break
    B.append(int(i))
    maxB += int(i)

num = 0
tmp = 0
maxNum = len(A)
if maxNum < len(B):
    maxNum = len(B)

numB = len(B)
for i in range(len(A)+1):
    tmpj = 0
    if i != 0:
        tmpj += A[i-1]

    while (tmpj + maxB > K):
        maxB -= B.pop()
        numB -= 1

    if i + numB > maxNum:
        maxNum = i + numB


print(maxNum)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ia 
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = list(ia(A))
b = list(ia(B))
na = 0
nb = 0
for i in a:
  if i < K:
    na += 1
  else:
    break
for i in b:
  if i < K:
    nb += 1
  else:
    break

t = a[na-1]
for i in B:
  if t + i > K:
    break
  else:
    na += 1
    t += i
t = b[nb-1]
for i in A:
  if t + i > K:
    break
  else:
    nb += 1
    t += i
print(max(na, nb))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))

    a_time = [0]
    b_time = []

    t = 0
    for a in a_lst:
        t += a
        if t > k:
            break
        a_time.append(t)
    t = 0
    for b in b_lst:
        t += b
        if t > k:
            break
        b_time.append(t)

    a_que = deque(a_time)
    b_que = deque(b_time)
    cnt = len(a_que)
    c_max = cnt - 1
    while c_max <= cnt and a_que and b_que:
        cnt -= 1
        a = a_que.pop()
        b = b_que.popleft()
        while a + b <= k:
            cnt += 1
            c_max = cnt
            if b_que:
                b = b_que.popleft()
            else:
                break

    print(c_max)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import bisect

input = sys.stdin.readline

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    Acum = list(itertools.accumulate(A))
    Bcum = list(itertools.accumulate(B))
    A = A[:bisect.bisect_right(Acum, K)]
    B = B[:bisect.bisect_right(Bcum, K)]
    rtime = sum(A) + sum(B)
    ans = len(A) + len(B)
    if rtime <= K:
        print(ans)
        return
    while rtime > K:
        if len(A) > 0 and len(B) > 0:
            Atmp = A.pop()
            Btmp = B.pop()
            if Atmp >= Btmp:
                B.append(Btmp)
                rtime -= Atmp
                ans -= 1
            else:
                A.append(Atmp)
                rtime -= Btmp
                ans -= 1
        elif len(A) == 0 and len(B) > 0:
            Btmp = B.pop()
            rtime -= Btmp
            ans -= 1
        elif len(A) > 0 and len(A) == 0:
            Atmp = A.pop()
            rtime -= Atmp
            ans -= 1
        else:
            print(0)
            return
    print(ans)
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a_sum = [0]
b_sum = [0]
for i in range(1, n+1):
  a_sum.append(a_sum[i-1] + an[i-1])
for j in range(1, m+1):
  b_sum.append(b_sum[j-1] + bn[j-1])

ans = len(bn)
idx = len(bn)
for j in range(m+1):
  if k - b_sum[j] < 0:
    ans = j - 1
    idx = j - 1
    break
for i in range(1, n+1):
  if a_sum[i] + b_sum[idx] > k:
    idx -= 1
    if idx < 0:
      for l in range(n+1):
        if k - a_sum[l] < 0:
          print(l - 1)
          exit()
  else:
    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()))

time = 0
count = -1
while time <= K:
    count += 1
    if not A and not B:
        break
    elif not A:
        time += B.pop(0)

    elif not B:
        time += A.pop(0)

    else:
        if A[0] <= B[0]:
            time += A.pop(0)

        else:
            time += B.pop(0)
print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    n, m, k = [int(x) for x in stdin.readline().rstrip().split()]

    pileda = 0
    a = [0]
    # ai = 0
    for x in stdin.readline().rstrip().split():
        # ai += 1
        x = int(x)
        pileda += x
        a.append(pileda)
        if pileda > k:
            break
    
    piledb = 0
    b = [0]
    for x in stdin.readline().rstrip().split():
        x = int(x)
        piledb += x
        b.append(piledb)
        if piledb > k:
            break

    maxa = len(a)-1
    maxb = len(b)-1

    ans = 0
    flag = False
    for i in range(maxa, -1, -1):
        if flag:
            break
        for j in range(maxb, -1, -1):
            if a[i-1] + b[j] <= k:
                ans = i + j -1
                flag = True
            if a[i] + b[j-1] <= k:
                ans = i + j -1
                flag = True
            if a[i] + b[j] <= k:
                ans = i + j
                flag = True
            if flag:
                break
    print(ans)
            

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A_np = np.array(A)
B_np = np.array(B)

C_np = np.append(A_np,B_np)
C_np = np.sort(C_np)

x = 0
for i in range(len(C_np)):
    if K >= x + C_np[i]:
        x += 1
    else:
        break
print(x)

Submission status: Wrong Answer

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

a_i = 0
b_i = 0
time = 0
counter = 0

while time < k:
    if a_i >= len(a_list) and b_i < len(b_list):
        time += b_list[b_i]
        if time > k:
            break
        counter += 1
        b_i += 1
    elif b_i >= len(b_list) and a_i < len(a_list):
        time += a_list[a_i]
        if time > k:
            break
        counter += 1
        a_i += 1
    elif a_i >= len(a_list) and b_i >= len(b_list):
        break
    elif a_list[a_i] <= b_list[b_i]:
        time += a_list[a_i]
        if time > k:
            break
        counter += 1
        a_i += 1
    else:
        time += b_list[b_i]
        if time > k:
            break
        counter += 1
        b_i += 1

print(counter)

Submission status: Wrong Answer

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

i, j = 0, 0
suma, sumb = 0, 0
flaga, flagb = True, True

while True:
    if i < len(a):
        if k - suma >= a[i]:
            suma += a[i]
            i += 1
        else:
            flaga = False
    else:
        flaga = False

    if j < len(b):
        if k - sumb >= b[j]:
            sumb += b[j]
            j += 1
        else:
            flagb = False
    else:
        flagb = False
    if not flaga:
        if not flagb:
            break



maxbooks = 0
for x in range(i-1, -1, -1):
    for y in range(j-1, -1, -1):
        if sum(a[0:x+1]) + sum(b[0:y+1]) <= k:
            books = x + y + 2
            maxbooks = max(maxbooks, books)
    
print(maxbooks)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#N=int(input())
import numpy
N,M,K=map(int, input().split())
AList=list(map(int, input().split()))
BList=list(map(int, input().split()))

if sum(AList)+sum(BList)<=K:
    print(N+M)
    #print("aa")
    quit()
    

SUM=0
cnt=0
AI=0
BI=0
for i in range(N+M):
    if AI>=N:
        if BI<M and SUM+BList[BI]<=K:
            SUM+=BList[BI]
            #print("BListA",BList[BI],BI)
            BI+=1
            cnt+=1
        else:
            break
    elif BI>=M:
        if AI<N and SUM+AList[AI]<=K:
            SUM+=AList[AI]
            #print("AListB",AList[AI])
            AI+=1
            cnt+=1
        else:
            break
    else:
        if AI<N and AList[AI]<=BList[BI] and SUM+AList[AI]<=K:
            SUM+=AList[AI]
            #print("AListC",AList[AI])
            AI+=1
            cnt+=1
        elif BI<M and AList[AI]>=BList[BI] and SUM+BList[BI]<=K:
            SUM+=BList[BI]
            #print("BListD",BList[BI])
            BI+=1
            cnt+=1
        else:
            break
#print(SUM)
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))
def sub(l,k):
    res = 0
    for i in l:
        if k >= i:
            k -= i
            res += 1
        else:
            return k,res
    return k,res
        
def main(n,m,k,ln,lm):
    nk = sum(ln)
    mk = sum(lm)
    if k>=nk+mk:
        return n+m
    elif k>nk:
        ik, res = sub(lm, k-nk)
        res += n
        startn = n - 1
        startm = res - 1
    else:
        ik, res = sub(ln, k)
        startn = res - 1
        ik, res2 = sub(lm, ik)
        res += res2
        startm = res2
        
    ires = res
    for i in range(startn,-1,-1):
        ik += ln[i]
        ik, delta = sub(lm[startm:], ik)
        startm += delta
        ires = ires - 1 + delta
        res = max(res, ires)
    return res

print(main(n,m,k,ln,lm))

Submission status: Wrong Answer

Solution code:
m,n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = a + b
d = sorted(c)
count = 0
m = 0
for i in range(len(c)):
  if k >= count:
    count = count + c[i]
    m = m+1
  else:
    pass
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()))
result = -1

A.append(10**10)
B.append(10**10)
i,j = 0,0
while K >= 0:
    K -= min(A[i],B[j])
    if A[i] <= B[j]:
        i += 1
    else:
        j += 1
    result += 1
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.append(10**9 + 1)
B.append(10**9 + 1)
ans = 0
i = 0
j = 0

while K >= 0:
  if min(A[i],B[j]) <= K:
    ans += 1
    if A[i] > B[j]:
      K = K - B[j]
      j += 1
    elif B[j] > A[i]:
      K = K- A[i]
      i += 1
    elif A[i] == B[j]:
      K = K - A[i]
      i += 1
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import bisect


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N, M, K = LI()
    AArray = LI()
    BArray = LI()

    aSum = [AArray[0]]
    bSum = [BArray[0]]

    cnt = 0

    for i in range(1, N):
        aSum.append(aSum[i-1]+AArray[i])
    for i in range(1, M):
        bSum.append(bSum[i-1]+BArray[i])

    for i in range(N):
        a = aSum[i]
        if a > K:
            break
        if a == K:
            cnt = max(cnt, i+1)
            break
        sa = K-a
        b = bisect.bisect_right(bSum, sa)
        cnt = max(cnt, i+1+b)

    # while K > 0 and (len(AArray) > 0 or len(BArray) > 0):
    #     if len(AArray) > 0 and len(BArray) > 0:
    #         if AArray[0] >= BArray[0]:
    #             b = BArray.pop(0)
    #             if K-b >= 0:
    #                 K -= b
    #                 cnt += 1
    #             else:
    #                 break
    #         elif AArray[0] < BArray[0]:
    #             a = AArray.pop(0)
    #             if K-a >= 0:
    #                 K -= a
    #                 cnt += 1
    #             else:
    #                 break
    #     elif len(AArray) == 0:
    #         b = BArray.pop(0)
    #         if K-b >= 0:
    #             K -= b
    #             cnt += 1
    #         else:
    #             break
    #     else:
    #         a = AArray.pop(0)
    #         if K-a >= 0:
    #             K -= a
    #             cnt += 1
    #         else:
    #             break

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[0]
for i in a:
    c+=[c[-1]+i]
d=[0]
for i in b:
    d+=[d[-1]+i]
ans=j=0
for i in range(m):
    if d[i]>k:
        ans=j=i-1


for i in range(n+1):
    while c[i]+d[j]>k and c[i]<k:
        j-=1
    if c[i]+d[j]<=k:    
        ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Ac = list(itertools.accumulate(A))
Bc = list(itertools.accumulate(B))
print(Ac,Bc)
amax, bmax = 0, 0
for i in range(len(A)):
    if Ac[i] <= K:
        amax = i + 1
    else: break
if amax == 0:
    At = 0
else:
    At = Ac[amax - 1]
for i in range(len(B)):
    if Bc[i] + At <= K:
        bmax = i + 1
ans = amax + bmax
if amax > 0:
    for i in range(1, amax):
        anow = amax - i
        At = Ac[anow - 1]
        for j in range(bmax-1, len(B)):
            if Bc[j] + At <= K:
                bmax = j + 1
            ans = max(ans,anow+bmax)
if Bc[len(B)-1] <= K:
    ans = max(ans, len(B))
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()))
i=0
j=0
t=0
A.append(1000000001)
B.append(1000000001)
while t < K:
    if A[i]>B[j] and t+B[j]<K:
        t+=B[j]
        j+=1
    elif A[i]<B[j] and t+A[i]<K:
        t+=A[i]
        i+=1
    else:
      	break
print(i+j)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))+[0]
b=list(map(int,input().split()))+[0]
if n>m:
  b=b+[pow(10,9)]*(n-m)
elif n<m:
  a=a+[pow(10,9)]*(m-n)
i,j=0,0
for l in range(n+m):
    x=min(a[i],b[j])
    k-=x
    if k<0:
        print(l)
        exit()
    if k==0:
        print(l+1)
        exit()
    if a[i]==b[j]:
        if a[i+1]<b[j+1]:
            i+=1
        elif a[i+1]>b[j+1]:
            j+=1
    if i<n and x==a[i]:
        i+=1
    elif j<m and x==b[j]:
        j+=1
print(n+m)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
aes = list(map(int, input().split()))
bs = list(map(int, input().split()))
r_aes = [0]*n
for i in range(1,n):
    aes[i] += aes[i-1]
for i in range(1,m):
    bs[i] += bs[i-1]
cnt_a = 0
for i in range(n):
    if aes[i] > k:
        break
    cnt_a += 1
cnt_b = 0
res = 0
#cnt = 5
while True:
    #print("cnt_a: "+str(cnt_a))
    #print("cnt_b: " + str(cnt_b))
    if cnt_b >= m or bs[cnt_b] > k:
        break
    if k-aes[cnt_a-1]>=bs[cnt_b]:
        cnt_b += 1
        res = max(res,cnt_a+cnt_b)
        continue
    cnt_a -= 1
    if cnt_a < 0:
        break
    #if cnt<= 0:
        #break
print(res)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
import bisect

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

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

    Aacc = [0]+list(accumulate(A))
    Bacc = list(accumulate(B))

    m = 0

    # print(Aacc)
    # print(Bacc)

    for i in range(N+1):
        t = Aacc[i]
        if K-t <= 0:
            break
        j = bisect.bisect_right(Bacc, K-t)
        # print(i, j)
        m = max(m, i+j)

    print(m)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
An, Bn, t = [int(x) for x in stdin.readline().rstrip().split()]

A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]


idxA = 0
idxB = 0

cnt = 0

for i in range(An + Bn):
	if t < 0 : break

	if An > i :
		t -= A[idxA]
		cnt += 1
		if t < 0 : break
		idxA += 1

	if Bn > i :
		t -= B[idxB]
		cnt += 1
		if t < 0 : break
		idxB += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N,M,K = map(int,input().split())
    A = []*N
    B = []*M
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = [10**9+10]* (N+M)
    A2 = [0] * N
    B2 = [0] * M
    cnt = 0
    for i in range(N):
        if A[i] + A2[i-1] > K:
            break
        A2[i] = A[i] + A2[i-1]
        cnt += 1
    for i in range(M):
        B2[i] = B[i] + B2[i-1]
    MAX = cnt
    for i in reversed(range(cnt)):
        cnt_m = 0
        for j in range((MAX-cnt),M):
            if A2[i] + B2[j] > K:
                break
            cnt_m += 1
        MAX += cnt_m
    print(MAX)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

all_list = a_list + b_list
all_list.sort()

book_num = 0
time = 0

for book in all_list:
    time += book
    if time <= k:
        book_num += 1
    else:
        print(book_num)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    ans = 0
    total = 0
    anow = -1
    for a in A:
        if a + total <= K:
            ans += 1
            total += a
            anow += 1
        else:
            break
    maxans = ans
    for b in B:
        total += b
        while total > K:
            if anow == -1:
                break
            total -= A[anow]
            anow -= 1
            ans -= 1
        if anow == -1:
            break
        ans += 1
        maxans = max(maxans, ans)
    print(maxans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
la = deque(list(map(int, input().split())))
lb = deque(list(map(int, input().split())))

cnt = 0
while k >= 0:
    if la == deque([]):
        if lb == deque([]):
            break
        elif lb[0] <= k:
            k -= lb[0]
            cnt += 1
            lb.popleft()
        else:
            break
    elif lb == deque([]):
        if la[0] <= k:
            k -= la[0]
            cnt += 1
            la.popleft()
        else:
            break
    elif la[0] >= lb[0]:
        if lb[0] <= k:
            k -= lb[0]
            cnt += 1
            lb.popleft()
        else:
            break
    elif la[0] < lb[0]:
        if la[0] <= k:
            k -= la[0]
            cnt += 1
            la.popleft()
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

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

aa = [0] + list(itertools.accumulate(A))
bb = [0] + list(itertools.accumulate(B))

ans = 0
for i in range(N+1):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if tmp_K >= bb[-1]:
        ans = max(ans, i+M)
        continue

    mn = 0
    mx = M
    while True:
        if mn == mx:
            if tmp_K >= bb[mn]:
                ans = max(ans, i+mn)
            break

        mid = (mn+mx//2)
        if bb[mid] <= tmp_K:
            if mn == mid:
                mn = mid+1
            else:
                mn = mid
                if i+mn <= ans:
                    break
        else:
            if mx == mid:
                mx = mid-1
            else:
                mx = mid
print(ans)

Submission status: Wrong Answer

Solution code:

import numpy as np

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

cost = 0
cnt = 0

top_a = a.pop(0)
top_b = b.pop(0)

while True:
    cnt +=1

    if top_a > top_b:
        cost += top_b
        if cost > k:
            cnt -= 1
            break
        if len(b) != 0:
            top_b = b.pop(0)
        else:
            top_b = np.inf
    else:
        cost += top_a
        if cost > k:
            cnt -= 1
            break
        if len(a) != 0:
            top_a = a.pop(0)
        else:
            top_a = np.inf

    if top_a == np.inf and top_b == np.inf:
        break


print(cnt)

Submission status: Wrong Answer

Solution code:
info = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

N = list()
M = list()
N.append(A[0])
for i in range(1, info[0]):
  N.append(N[i-1]+A[i])
M.append(B[0])
for i in range(1, info[1]):
  M.append(M[i-1]+B[i])

flag = False
for i in range(info[0]-1, -1, -1):
  for j in range(info[1]-1, -1, -1):
    if N[i]+M[j] <= info[2]:
      print(i+j+2)
      flag = True
      break
  if flag:
    break
    
if not flag:
  print(0)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K=map(int, input().split())
AA=list(map(int,input().split()))
BB=list(map(int,input().split()))
CC=[10^9]*len(AA)
DD=[10^9]*len(BB)
CC[0]=AA[0]
for i in range(N-1):
    CC[i+1]=CC[i]+AA[i+1]
    if CC[i+1]>=K:
        break

ans=max(0, bisect.bisect_right(CC,K))
DD[0]=BB[0]
if DD[0]<=K:
	ans=max(ans, bisect.bisect_right(CC,K-DD[0])+1)
for i in range(M-1):
    DD[i+1]=DD[i]+BB[i+1]
    if DD[i+1]<=K:
	    ans=max(ans, bisect.bisect_right(CC,K-DD[i+1])+i+2)
    else:
    	break
print(ans)

Submission status: Wrong Answer

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

i, j = 0, 0
ans = 0
time = 0

for _ in range(m+n):
    s, t = a[i], b[j]

    mn = min(s, t)

    time += mn

    if time >= k:
        break

    if s <= t and i < n-1:
        i += 1
    if s > t and j < m-1:
    # else:
        j += 1

    ans += 1

# mn = min(a[0], b[0])
# k -= mn

# while time <= k:
#     # print(f'{i} {j}')
#     s, t = a[i], b[j]
    
#     mn = min(s, t)

#     if s <= t and i < n-1:
#         i += 1
#     if s > t and j < m-1:
#     # else:
#         j += 1

#     time += mn

#     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.extend(b)

time = 0
count = 0
for x in a:
  if time > k:
    break
  time += x
  count += 1
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()))
mx=n
mn=m
mxl=a
mnl=b
if m>n:
    mx=m
    mn=n
    mxl=b
    mnl=a
sm=0
counts=[]
i=0
while sm<=k and i<n:
    sm+=a[i]
    i+=1
counts.append(i)
sm=0
i=0
while sm<=k and i<m:
    sm+=b[i]
    i+=1
counts.append(i)
sm=0
i=0
for j in range(mx):
    if sm<=k:
        sm+=mxl[j]
        i+=1
    if sm<=k and j<mn:
        sm+=mnl[j]
        i+=1
counts.append(i)
print(max(counts))

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)
cnt = 0
ca = 0
cb = 0

for i in range(n + m):
    if a[ca] == b[cb] == 10**10:
        break
    if cnt < k:
        if a[ca] < b[cb]:
            cnt += a[ca]
            if cnt <= k:
                ca += 1
            else:
                print(ca + cb)
                exit()
        else:
            cnt += b[cb]
            if cnt <= k:
                cb += 1
            else:
                print(ca + cb)
                exit()
print(ca + cb)