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:
"""
    Satwik_Tiwari ;) .
    4th july , 2020  - Saturday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase


import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    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

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)


def bfs(g,st):
    visited = [-1]*(len(g))
    visited[st] = 0
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == -1):
                visited[i] = visited[s]+1
                queue.append(i)
    return visited


def dfsusingstack(v,st):
    d = deque([])
    visited = [0]*(len(v))
    d.append(st)
    new = []
    visited[st] = 1
    while(len(d) != 0):
        curr = d.pop()
        new.append(curr)
        for i in v[curr]:
            if(visited[i] == 0):
                visited[i] = 1
                d.append(i)
    return new

# 6
# 1 -1 2 3 -5 0
def solve():
    n,m,k = sep()
    a = lis()
    b = lis()
    
    # a = sorted(a)
    # b = sorted(b)

    i = 0
    j = 0
    cnt = 0
    while(i<n or j<m):
        if(i<n and j<m):
            if(k<a[i] and k<b[j]):
                break
            if(a[i]<b[j]):
                cnt+=1
                k-=a[i]
                i+=1
            else:
                cnt+=1
                k-=b[j]
                j+=1
            continue
        if(i>=n):
            if(k<b[j]):
                break
            cnt+=1
            k-=b[j]
            j+=1
            continue
        if(k<a[i]):
            break
        cnt+=1
        k-=a[i]
        i+=1

    # print(k)
    print(cnt)


testcase(1)
# testcase(int(inp()))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
total_time = 0
num = 0
i, j = 0, 0
while num < (n+m):
  if i == n and j < m:
    total_time = total_time + B[j]
    j += 1
  if j == m and i < n:
    total_time = total_time + A[i]
    i += 1
  if i < n and j < m:
    if A[i] <= B[j]:
      total_time = total_time + A[i]
      i += 1
    else:
      total_time = total_time + B[j]
      j += 1
  if total_time > k:
    break
  num += 1
print(num)

Submission status: Wrong Answer

Solution code:
import sys 
import numpy as np

def binarySearch_canread(data, target):
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]

    # 追加　全部読める場合と何も読めない場合
    if target > max(data):
        return len(data)
    elif target < min(data):
        return 0

    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None

    while imin <= imax:
        imid = imin + (imax - imin) // 2

        if imid + 1 < len(data):
            min_diff_right = abs(data[imid + 1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid - 1] - target)

        if min_diff_left < min_diff:
            min_diff = min_diff_left 
            closest_num = data[imid - 1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid + 1]

        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid - 1
        else:
            return list(data).index(data[imid]) + 1 # data[imid]

    # 何冊読めるかを返したい
    differ = target - closest_num
    can_read = None
    if differ > 0: # 読める時間（target）の方が大きい
        can_read = max([i for i, x in enumerate(data) if x == closest_num]) + 1
    elif differ < 0: # 読める時間の方が少ない
        can_read = min([i for i, x in enumerate(data) if x == closest_num])



    return can_read

if __name__ == '__main__':
    read = sys.stdin.buffer.read 
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines 

    N, M, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    B = np.array(readline().split(), np.int64)

    Acum = np.zeros(N+1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum = np.zeros(M+1, np.int64)
    Bcum[1:] = np.cumsum(B)

    # Aから1冊ずつ取っていく
    max_read = 0
    for i, cumNum in enumerate(Acum[1:]):
        if cumNum <= K:
            reading = i + 1 # 読んだ数
            limit = K - cumNum
            can_reading = reading + binarySearch_canread(Bcum[1:], limit)
            if (max_read < can_reading):
                max_read = can_reading

    print(max_read)

Submission status: Wrong Answer

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


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    A = [0 for i in range(len(a)+1)]
    B = [0 for i in range(len(b)+1)]
    A[0] = a[0]
    B[0] = b[0]

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

    index = m
    ans = [0]
    for i in range(len(a)+1):
        rest = k - A[i]
        if rest < 0:
            break

        while B[index] > rest:
            index -= 1

        ans.append(i + index)

    print(max(ans))


    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Wrong Answer

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


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    A = [0 for i in range(len(a))]
    B = [0 for i in range(len(b))]
    A[0] = a[0]
    B[0] = b[0]

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

    index = m-1
    ans = [0]
    for i in range(len(a)):
        rest = k - A[i]
        if rest < 0:
            break

        if index == -1:
            break

        while B[index] > rest:
            index -= 1
            if index == -1:
                break

        ans.append(i + index+2)

    print(max(ans))


    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()

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

if k < a[0] and k < b[0]:
    print(0)
    exit()

if sum(a) + sum(b) <= k:
    print(n+m)
    exit()

a_temp = a[0]
b_temp = b[0]
temp = 0
count = 0
hour = 0
i = 0
j = 0

while k > hour:

    count += 1
    if a_temp <= b_temp:
        hour += a_temp
        i += 1
        if i >= len(a):
            a_temp = 10**10
        else:
            a_temp = a[i]
    else:
        hour += b_temp
        j += 1
        if j >= len(b):
            b_temp = 10**10
        else:
            b_temp = b[i]
    if hour + a_temp > k and hour + b_temp > k:
        break
    #print(count,hour)

print(count)

Submission status: Wrong Answer

Solution code:
# ABC172 C
import sys
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)
    sys.exit()

ans = 0
for i in range(n+1):
    time = sum(A[:i])
    if time >= k:
        ans = max(i-1, ans)
        break
    j = 0
    while time <= k and j < m:
        time += B[j]
        j += 1

    count = i + (j-1)
    ans = max(count, ans)
#    print(i, j, count, ans, time)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

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

acc_a = [0]
for i in range(N):
    acc_a.append(acc_a[i] + A[i])

acc_b = [0]
for i in range(M):
    acc_b.append(acc_b[i] + B[i])

acc_a = numpy.array(acc_a)
acc_b = numpy.array(acc_b)

currentMax = 0
for j in range(M + 1):
    tB = acc_b[j]
    remain = K - tB
    # print('-----------')
    # print('Bを{0}冊読んだら，かかる時間は{1}分, 残り時間は{2}分'.format(j, tB, K - tB))
    if remain < 0:
        # print('時間切れで読める本なし')
        break

    print(numpy.where(acc_a < remain)[0])
    if len(numpy.where(acc_a < remain)[0]) != 0:
        readable = numpy.where(acc_a <= remain)[0][-1]

        # print('残り時間{0}分で読めるAの本は{1}冊'.format(remain, readable))
        # print('トータル{0}冊読める'.format(j + readable))
        currentMax = max(currentMax, j + readable)

print(currentMax)

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
time = 0
while time < K:
    if not A:
        ans += 1
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        time += A[0]
        A.pop(0)
    elif A[0] >= B[0] :
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(1,len(a)):
    a[i] += a[i-1]
for i in range(1,len(b)):
    b[i] += b[i-1]
ans = 0
for i in range(len(a)):
    d = k - a[i]
    if d < 0:
        break
    for j in range(len(b)):
        if d < b[j]:
            break
        if len(b)-1 == j:
            j += 1
    ans = max(ans,i+j+1)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
res = 0
output = 0
j = M
for i in range(N + 1):
  if K < a[i]:
    break
  else:
    res = K - a[i]
  #print(res)
  num = 0
  while b[j] > res:
    #print("b:",b[j])
    j -= 1
    # print(j)
  num = i + j 
  output = max(output, num)
print(num)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
res = 0
output = 0
for i in range(N + 1):
  if K < a[i]:
    break
  else:
    res = K - a[i]
  #print(res)
  num = 0
  j = 0
  while j <= M and b[j] <= res:
    #print("b:",b[j])
    j += 1
    # print(j)
  num = i + (j - 1)
  if output <= num:
    output = num
print(num)

Submission status: Wrong Answer

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

book_num = 0

sum_n = {-1: 0}
sum_m = {-1: 0}
for n in range(N):
    sum_n[n] = sum_n[n - 1] + A[n]
    if K < sum_n[n]:
        break
    if book_num < n + 1:
        book_num = n + 1
    for m in range(M):
        if m not in sum_m:
            sum_m[m] = sum_m[m - 1] + B[m]
        if K < sum_n[n] + sum_m[m]:
            break
        else:
            book_num = n + 1 + m + 1

print(book_num)

Submission status: Wrong Answer

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

c=0
s=0
x=0
y=0

for _ in range(0,n+m):
  if x<n and y<m:
    c+=1
#    print(n,m,x,y)
#    print(a[x],b[y],s)
    if a[x]<=b[y]:
      s+=a[x]
      x+=1
    else:
      s+=b[y]
      y+=1
  elif x>=n:
    s+=b[y]
    y+=1
  elif y>=m:
    s+=a[x]
    x+=1

  if s>k:
    c-=1
    break
  elif s==k:
    break
print(c)

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

def main():
    N, M, K = (int(i) for i in input().split())
    a = list(reversed([int(i) for i in input().split()]))
    b = list(reversed([int(i) for i in input().split()]))

    @lru_cache(None)
    def nbooks(budget, i, j):
        # the number of books you can read with budget
        # and book stacks a[:i+1] and b[:j+1]
        ab = -1 if i < 0 else budget - a[i]
        bb = -1 if j < 0 else budget - b[j]

        if ab < 0 and bb < 0:
            return 0

        # there is budget to read at least one of the books
        return 1 + max(
                nbooks(ab, i-1, j),
                nbooks(bb, i, j-1))

    max_books = nbooks(K, N-1, M-1)
    print(max_books, flush=True)
    return

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

def main():
    N, M, K = (int(i) for i in input().split())
    a = list(reversed([int(i) for i in input().split()]))
    b = list(reversed([int(i) for i in input().split()]))
    # a = [int(i) for i in input().split()]
    # b = [int(i) for i in input().split()]

    @lru_cache(None)
    def nbooks(budget, i, j):
        # the number of books you can read with budget
        # and book stacks a[:i+1] and b[:j+1]
        if budget < 0:
            return 0
        
        ab = -1 if i < 0 else budget - a[i]
        bb = -1 if j < 0 else budget - b[j]

        if ab < 0 and bb < 0:
            return 0

        return 1 + max(
                nbooks(ab, i-1, j),
                nbooks(bb, i, j-1))

    max_books = nbooks(K, N-1, M-1)
    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()))
 
ans = 0
time = 0
 
 
for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
tmp = 0
count_a = ans
 
for j in range(len(b)):
    time += b[j]
    tmp = count_a + j + 1
    while count_a > 0 & time > k:
        time -= a[count_a - 1]
        count_a -= 1
        tmp -= 1
    if time > k:
        tmp = j
        if tmp > ans:
            ans = tmp
        break
    else:
        tmp = count_a + j + 1
    if tmp > ans:
        ans = tmp
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()))
 
ans = 0
time = 0
 
 
for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
tmp = 0
count_a = ans
 
for j in range(len(b)):
    time += b[j]
    tmp = count_a + j + 1
    if time > k:
        while count_a > 0 & time > k:
            time -= a[count_a]
            count_a -= 1
            tmp -= 1
        if time > k:
            tmp = j
            if tmp > ans:
                ans = tmp
            break
        else:
            tmp = count_a + j + 1
            if tmp > ans:
                ans = tmp
    else:
        if tmp > ans:
            ans = tmp
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()))

c = a+b
c.sort()
for i in range(1, n+m):
    c[i] += c[i-1]
for i in range(n+m):
    if c[i] > k:
        print(i)
        break
else:
    print(n+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
time = 0
 
 
for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
tmp = 0
count_a = ans
 
for j in range(len(b)):
    time += b[j]
    tmp = count_a + j + 1
    if time > k:
        while count_a > 0 & time > k:
            time -= a[count_a]
            count_a -= 1
            tmp -= 1
        if time > k:
            tmp = j
            if tmp > ans:
                ans = tmp
            break
        else:
            tmp = count_a + j + 1
            if tmp > ans:
                ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
n,m,k = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))

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

x,j = 0,m
for i in range(n+1):
    if a[i]>k:
        break
    while b[j] > k-a[i]:
        j -=1
    x = max(x,i+j)
print(x)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
n,m,k = map(int,input().split())
a = deque(list(map(int,input().split())))
b = deque(list(map(int,input().split())))
a.append(np.inf)
b.append(np.inf)

x = 0
cnt = 0
while True:
    if x+min(a[0],b[0])>k:break
    if a[0]<b[0]:
        x += a.popleft()
    else:
        x += b.popleft()
    cnt += 1
print(cnt)

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

d = [0]*(len(a)+len(b))
a_i,b_i = 0,0
for i in range(len(a)+len(b)):
    if a[a_i]<b[b_i]:
        d[i] = a[a_i]
        a_i+=1
    else:
        d[i] = b[b_i]
        b_i+=1
    if a_i>=len(a):
        for j in range(len(a)+len(b)-i-1):
            d[i+j+1] = b[b_i]
            b_i+=1
        break
    if b_i>=len(b):
        for j in range(len(a)+len(b)-i-1):
            d[i+j+1] = a[a_i]
            a_i+=1
        break

x = 0
cnt = 0
i=0
while True:
    if i>=len(d):break
    if x+d[i]>k:break
    cnt+=1
    x+=d[i]
    i+=1
print(cnt)

Submission status: Wrong Answer

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

for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
tmp = 0
count_a = ans
 
for j in range(len(b)):
    time += b[j]
    if time > k:
        while count_a > 0 & time > k:
            time -= a[count_a]
            count_a -= 1
        if time > k:
            tmp = j
        else:
            tmp = count_a + j + 1
    else:
        tmp = count_a + j + 1
    if tmp > ans :
        ans = tmp
    
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()))
ans = 0

a_sum = [0]
for i, minute in enumerate(a):
        a_sum.append(a_sum[i]+minute)
b_sum = [0]
for i, minute in enumerate(b):
        b_sum.append(b_sum[i]+minute)

B = m
ans_list = []

for i, a_time in enumerate(a_sum):
        if a_time > k:
                ans_list.append(i-1) #手前のやつなので加えてOK
                break
        for j in b_sum[::-1]:
                if j <= k-a_time:
                        ans_list.append(i+B)
                        break
                elif j > k-a_time:
                        B -= 1
print(max(ans_list))

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
time = 0
 
 
for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
tmp = 0
count_a = ans
 
for j in range(len(b)):
    time += b[j]
    if time > k:
        while count_a > 0 & time > k:
            time -= a[count_a]
            count_a -= 1
        if time > k:
            tmp = 0
        else:
            tmp = count_a + j + 1
    else:
        tmp = count_a + j + 1
    if tmp > ans :
        ans = tmp
    
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()))
ans = 0

a_sum = [0]
for i, minute in enumerate(a):
        a_sum.append(a_sum[i]+minute)
b_sum = [0]
for i, minute in enumerate(b):
        b_sum.append(b_sum[i]+minute)

B = m
ans_list = []

for i, a_time in enumerate(a_sum):
        if a_time > k:
                ans_list.append(i-1) #手前のやつなので加えてOK
                break
        for j in b_sum[::-1]:
                if j <= k-a_time:
                        ans_list.append(i+B)
                        break
                elif j > k-a_time:
                        B -= 1
print(ans_list)

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

a_sum = [0]
for i, minute in enumerate(a):
        a_sum.append(a_sum[i]+minute)
b_sum = [0]
for i, minute in enumerate(b):
        b_sum.append(b_sum[i]+minute)

B = m
ans_list = []

for i, a_time in enumerate(a_sum):
        if a_time > k:
                ans_list.append(i)
                continue
        for j in b_sum[::-1]:
                if j <= k-a_time:
                        ans_list.append(i+B)
                        break
                elif j > k-a_time:
                        B -= 1

print(max(ans_list))

Submission status: Wrong Answer

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

i = 0
j = 0

flag = 0
yonda = []
while k >= 0:
    if i == len(Ai) and j == len(Bi):
        flag = 1
        break
    elif j == len(Bi):
        k -= Ai[i]
        yonda.append(Ai[i])
        i += 1
    elif i == len(Ai):
        k -= Bi[j]
        yonda.append(Bi[j])
        j += 1
    else:
        if Ai[i] >= Bi[j]:
            k -= Bi[j]
            yonda.append(Bi[j])
            j += 1
        else:
            k -= Ai[i]
            yonda.append(Ai[i])
            i += 1
if flag == 0:
    print(len(yonda)-1)
else:
    print(len(yonda))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from itertools import accumulate
N, M, K = mapint()
As = list(accumulate(list(mapint())))
Bs = list(accumulate(list(mapint())))
from bisect import bisect_left

ans = 0
for i, a in enumerate(As, 1):
    if a>K:
        break
    idx = bisect_left(Bs, K-a)
    ans = max(ans, i+idx)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from itertools import accumulate
N, M, K = mapint()
As = list(accumulate(list(mapint())))
Bs = list(accumulate(list(mapint())))
from bisect import bisect_right

ans = 0
for i, a in enumerate(As, 1):
    if a>K:
        break
    idx = bisect_right(Bs, K-a)
    ans = max(ans, i+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()))

c=0
s=0
x=0
y=0

for _ in range(0,n+m):
#  print(_)
  if x<n and y<m:
#    print(n,m,x,y)
#    print(a[x],b[y],s)
    if a[x]<=b[y]:
      s+=a[x]
      c+=1
      x+=1
    else:
      s+=b[y]
      c+=1
      y+=1
  elif x>=n:
    s+=b[y]
    c+=1
    y+=1
  elif y>=m:
    s+=a[x]
    c+=1
    x+=1
  if s>k:
    c-=1
    break
print(c)

Submission status: Wrong Answer

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

time = 0
count = -1
saidaicho = len(A) + len(B)
while time <= K:
    time += max(A[0], B[0])
    count += 1

    if A[0] > B[0]:
        A.pop(0)
    else:
        B.pop(0)

    if len(A) == 0:
        A.append(0)
    elif len(B) == 0:
        B.append(0)

    if count == saidaicho:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
b = [0]
for x in input().split():
    b.append(b[-1] + int(x))

res = 0
a_ = 0
for i in range(n+1):
    a_ += a[i]
    b_max = k - a_
    b_num = bisect.bisect(b, b_max) - 1
    res = max(res, i + b_num)

print(res)