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: Runtime Error

Solution code:
from sys import stdin
n,m,k = map(int, stdin.readline().rstrip().split())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))

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

for i in range(0,n):
    j = 0
    while A[i] + B[j+1] <= k:
        j += 1
    ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a = list(input().split())
a = [int(i) for i in a]
b = list(input().split())
b = [int(i) for i in b]
aa=a.copy()
aa.extend(b)
if sum(aa)<=k:
  print(n+m)
  exit()

#print(aa)
ai,bi=0,0
ans=0
for _ in range(n+m):
  #print(k, a[ai], b[bi], ai,bi)
  if k<= a[ai] and k<= b[bi]:
    print(ans)
    exit()
    
  if a[ai] <= b[bi]:
    k-=a[ai]
    ai+=1
    ans+=1
  else:
    k-=b[bi]
    bi+=1
    ans+=1
    
  if ai == len(a):
    a=[10*10]*10000
  if bi == len(b):
    b=[10*10]*10000
    
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a = list(input().split())
a = [int(i) for i in a]
b = list(input().split())
b = [int(i) for i in b]
aa=a.copy()
aa.extend(b)
if sum(aa)<=k:
  print(n+m)
  exit()

#print(aa)
ai,bi=0,0
ans=0
for _ in range(n+m):
  #print(k, a[ai], b[bi], ai,bi)
  if k<= a[ai] and k<= b[bi]:
    print(ans)
    exit()
    
  if a[ai] <= b[bi]:
    k-=a[ai]
    ai+=1
    ans+=1
  else:
    k-=b[bi]
    bi+=1
    ans+=1
    
  if ai == len(a):
    a=[10*9]*10000
  if bi == len(b):
    b=[10*9]*10000
    
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a = list(input().split())
a = [int(i) for i in a]
b = list(input().split())
b = [int(i) for i in b]
aa=a.copy()
aa.extend(b)
if sum(aa)<=k:
  print(n+m)
  exit()

#print(aa)
ai,bi=0,0
ans=0
for _ in range(n+m):
  #print(k, a[ai], b[bi])
  if k<= a[ai] and k<= b[bi]:
    print(ans)
    exit()
    
  if a[ai] <= b[bi]:
    k-=a[ai]
    ai+=1
    ans+=1
  else:
    k-=b[bi]
    bi+=1
    ans+=1
print(ans)

Submission status: Runtime Error

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

while m + A[0] < K or m + B[0] < K:
    if A[0] < B[0]:
        counter += 1
        m += A.pop(0)
    elif B[0] < A[0]:
        counter += 1
        m += B.pop(0)
    elif A[0] == B[0]:
        if m + A[0] + B[0] > K:
            counter += 1
            break
        counter += 2
        m += A.pop(0) + B.pop(0)

print(counter)

Submission status: Runtime Error

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**10)
b.append(10**10)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(a,b,0)
print(ans)

Submission status: Runtime Error

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      #a.popleft()
    else:
      time += b[0]
      #b.popleft()
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(a,b,0)
print(ans)

Submission status: Runtime Error

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      #time += a[0]
      a.popleft()
    else:
      #time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(a,b,0)
print(ans)

Submission status: Runtime Error

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
      cnt(a,b,time)

cnt(a,b,0)
print(ans)

Submission status: Runtime Error

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(a,b,0)
print(ans)

Submission status: Runtime Error

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(a,b,0)

Submission status: Runtime Error

Solution code:
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    A.append(10**9+1)
    B.append(10**9+1)
    ai = 0
    bi = 0
    ans = 0

    def compare(ai,bi):
        while A[ai]== B[bi]:
            ai += 1
            bi += 1
            if ai==N-1 or bi == M-1:
                break
        if A[ai]>B[bi] or ai>=N-1:
            x = 2
            return x
        elif A[ai]<B[bi]or bi >= M-1:
            x = 1
            return x
        
        

    while True:
        if K < A[ai] and K<B[bi]:
            break

        if A[ai]>B[bi]:
            K = K - B[bi]
            bi += 1
            ans += 1
        elif A[ai]<B[bi]:
            K = K - A[ai]
            ai += 1
            ans += 1
        elif A[ai]==B[bi]:
            if compare(ai,bi) == 1:
                while A[ai]== B[bi] and ai<=N-1 and K < A[ai]:
                    K = K - A[ai]
                    ai += 1
                    ans += 1
            elif compare(ai,bi) == 2:
                while A[ai]== B[bi] and bi<=M-1 and K < B[bi]:
                    K = K - B[bi]
                    bi += 1
                    ans += 1




    
    print(ans)

if __name__ == "__main__":
	main()

Submission status: Runtime Error

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

while m + A[0] < K or m + B[0] < K:
    if A[0] < B[0]:
        counter += 1
        m += A[0]
        A.remove(A[0])
    elif B[0] < A[0]:
        counter += 1
        m += B[0]
        B.remove(B[0])
    elif A[0] == B[0]:
        if m + A[0] + B[0] > K:
            counter += 1
            break
        counter += 2
        m += A[0]+B[0]
        A.remove(A[0])
        B.remove(B[0])

print(counter)

Submission status: Runtime Error

Solution code:
import sys

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ak=[]
aa=0
for i in a:
    aa+=i
    ak.append(aa)
bk=[]
bb=0
for i in b:
    bb+=i
    bk.append(bb)
ass=bs=0
for i in range(len(ak)):
    if ak[i]<=k:
        ass=i+1
    else:
        break
for i in range(len(bk)):
    if bk[i]+ak[ass-1]<=k:
        bs=i+1
    else:
        break
wk=ass+bs
aswk=ass
bswk=bs
if wk==n+m:
    print(n+m)
    sys.exit()

for i in range(ass-2,-1,-1):
    while k> ak[i]+bk[bswk]:
        bswk+=1
        if bswk<=m:
            break
an = max(ass+bs,i+bswk)        
        
print(an)

Submission status: Runtime Error

Solution code:
from bisect import *

N,M,K,*f = map(int, open(0).read().split())
A = f[:N]
B = f[N:]
a_read = 0
b_read = 0
passed = 0
csa = [0]
for i in range(N):
    csa.append(csa[i]+A[i])
csb = [0]
for i in range(M):
    csb.append(csb[i]+B[i])
for i in range(N+M):
    if a_read == N:
        bs = bisect_right(csb,K-csa[N])
        b_read = bs - 1
        break
    elif b_read == M:
        bs = bisect_right(csa,K-csb[M])
        b_read = bs - 1
        break
    else:
        if A[a_read] < B[b_read]:
            bs = bisect_right(csa,min(csa[a_read]+B[b_read],K-csb[b_read]))
            if bs <= a_read:
                break
            else:
                a_read = bs - 1
        elif A[a_read] > B[b_read]:
            bs = bisect_right(csb,min(csb[b_read]+A[a_read],K-csa[a_read]))
            if bs <= b_read:
                break
            else:
                b_read = bs - 1
        else:
            if K - csa[a_read] - csb[b_read] >= A[a_read]:
                for j in range(1,N+M):
                    if A[a_read+j] < B[a_read+j]:
                        if K - csa[a_read+j-1] - csb[b_read] >= A[a_read+j]:
                            a_read += j
                            break
                        else:
                            a_read += j - 1
                            break
                    elif A[a_read+j] > B[a_read+j]:
                        if K - csa[a_read] - csb[b_read+j-1] >= B[a_read+j]:
                            b_read += j
                            break
                        else:
                            b_read += j - 1
                            break
            else:
                break
print(a_read+b_read)

Submission status: Runtime Error

Solution code:
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    A.append(10**9+1)
    B.append(10**9+1)
    ai = 0
    bi = 0
    ans = 0

    def compare(ai,bi):
        while A[ai]== B[bi]:
            ai += 1
            bi += 1
            if ai==N-1 or bi == M-1:
                break
        if A[ai]>B[bi] or ai==N-1:
            x = 2
            return x
        elif A[ai]<B[bi]or bi == M-1:
            x = 1
            return x
        
        

    while True:
        if K < A[ai] and K<B[bi]:
            break

        if A[ai]>B[bi]:
            K = K - B[bi]
            bi += 1
            ans += 1
        elif A[ai]<B[bi]:
            K = K - A[ai]
            ai += 1
            ans += 1
        elif A[ai]==B[bi]:
            if compare(ai,bi) == 1:
                while A[ai]== B[bi] and ai<=N-1 and K < A[ai]:
                    K = K - A[ai]
                    ai += 1
                    ans += 1
            elif compare(ai,bi) == 2:
                while A[ai]== B[bi] and bi<=M-1 and K < B[bi]:
                    K = K - B[bi]
                    bi += 1
                    ans += 1




    
    print(ans)

if __name__ == "__main__":
	main()

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

"""
dp
time / books_no?
10 0 0
20 0 0
30 0 0
40 0 0
50 0 0
60 1 0
70 1 0
80 0 1




"""



N, M, K = LI()
A = LI()
B = LI()

a = [0 for i in range(2 * 10 ** 5)]
b = [0 for i in range(2 * 10 ** 5)]
a_sum = [0 for i in range(2 * 10**5)]
b_sum = [0 for i in range(2 * 10 ** 5)]

time = 0
sum_a = 0
for i in range(N):
    time += A[i]
    if time > 2 * 10 ** 5:
        break
    a[time] += 1

time = 0
for j in range(M):
    time += B[j]
    if time > 2 * 10 ** 5:
        break
    b[time] += 1

s_a = 0
s_b = 0
for time in range(2*10 **5):
    s_a += a[time]
    a_sum[time] = s_a
    s_b += b[time]
    b_sum[time] = s_b

ans = 0
for i in range(K):
    ans = max(ans, a_sum[i] + b_sum[K - i])
print(ans)

Submission status: Runtime Error

Solution code:
# coding:utf-8
import itertools
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
j = m

aa = [0] + list(itertools.accumulate(a))
bb = [0] + list(itertools.accumulate(b))
#print(aa)
#print(bb)


# しゃくとり法 / Aの山だけ読みつつ、そこにBからいくつ取り出すかで考える
for i, a_item in enumerate(a):
    if a_item > k:
        break
    while a_item + b[j] > k:
        j -= 1
    ans = max(i + j, ans)
print(ans)

Submission status: Runtime Error

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()
    l=[]
    while len(a) or len(b):
        if len(a) and len(b):
            l.append(min(a[0],b[0]))
            if min(a[0],b[0])==a[0]:
                a.pop(0)
            else:
                b.pop(0)
        elif len(a):
            l.append(a[0])
            a.pop(0)
        else:
            l.append(b[0])
            b.pop(0)
    #print(*l)
    c=0
    for i in range(n+m):
        c+=l[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: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a, b =[0],[0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
 
ans, j =0,M
for i in range(N+1):
  while b[j] > K-a[i]:
        j -= 1
  ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a, b =[0],[0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
 
ans, j =0,M
for i in range(N+1):
    while b[j] > K-a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

Solution code:
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: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

N,M,K=map(int,inp().split())
list_a=list(map(int,inp().split()))
list_b=list(map(int,inp().split()))


totaltame_a=[0]
for a in list_a:
    temp_a=totaltame_a[-1]+a
    if temp_a>K:
        break
    else:
        totaltame_a.append(temp_a)


totaltime_b=[0]
for b in list_b:
    totaltime_b.append(totaltime_b[-1]+b)

ans=0

for i in range (len(totaltame_a)):
    Kb=K-totaltame_a[i]
    j=bisect.bisect_right(totaltime_b,Kb)-1
    if i+j>ans:
        ans=i+j
    else:
        pass

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a,b=[0],[0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
ans=0
j=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: Runtime Error

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

Submission status: Runtime Error

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

while m + A[0] < K or m + B[0] < K:
    if A[0] < B[0]:
        counter += 1
        m += A[0]
        A.remove(A[0])
    elif B[0] < A[0]:
        counter += 1
        m += B[0]
        B.remove(B[0])

print(counter)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_right

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

##累積和のリストが得られる
a_cum = list(accumulate(a))
b_cum = list(accumulate(b))

ans = [0]
for i in range(n+1):    
    c = bisect_right(b, k-a[i]) - 1 
    if c != -1: 
        ans.append(c+i)
print(max(ans))

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_right

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

##累積和のリストが得られる
a_cum = list(accumulate(a))
b_cum = list(accumulate(b))

ans=[0]
for i in range(n+1):    #0~n+1
    c = bisect_right(b,k-a[i])-1 ##Aをi冊読んだ場合の残り時間 : k-a[i]  bisect_rightでbの累積時間の最大のインデックス(本の冊数)が求まる
                                 ##bisectは位置が求まるので、-1で冊数を求めている
    if c!=-1: #0から始まるので、冊数が0の場合は-1となってしまう
        ans.append(c+i)
print(max(ans))

Submission status: Runtime Error

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

time=0
cnt=0
a=[0]*(N+1)
b=[0]*(M+1)

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

for i in range(N+1):
    if a[i]<b[i]:
        time+=a[i]
        if time<=K:
            cnt+=1
        else:
            break
    else:
        time+=b[i]
        if time<=K:
            cnt+=1
        else:
            break
print(cnt)

Submission status: Runtime Error

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

time=0
cnt=0
a,b=[0],[0]

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

for i in range(N+1):
    if a[i]<b[i]:
        time+=a[i]
        if time<=K:
            cnt+=1
        else:
            break
    else:
        time+=b[i]
        if time<=K:
            cnt+=1
        else:
            break
print(cnt)

Submission status: Runtime Error

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

time=0
cnt=0
a,b=[0],[0]

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

for i in range(0,N+1):
    if a[i]<b[i]:
        time+=a[i]
        if time<=K:
            cnt+=1
        else:
            break
    else:
        time+=b[i]
        if time<=K:
            cnt+=1
        else:
            break
print(cnt)

Submission status: Runtime Error

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

time=0
cnt=0

for i in range(0,200000):
    if A[i]<B[i]:
        time+=A[i]
        if time<=K:
            cnt+=1
        else:
            break
    else:
        time+=B[i]
        if time<=K:
            cnt+=1
        else:
            break
print(cnt)

Submission status: Runtime Error

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):
  for idx in range(lim_b):
    if k >= cum_a[-l] + cum[idx]:
      ans = max(ans, lim_a - l + idx + 2)
print(ans)

Submission status: Runtime Error

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:
        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 == j:
            res.append(k+1+l+1)
            break

print(max(res))

Submission status: Runtime Error

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

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

	else:
		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: Runtime Error

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 True:
    if k >= cum_a[-l] + cum_b[idx]:
      ans = lim_a - l + idx + 2
    else:
      idx += 1
    idx += 1
print(ans)

Submission status: Runtime Error

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

while 1:
    if A[0] < B[0] or B == []:
        tmp = A[0]
        A = A[1:]
    elif A[0] >= B[0] or A == []:
        tmp = B[0]
        B = B[1:]
    else:
        pass
    if sum + tmp > K:
        break
    else:
        ans += 1
        sum += tmp

print(ans)

Submission status: Runtime Error

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]
for j in range(M-1):
    Bsum[0] = B[0]
    Bsum[i+1] = Bsum[i] + B[i+1]

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

print(max(res))

Submission status: Runtime Error

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

sum_AB = 0
cnt = 0
idx_A = -1
idx_B = -1
for i,a in enumerate(A):
  if sum_AB + a > K:
    break
  else:
    sum_AB += a
    cnt += 1
    idx_A = i
for i,b in enumerate(B):
  if sub_AB + b > K:
    break
  else:
    sum_AB += b
    cnt += 1
    idx_B = i
ans = cnt
A = [0:idx_A+1][::-1]
B = [idx_B:]
for a in A:
  sum_AB -= a
  cnt -= 1
  for b in B:
    if sum_AB + b > K:
      break
    else:
      sum_AB += b
      cnt += 1
  ans = max(cnt,ans)
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N,M,K=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    time,,time2,ans=k,k,0,0
    if time-A[0]<=0 or time-B[0]<=0:
        print("0")
        return 
        
    for i in range(1,max(N,M)):
        time-=A[i]
        time2-=B[i]
        if time<=0:
            time+=B[i-1]
            break
        elif time2<=0:
            time2+=A[i-1]
            break
        time-=B[i]
        time2-=A[i]
        if time<=0:
            time+=A[i-1]
            break
        elif time2<=0:
            time2+=B[i-1]
            break
    print(i-1)
    return 

main()

Submission status: Runtime Error

Solution code:
arr1=[]
arr2=[]
satu=0
num1,num2,time=map(int,input().split())
arr1+=map(int,input().split())
arr2+=map(int,input().split())
order1=0
order2=0


while time>=0:
    if order1<num1-1 or order2<num2-1:
        if arr1[order1]<arr2[order2]:
            time-=arr1[order1]
            order1+=1
            satu+=1
        elif arr1[order1]>arr2[order2]:
            time-=arr2[order2]
            order2+=1
            satu+=1
    else:break
print(satu)