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:
"""
// Author : snape_here - Susanta Mukherjee
     
 """
 
from __future__ import division, print_function
 
import os,sys
from io import BytesIO, IOBase
 
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
 
 
def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
 
 
def read():
    sys.stdin = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 

def isPrime(n):
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
    return True

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

mod=1000000007

from math import *

import bisect

from decimal import *

getcontext().prec = 50

abc="abcdefghijklmnopqrstuvwxyz"

pi=3.141592653589793238

def main():

    n,m,k=mi()
    a=li()
    b=li()
    a.extend(b)
    a.sort()
    c=0 
    ans=n+m
    for i in range(n+m):
        c+=a[i]
        if c>k:
            ans=i
            break
    print(ans)


# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
 
 
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
 
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
 
if __name__ == "__main__":
    #read()
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
A=deque()
B=deque()
for i in list(map(int,input().split())):
    A.append(i)
for i in list(map(int,input().split())):
    B.append(i)

ans=[]
goukei=0
cnt=0
while True:
    if not A and not B:
        break
    else:
        if not A:
            ans.append(B[0])
            goukei+=B.popleft()
        elif not B:
            ans.append(A[0])
            goukei+=A.popleft()
        else:
            if A[0]>B[0]:
                ans.append(B[0])
                goukei+=B.popleft()
            else:
                ans.append(A[0])
                goukei+=A.popleft()
    if k>goukei:
        cnt+=1
    else:
        break
#print(ans)
#print(goukei)
print(cnt)

Submission status: Wrong Answer

Solution code:
ans=0

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

r=0

for l in range(n):
    if x>k:
        x-=a.pop()
        z-=1
        continue
    else:
        while r<m and x+b[r]<=k:
            x+=b[r]
            r+=1
            z+=1
        ans=max(z,ans)
        #show(a,z,r)
        x-=a.pop()
        z-=1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
A=deque()
B=deque()
for i in list(map(int,input().split())):
    A.append(i)
for i in list(map(int,input().split())):
    B.append(i)

ans=[]
goukei=0
cnt=0
while True:
    if not A and not B:
        break
    else:
        if not A:
            ans.append(B[0])
            goukei+=B.popleft()
        elif not B:
            ans.append(A[0])
            goukei+=A.popleft()
        else:
            if A[0]>B[0]:
                ans.append(B[0])
                goukei+=B.popleft()
            else:
                ans.append(A[0])
                goukei+=A.popleft()
    if k>=goukei:
        cnt+=1
    else:
        break
#print(ans)
#print(goukei)
print(cnt)

Submission status: Wrong Answer

Solution code:
ans=0

n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
x=sum(a)
z=n

r=0

for l in range(n):
    
        while r<m and x+b[r]<=k:
            x+=b[r]
            r+=1
            z+=1
        if x<=k:ans=max(z,ans)
        #show(a,z,r)
        x-=a.pop()
        z-=1

while r<m and x+b[r]<=k:
    x+=b[r]
    r+=1
    z+=1
ans=max(z,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
ans=0

n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
x=sum(a)
z=n

r=0

for l in range(n):
    
        while r<m and x+b[r]<=k:
            x+=b[r]
            r+=1
            z+=1
        ans=max(z,ans)
        #show(a,z,r)
        x-=a.pop()
        z-=1

while r<m and x+b[r]<=k:
    x+=b[r]
    r+=1
    z+=1
ans=max(z,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
ans=0

n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
x=sum(a)
z=n

r=0

for l in range(n):
    if x>k:
        x-=a.pop()
        z-=1
        continue
    else:
        while r<m and x+b[r]<=k:
            x+=b[r]
            r+=1
            z+=1
        ans=max(z,ans)
        #show(a,z,r)
        x-=a.pop()
        z-=1

while r<m and x+b[r]<=k:
    x+=b[r]
    r+=1
    z+=1
ans=max(z,ans)

print(ans)

Submission status: Wrong Answer

Solution code:

ans=0

n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
x=sum(a)
z=n

r=-1

for l in range(n):
    if x>k:
        x-=a.pop()
        z-=1
        continue
    else:
        while r<m and x+b[r]<=k:
            x+=b[r]
            r+=1
            z+=1
        ans=max(z,ans)
        #show(a,z,r)
        x-=a.pop()
        z-=1

while r<m and x+b[r]<=k:
    x+=b[r]
    r+=1
    z+=1
ans=max(z,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    As = [0]*(N+1)
    Bs = sum(B)
    As[0] = 0
    for i in range(1,N):
        As[i] = As[i-1] + A[i-1]
    T = K
    j = M 
    ans = 0
    for i in range(N):
        T = K - A[i]
        if T < 0:
            break
        while Bs > T:
            j -= 1
            Bs -= B[j]
        ans = max(ans, i+j+1)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ans=0

n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))
x=sum(a)
z=n

r=0

for l in range(n):
    if x>k:
        x-=a.pop()
        z-=1
        continue
    else:
        while r<m and x+b[r]<=k:
            x+=b[r]
            r+=1
            z+=1
        ans=max(z,ans)
        #show(a,z,r)
        x-=a.pop()
        z-=1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect
    from itertools import accumulate

    import sys
    input = sys.stdin.readline

    n, m, k = map(int, input().split())
    a = list(accumulate([0] + list(map(int, input().split()))))
    b = list(accumulate([0] + list(map(int, input().split()))))

    i1 = max(0, bisect(a, k) - 1)
    j1 = max(0, bisect(b, k - a[i1]) - 1)
    i2 = max(0, bisect(b, k) - 1)
    j2 = max(0, bisect(a, k - b[i2]) - 1)

    print(max(i1 + j1, i2 + j2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect
    from itertools import accumulate

    import sys
    input = sys.stdin.readline

    n, m, k = map(int, input().split())
    a = list(accumulate([0] + list(map(int, input().split()))))
    b = list(accumulate([0] + list(map(int, input().split()))))

    i1 = bisect(a, k) - 1
    j1 = bisect(b, k - a[i1]) - 1
    i2 = bisect(b, k) - 1
    j2 = bisect(a, k - b[i2]) - 1

    print(max(i1 + j1, i2 + j2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    Bs = sum(B)
    T = K
    j = M-1 
    ans = 0
    for i in range(N):
        T -= A[i]
        if T < 0:
            continue
        while Bs > T:
            Bs -= B[j]
            j -= 1
        ans = max(ans, i+j+2)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M ,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = list(map(int,input().split()))
newList = []
z = 0
while True:
    if z < len(A):
        newList.append(A[z])
    if z < len(B):
        newList.append(B[z])
    z += 1
    if (z > len(A)) and (z > len(B)):
        break

while K >= 0:
    if newList[0] > K:
        break
    K = K - newList[0]
    newList.pop(0)
    if len(newList) == 0:
        break



print((N+M) - len(newList))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    Bs = sum(B)
    T = K
    j = M-1 
    ans = 0
    for i in range(N):
        T -= A[i]
        if T < 0:
            break
        while Bs > T:
            Bs -= B[j]
            j -= 1
        ans = max(ans, i+j+2)
    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()))

sa = [0 for i in range(n+1)]
sb = [0 for i in range(m+1)]

c = 0

for i in range(n):
  c += a[i]
  sa[i+1] = c
c = 0
for i in range(m):
  c += b[i]
  sb[i+1] = c
ans = 0
if k >= sum(a)+sum(b):
  print (n+m)
  exit()
for i in range(n):
  x = k - sa[i]
  if x < 0:
    continue
  y = bisect.bisect_left(sb,x)
  # print (x,y,i)
  y += i  
  ans = max(ans, y-1)
print (ans)

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()))
ls = an[::-1] + bn
l = 0
r = n
s = sum(an)
ans = 0
while r < n + m and l < n:
    if s <= k:
        ans = max(ans, r - l)
        s += ls[r]
        r += 1
    else:
        s -= ls[l]
        l += 1
if s <= k:
    ans = max(ans, r-l)
print(ans)

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()))
ls = an[::-1] + bn
l = 0
r = n
s = sum(an)
ans = 0
while r < n + m:
    if s <= k:
        ans = max(ans, r - l)
        s += ls[r]
        r += 1
    else:
        s -= ls[l]
        l += 1
if s <= k:
    ans = max(ans, r-l)
print(ans)

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()))
ls = an[::-1] + bn
l = 0
r = 0
s = 0
ans = 0
while r < n + m:
    if s <= k:
        ans = max(ans, r - l)
        s += ls[r]
        r += 1
    else:
        s -= ls[l]
        l += 1
if s <= k:
    ans = max(ans, r-l)
print(ans)

Submission status: Wrong Answer

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

time = 0
books = 0
a_index = 0
b_index = 0

for i in range(1, n + 1):
  if time + a[i] <= k:
    time += a[i]
    books += 1
    a_index = i

for i in range(1, m + 1):
  if time + b[i] <= k:
    time += b[i]
    books += 1
    b_index = i

max_books = books

for i in range(a_index, 0, -1):
  time -= a[i]
  books -= 1
  for j in range(b_index + 1, m + 1):
    if time + b[j] <= k:
      time += b[j]
      books += 1
      b_index = j
      max_books = max(max_books, books)

print(max_books)

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()))
r=0
x=sum(B)
y=M-1
for i in range(N):
    x+=A[i]
    while x>K and y>=0:
        x-=B[y]
        y-=1
    if x<=K:
        r=max(r,i+y+2)
print(r)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0
    Amax = bisect_left(As, K)
    Bmax = bisect_left(Bs, K)

    for i in range(Amax):
        for j in range(Bmax):
            if As[i] + Bs[j] > K:
                break
            count = max(count, (i+j))

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    As = [0]
    for a in A:
        As.append(As[-1]+a)

    Bs = [0]
    for b in B:
        Bs.append(Bs[-1]+b)

    count = 0
    Amax = bisect_left(As, K)
    Bmax = bisect_left(Bs, K)

    for i in range(Amax):
        for j in range(Bmax):
            if As[i] + Bs[j] > K:
                break
            count = max(count, (i+j))

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a = deque(a)
b = deque(b)
al = 1
bl = 1
ans = 0
total_min = 0


while True:
    if not len(a):
        al = 0
    if not len(b):
        bl = 0
    if al and bl and total_min + a[0] <= total_min + b[0] <= k:
        total_min += a.popleft()
        ans += 1
    elif al and bl and total_min + b[0] <= total_min + a[0] <= k:
        total_min += b.popleft()
        ans += 1
    elif bl and total_min + b[0] <= k:
        total_min += b.popleft()
        ans += 1
    elif al and total_min + a[0] <= k:
        total_min += a.popleft()
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

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

#output
from collections import deque
answer = 0
acc_sum = 0
a = deque(a)
b = deque(b)

for i in range(n+m+1):
    if a and b:
        if a[0] < b[0]:
            temp = a.popleft()
            acc_sum += temp
            if acc_sum > k:
                break
            else:
                answer += 1
        else:
            temp = b.popleft()
            acc_sum += temp
            if acc_sum > k:
                break
            else:
                answer += 1
    elif not a and b:
        temp = b.popleft()
        acc_sum += temp
        if acc_sum > k:
            break
        else:
            answer += 1
    elif a and not b:
        temp = a.popleft()
        acc_sum += temp
        if acc_sum > k:
            break
        else:
            answer += 1
        
print(answer)

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()))
T = 0
c = 0

for i in range(n+1):
    for j in range(m+1):
        t = sum(a[:i]) + sum(b[:j])
        if T <= t <= k and c < i+j:
            T = t
            c = i+j
            break

print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque

# N, M, K = map(int, input().split())
# A = deque(map(int, input().split()))
# B = deque(map(int, input().split()))
N, M, K = map(int, "3 4 1000000000".split())
A = deque(map(int, "600000000 90 120".split()))
B = deque(map(int, "800000000 150 80 150".split()))

result = 0

while (A != deque() and K >= A[0]) or (B != deque() and K >= B[0]):
    a, b = 0, 0
    na, nb = 0, 0
    for i in A:
        if a+i <= K:
            a += i
            na += 1
        else:
            break
    for i in B:
        if b+i <= K:
            b += i
            nb += 1
        else:
            break


    if na > nb:
        result += 1
        na -= 1
        K -= A.popleft()
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.popleft()
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.popleft()
        else:
            nb -= 1
            K -= B.popleft()
print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque

def tsundoku(A, B, K):
    count = 0
    while K >= 0:
        if len(A) > 0 and len(B) > 0:
            if A[0] < B[0]:
                K -= A.popleft()
            else:
                K -= B.popleft()
        elif len(A) == 0 and len(B) > 0:
            K -= B.popleft()
        elif len(A) > 0 and len(B) == 0:
            K -= A.popleft()
        else:
            break
        if K >=0:
            count += 1

    return count




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

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
# N, M, K = map(int, "3 4 730".split())
# A = deque(map(int, "60 90 120".split()))
# B = deque(map(int, "80 150 80 150".split()))

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in A:
    if a+i <= K:
        a += i
        na += 1
    else:
        break
for i in B:
    if b+i <= K:
        b += i
        nb += 1
    else:
        break

while (A != deque() and K >= A[0]) or (B != deque() and K >= B[0]):
    if na > nb:
        result += 1
        na -= 1
        K -= A.popleft()
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.popleft()
    elif na == nb:
        result += 1
        if A == deque():
            nb -= 1
            K -= B.popleft()
        elif B == deque():
            na -= 1
            K -= A.popleft()
        else:
            if A[0] <= B[0]:
                na -= 1
                K -= A.popleft()
            else:
                nb -= 1
                K -= B.popleft()

print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in A:
    if a+i <= K:
        a += i
        na += 1
    else:
        break
for i in B:
    if b+i <= K:
        b += i
        nb += 1
    else:
        break

while A != deque() and K >= A[0] or B != deque() and K >= B[0]:
    if na > nb:
        result += 1
        na -= 1
        K -= A.popleft()
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.popleft()
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.popleft()
        else:
            nb -= 1
            K -= B.popleft()

print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in range(len(A)):
    if a+A[i] <= K:
        a += A[i]
        na += 1
    else:
        break
for i in range(len(B)):
    if b+B[i] <= K:
        b += B[i]
        nb += 1
    else:
        break

while A != deque() and K >= A[0] or B != deque() and K >= B[0]:
    if na > nb:
        result += 1
        na -= 1
        K -= A.popleft()
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.popleft()
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.popleft()
        else:
            nb -= 1
            K -= B.popleft()

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()))
timer = 0
cnt = 0
def append_float(tg_list):
  if len(tg_list) == 0:
    tg_list.append(float('inf'))
  return tg_list
while timer <= k:
  a = append_float(a)
  b = append_float(b)
  min_pop = min(a[0], b[0])
  if min_pop == a[0]:
    timer += a.pop(0)
    cnt += 1
  elif min_pop == b[0]:
    timer += a.pop(0)
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    #output
    from collections import deque
    answer = 0
    acc_sum = 0
    a = deque(a)
    b = deque(b)

    for i in range(n+m):
        if a and b:
            if a[0] < b[0]:
                temp = a.popleft()
                acc_sum += temp
                if acc_sum > k:
                    break
                else:
                    answer += 1
            else:
                temp = b.popleft()
                acc_sum += temp
                if acc_sum > k:
                    break
                else:
                    answer += 1
        elif not a and b:
            temp = b.popleft()
            acc_sum += temp
            if acc_sum > k:
                break
            else:
                answer += 1
        elif a and not b:
            temp = a.popleft()
            acc_sum += temp
            if acc_sum > k:
                break
            else:
                answer += 1
            
    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

ans = 0
for i, va in enumerate(a):
    if va > K:
        break
    j = M
    while va + b[j] < K:
        #print(va, b[j], ans)
        j -= 1
        if j < 0:
            break
    ans = max(i+j, 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()))
Asum = [0] * N
Bsum = [0] * M
res = [0]
Aend = 9999999
Bend = 9999999

for i in range(N-1):
    Asum[0] = A[0]
    Asum[i+1] = Asum[i] + A[i+1]
    if Asum[i+1] > K:
        Aend = i
        break    
for j in range(M-1):
    Bsum[0] = B[0]
    Bsum[j+1] = Bsum[j] + B[j+1]
    if Bsum[j+1] > K:
        Bend = j
        break


for k in range(N):
    for l in range(M):
        if (Asum[k] + Bsum[l]) > K:
            res.append(k+1+l-1+1)
            break
        elif (Asum[k] + Bsum[l]) == K:
            res.append(k+1+l+1)
            break
        elif l == Bend:
            res.append(k+l)
            break

print(max(res))

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()))
Asum = [0] * N
Bsum = [0] * M
res = [0]
Aend = 9999999
Bend = 9999999

for i in range(N-1):
    Asum[0] = A[0]
    Asum[i+1] = Asum[i] + A[i+1]
    if Asum[i+1] > K:
        Aend = i
        break    
for j in range(M-1):
    Bsum[0] = B[0]
    Bsum[j+1] = Bsum[j] + B[j+1]
    if Bsum[j+1] > K:
        Bend = j
        break


for k in range(N):
    for l in range(M):
        if (Asum[k] + Bsum[l]) > K:
            res.append(k+1+l-1+1)
            break
        elif (Asum[k] + Bsum[l]) == K:
            res.append(k+1+l+1)
            break
        elif l == Bend:
            res.append(k+1+l+1)
            break

print(max(res))

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()))
cum_a = []
total = 0
for i in range(n):
  total += a[i]
  if total > k:
    break
  cum_a.append(total)
  
cum_b = []
total = 0
for j in range(m):
  total += b[j]
  if total > k:
    break
  cum_b.append(total)
lim_a = len(cum_a)
lim_b = len(cum_b)
ans = lim_a
for l in range(1, lim_a + 1):
  for idx in range(lim_b):
    if k >= cum_a[-l] + cum_b[idx]:
      ans = max(ans, lim_a - l + idx + 2)
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()))
Asum = [0] * N
Bsum = [0] * M
res = [0]

for i in range(N-1):
    Asum[0] = A[0]
    Asum[i+1] = Asum[i] + A[i+1]
    if Asum[i+1] > K:
        break    
for j in range(M-1):
    Bsum[0] = B[0]
    Bsum[j+1] = Bsum[j] + B[j+1]
    if Bsum[j+1] > K:
        break


for k in range(N):
    for l in range(M):
        if (Asum[k] + Bsum[l]) > K:
            res.append(k+1+l-1+1)
            break
        elif (Asum[k] + Bsum[l]) == K:
            res.append(k+1+l+1)
            break
        elif l == M-1:
            res.append(k+1+l+1)
            break

print(max(res))

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()))
cum_a = []
total = 0
for i in range(n):
  total += a[i]
  if total > k:
    break
  cum_a.append(total)
  
cum_b = []
total = 0
for j in range(m):
  total += b[j]
  if total > k:
    break
  cum_b.append(total)
lim_a = len(cum_a)
lim_b = len(cum_b)
idx = 0
ans = lim_a
for l in range(1, lim_a + 1):
  while idx < lim_b:
    if k >= cum_a[-l] + cum_b[idx]:
      ans = max(ans, lim_a - l + idx + 2)
    else:
      break
    idx += 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()))
j = 0
l = 0
c = 0
ans = 0
for i in range(n*k):
	if j >= n and l >=m:
		#print("test3")
		break

	if l >= m:
		#print("test1")
		if  k >= c+a[j]:
			c += a[j]
			j += 1
			ans +=1
		else:
			break

	elif j >= n:
		#print("test2")
		if k >= c + b[l]:
			c += b[l]
			l += 1
			ans +=1
		else:
			break

	else:
		#print("{} {}".format(j,l))
		if a[j] > b[l]:
			if k >= c + b[l]:
				c += b[l]
				l += 1
				ans +=1
			else:
				break

		else:
			if  k >= c+a[j]:
				c += a[j]
				j += 1
				ans +=1
			else:
				break
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()))

# print(K)
# print(a)
# print(b)
# N,M=3,4
# K=730
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0

accum_a=np.cumsum(a)
accum_a=accum_a[accum_a <K]
accum_a=np.append(accum_a,K)
accum_a=np.insert(accum_a,0,0)

accum_b=np.cumsum(b)

ans=0
# print(accum_a)
# print(accum_b)
# print(len(accum_a))


for j in range (len(accum_a)-1):
    Kb=K-accum_a[j]
    _accum_b=accum_b
    _accum_b=np.append(_accum_b,Kb)
    _accum_b1=np.sort(_accum_b)
    bookb=np.where(_accum_b1==Kb)
    bookb=np.amax(bookb)

    if j+bookb>ans:
        ans=j+bookb
    else:
        pass

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()))
cum_a = []
total = 0
for i in range(n):
  total += a[i]
  if total > k:
    break
  cum_a.append(total)
  
cum_b = []
total = 0
for j in range(m):
  total += b[j]
  if total > k:
    break
  cum_b.append(total)
lim_a = len(cum_a)
lim_b = len(cum_b)
idx = 0
ans = lim_a
for l in range(1, lim_a + 1):
  while idx < lim_b:
    if k >= cum_a[-l] + cum_b[idx]:
      ans = lim_a - l + idx + 2
    else:
      idx += 1
      break
    idx += 1
print(ans)