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:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M, K = map(int, readline().split())
A = list(map(int, readline().split()))[::-1]
B = list(map(int, readline().split()))[::-1]

tot = 0
cnt = 0

while True:
    if len(A) > 0:
        acc_a = A.pop()
    else:
        acc_a = sys.maxsize
    if len(B) > 0:
        acc_b = B.pop()
    else:
        acc_b = sys.maxsize
    if acc_a == acc_b == sys.maxsize:
        break
    acc = min(acc_a, acc_b)

    if tot + acc <= K:
        cnt += 1
    else:
        break

    tot += acc
    if acc_a <= acc_b:
        B.append(acc_b)
    else:
        A.append(acc_a)

print(cnt)

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

#print(A)
idx = 0
for b in B:
    idx = bisect.bisect_left(A,b,lo=idx+1)
    A.insert(idx,b)

tmp = 0
ans = 0
for i in range(len(A)):
    if tmp+A[i]>k:
        break
    tmp+=A[i]
    ans+=1
print(ans)

Submission status: Wrong Answer

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

ans = 0
while k >= 0:
    if a:
        tmp_a = a.pop(0)
    if b:
        tmp_b = b.pop(0)

    if tmp_a > tmp_b:
        a.insert(0, tmp_a)
        if k > tmp_b:
            k -= tmp_b
            ans += 1
        else:
            print(ans)
            exit(0)
    else:
        b.insert(0, tmp_b)
        if k > tmp_a:
            k -= tmp_a
            ans += 1
        else:
            print(ans)
            exit(0)

Submission status: Wrong Answer

Solution code:
nmk = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_num = 0
b_num = 0
ans = 0
time = 0
for i in range(nmk[0]+nmk[1]):
    try:
        if a[a_num]<b[b_num]:
            time += a[a_num]
            if time<=nmk[2]:
                ans += 1
                a_num += 1
            else:
                break
        elif a[a_num]>b[b_num]:
            time += b[b_num]
            if time<=nmk[2]:
                ans += 1
                b_num += 1
            else:
                break
    except:
        if a_num==nmk[0]:
            time += b[b_num]
            if time<=nmk[2]:
                ans += 1
                b_num += 1
            else:
                break
        else:
            time += a[a_num]
            if time<=nmk[2]:
                ans += 1
                a_num += 1
            else:
                break

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_ = [sum(A[:i+1]) for i in range(len(A)) if sum(A[:i+1]) <= K]
B_ = [sum(B[:i+1]) for i in range(len(B)) if sum(B[:i+1]) <= K]

x = [i+j+2 for i in range(len(A_)) for j in range(len(B_)) if A_[i]+B_[j] <= K]
print(max(x) if len(x) > 0 else 0)

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

ma = 0
mb = 0

i=0
j=0

flag = True

while ma + A[i] <= K:
  ma += A[i]
  i += 1
  if i == len(A):
    break

while mb + B[j] <= K - ma:
  mb += B[j]
  j += 1
  if j == len(B):
    flag = False
    break

ans = i + j
k = i-1
while flag and k > 0:
  ma -= A[k]
  while mb + B[j] <= K - ma:
    mb += B[j]
    j += 1
    if j == len(B):
      flag = False
      break      
  ans = max(ans,k+j)
  k -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(_) for _ in input().split(' ')]
a = [int(_) for _ in input().split(' ')] + [k + 1]
b = [int(_) for _ in input().split(' ')] + [k + 1]

t = 0
answer = 0

i = 0
j = 0

while True:
    if a[i] + t > k:
        if b[j] + t > k:
            break
        else:
            t += b[j]
            j += 1
    else:
        if b[j] + t > k:
            t += a[i]
            i += 1
        else:
            if a[i] <= b[j]:
                t += a[i]
                i += 1
            else:
                t += b[j]
                j += 1
    answer += 1

print(answer)

Submission status: Wrong Answer

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

    A = [10**10]+A[::-1]
    B = [10**10]+B[::-1]

    a = 0
    while True:
        C = min(A,B,key=lambda x:x[-1])
        if K >= C[-1]:
            a += 1
            K -= C.pop()
        else:
            return a

print(hoge())

Submission status: Wrong Answer

Solution code:
N,M,K = (int(a) for a in input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
for i in range(N) :
    a[i+1] = a[i] + A[i]
for i in range(M) :
    b[i+1] = b[i] + B[i]
x = N
y = M
while a[x] + b[y] > K :
    if a[x] > b[y] :
        x -= 1
    elif a[x] < b[y] :
        y -= 1
print(x+y)

Submission status: Wrong Answer

Solution code:
a,b,c=map(int,input().split())
li_a=list(map(int,input().split()))
li_b=list(map(int,input().split()))
for i in li_b:
  li_a.append(i)
li_a.sort()
count=0
while c>0:

      
    c=c-li_a[count]
    if c<0:
      break
    count+=1
    
    
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
import numpy
A = list(numpy.cumsum(numpy.array(a)))
B = list(numpy.cumsum(numpy.array(b)))
A = [i for i in A if i<=k]
B = [i for i in B if i<=k]
n=len(A)
m=len(B)
if n==0:
  print(m)
  exit()
if m==0:
  print(n)
  exit()
i,j = 0,m-1
ans=m
while True:
  if i==n or j==-1:
    break
  if B[j]+A[i]<=k:
    ans = max(ans,i+j+2)
    i+=1
  else:
    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()))

l = 0
ln = 0
lm = 0
ans = 0

while (k > 0):
    if (ln >= n):
        s = float("inf")
    else:
        s = a[ln]

    if (lm >= m):
        t = float("inf")
    else:
        t = b[lm]

    if (min(s, t) > k):
        break
    elif (s > t):
        k -= t
        lm += 1
    elif (t >= s):
        k -= s
        ln += 1

print(ln+lm)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,L = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
cnt = 0
while True:
    if L < 0:
        cnt -= 1
        break
    elif L == 0:
        break
    else:
        if len(A) != 0 and len(B) != 0:
            if A[0] < B[0]:
                tmp = A.popleft()
            else:
                tmp = B.popleft()
        elif len(A) != 0 and len(B) == 0:
            tmp = A.popleft()
        elif len(A) == 0 and len(B) != 0:
            tmp = B.popleft()
        else:
            break
        L -= tmp
        cnt += 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()))

c = 0
for _ in range(len(a)+len(b)):
  if len(a) == 0 and len(b) == 0:
    break
  elif len(a) > 0 and len(b) == 0:
    if k >= a[0]:
      k -= a.pop(0)
      c += 1
    else:
      break
  elif len(a) == 0 and len(b) > 0:
    if k >= b[0]:
      k -= b.pop(0)
      c += 1
    else:
      break
  else:
    if a[0] >= b[0]:
      if k >= b[0]:
        k -= b.pop(0)
        c += 1
      else:
        break
    else:
      if k >= a[0]:
        k -= a.pop(0)
        c += 1
      else:
        break

print(c)

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())))
t = 0
x, y = a.popleft(), b.popleft()

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

while k >= 0:
    t += 1
    if x > y:
        k -= y
        if b:
            y = b.popleft()
        else:
            y = float("inf")
    else:
        k -= x
        if a:
            x = a.popleft()
        else:
            x = float("inf")
print(t - 1)

Submission status: Wrong Answer

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

len_a, len_b = len(A) - 1, len(B) - 1
max_val = pow(10, 9) + 10

time = 0
book_count = 0
a_idx, b_idx = 0, 0

while time < K:
  # index out of range
  if a_idx <= len_a:
    tmp_a = A[a_idx]
  else:
    tmp_a = max_val
  if b_idx <= len_b:
    tmp_b = B[b_idx]
  else:
    tmp_b = max_val
  # 今回読んだら時間を超える場合、ここで終了
  if time + min(tmp_a, tmp_b) > K:
    break
  if tmp_a <= tmp_b:
    time += tmp_a
    a_idx += 1
  else:
    time += tmp_b
    b_idx += 1
  book_count += 1

print(book_count)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split(" "))
alist = list(map(int, input().split(" ")))
blist = list(map(int, input().split(" ")))

total = 0
count = 0
while total < k and (alist != [] or blist != []):
  if alist == []:
    total += blist[0]
    count += 1
    blist.pop(0)
  elif blist == []:
    total += alist[0]
    count += 1
    alist.pop(0) 
  elif alist[0] <= blist[0]:
    total += alist[0]
    count += 1
    alist.pop(0)
  elif alist[0] > blist[0]:
    total += blist[0]
    count += 1
    blist.pop(0)
 
if total > k:
  print(count-1)
else:
  print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

count = 0
while len(a) > 0 and len(b) > 0:
    if a[0] <= b[0] and a[0] < k:
        k -= a.popleft()
        count += 1
        continue
    elif b[0] < a[0] and b[0] < k:
        k -= b.popleft()
        count += 1
        continue
    break
        
while len(a) > 0 and a[0] <= k:
    k -= a.popleft()
    count += 1
while len(b) > 0 and b[0] <= k:
    k -= b.popleft()
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

num_books = 0
remaining_time = K

while True:
    consumption = 0

    if len(A) == 0 and len(B) == 0: break

    if len(A) == 0:
        consumption = B.popleft()
    elif len(B) == 0:
        consumption = A.popleft()
    elif A[0] < B[0]:
        consumption = A.popleft()
    else:
        consumption = B.popleft()
    # print(consumption)
    
    remaining_time -= consumption
    if remaining_time < 0: break

    num_books += 1

print(num_books)

Submission status: Wrong Answer

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m,k = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    b = [int(i) for i in ipt().split()]
    an = n
    bn = m
    sm = 0
    for i,ai in enumerate(a):
        if sm+ai > k:
            an = i
            break
        sm += ai
    for i,bi in enumerate(b):
        if sm+bi > k:
            bn = i
            break
        sm += bi
    ma = an+bn
    for i,ai in enumerate(a[an-1:-1:-1]):
        sm -= ai
        for j in range(bn,m):
            if sm+bn > k:
                bn = j
                break
            elif j == m-1:
                bn = m
            sm += b[j]
        if ma < an-i-1+bn:
            ma = an-i-1+bn
        if bn == m:
            print(ma)
            exit()
    print(ma)


    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

timeLeft = k
count = 0;

i = 0
j = 0

while i < len(a) and j < len(b):
    if (a[i] < b[j] and a[i] <= timeLeft):
        timeLeft -= a[i]
        i += 1
    elif(a[i] > b[j] and b[j] <= timeLeft):
        timeLeft -= b[j]
        j += 1
    else:
        break

while i < len(a) :
    if (a[i] <= timeLeft):
        timeLeft -= a[i]
        i += 1
    else:
        break

while j < len(b) :
    if (b[j] <= timeLeft):
        timeLeft -= b[j]
        j += 1
    else:
        break


print(i+j)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def lower_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok



def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] = a[i] + a[i-1]
	for i in range(1, m):
		b[i] = b[i] + b[i-1]
	log.print(a, b)
	ans = 0
	for i in range(-1, n):
		if a[i] <= k:
			if i == -1:
				ans = max(ans, lower_case(b, k))
				continue
			ans = max(ans, i+1+lower_case(b, k-a[i]))
			log.print(i, k-a[i], lower_case(b, k-a[i]))
	print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
def dfs(a, b, t):
    global cnt
    cnt = max(cnt, a+b)
    if a < N and t + A[a] <= K:
        dfs(a+1, b, t+A[a])
    if b < M and t + B[b] <= K:
        dfs(b+1, a, t+B[b])
    
dfs(0, 0, 0)
print(cnt)

Submission status: Wrong Answer

Solution code:

from collections import deque



# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# 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")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def main():
    # n = int(input())
    # l = [int(j) for j in input().split()]
    
# 3 4 240
# 60 90 120
# 80 150 80 150

    # for t in range(int(input())):
    n,m,k = [int(j) for j in input().split()]
    l1 = [int(j) for j in input().split()]
    l2 = [int(j) for j in input().split()]
    # pre = [0]*n
    i = 0
    j = 0
    mon = k
    # book = 0
    while(mon>0 and i<n and j<m):
        if(l1[i]>l2[j]):
            if mon-l2[j]>=0:
                mon-=l2[j]
                j+=1
            else:
                mon = -1
        else:
            if mon-l1[i]>=0:
                mon-=l1[i]
                i+=1
            else:
                mon = -1
        # print(i,j,mon)
    while i<n and mon>0:
            if mon-l1[i]>=0:
                mon-=l1[i]
                i+=1
            else:
                mon = -1
    while j<m and mon>=0:
            if mon-l2[j]>=0:
                mon-=l2[j]
                j+=1
            else:
                mon = -1
    print(i+j)




# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = A + B
AB = sorted(AB)
sum_ = 0
count = 0

for i in range(N + M):
    sum_ += AB[i]
    if(sum_ <= K):
        count += 1
    else:
        break
        
print(count)

Submission status: Wrong Answer

Solution code:
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

from collections import deque
n,m,k=mi()
a=deque(lmi())
b=deque(lmi())
i=0
cnt=0
value=0
while a or b:
  try:
    r=a[i]
  except:
    r=float('inf')
  try:
    q=b[i]
  except:
    q=float('inf')
  p=min(q,r)
  if p==r:
    p=a.popleft()
  else:
    p=b.popleft()
  #print(p)
  value+=p
  if value>k:
    break
  cnt+=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
for i in range(n + m):
    if len(a) == 0:
        a.append(10 ** 9 + 1)
    if len(b) == 0:
        b.append(10 ** 9 + 1)
    if a[0] > k and b[0] > k:
        break
    if a[0] < b[0]:
        k -= a[0]
    else:
        k -= b[0]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main(n, m, k, a_n, b_n):
    r = 0

    for _ in range(n+m):
        if len(a_n) > 0:
            a_v = a_n[0]
        else:
            a_v = float('inf')

        if len(b_n) > 0:
            b_v = b_n[0]
        else:
            b_v = float('inf')

        if a_v < b_v:
            k -= a_n.pop(0)
        else:
            k -= b_n.pop(0)

        if k >= 0:
            r += 1

        if k <= 0:
            return r
    return r



if __name__ == "__main__":
    n, m, k = map(int, input().split())
    a_n = list(map(int, input().split()))
    b_n = list(map(int, input().split()))
    print(main(n, m, k, a_n, b_n))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import bisect

def main():
    N, M, K = map(int, input().split())
    A_lsit = list(map(int, input().split()))
    B_lsit = list(map(int, input().split()))

    A_sum_list = A_lsit[:]
    for i in range(1, N):
        A_sum_list[i] = A_sum_list[i-1] + A_lsit[i]
    B_sum_list = B_lsit[:]
    for i in range(1, M):
        B_sum_list[i] = B_sum_list[i-1] + B_lsit[i]
    #print(A_sum_list)
    #print(B_sum_list)

    max_book_number = 0
    for i in range(N):
        if A_sum_list[i] > K:
            pass
        else:
            book_number_A = i+1
            book_number_B = bisect.bisect_right(
                B_sum_list, K-A_sum_list[i])
            max_book_number = max(
                max_book_number,
                book_number_A + book_number_B
            )
            #print(book_number_A, book_number_B, book_number_A + book_number_B)
    print(max_book_number)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

A = A + [10 ** 10]
B = B + [10 ** 10]

time = 0
count = 0
while True:
    if A[0] <= B[0]:
        time += A.pop(0)
    else:
        time += B.pop(0)
    if time > K:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, m, k = inpl()
a = inpl()
b = inpl()
tmp = 0
for i in range(len(a)):
    tmp += a[i]
    a[i] = tmp
tmp = 0
for i in range(len(b)):
    tmp += b[i]
    b[i] = tmp
ans = 0
a_start = bisect.bisect_right(a, k)
if a_start == 0:
    print(bisect.bisect_right(b, k))
    exit()
for a_amount in range(a_start, 0, -1):
    new_k = k - a[a_amount - 1]
    b_amount = bisect.bisect_right(b, new_k)
    ans = max(ans, a_amount + b_amount)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = [int(num) for num in input().split()]
A_list = [int(num) for num in input().split()]
B_list = [int(num) for num in input().split()]

read_min = K
read_cnt = 0
ai = 0
bi = 0
for _ in range(N+M):
  if ai < N and bi < M:
    if A_list[ai] < B_list[bi]:
      read_min -= A_list[ai]
      ai += 1
    elif A_list[ai] >= B_list[bi]:
      read_min -= B_list[bi]
      bi += 1
  else:
    if ai > N:
      read_min -= B_list[bi]
      bi += 1
    elif bi > M:
      read_min -= A_list[ai]
      ai += 1
    
  if read_min < 0:
    break
  read_cnt += 1  

print(read_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(' ')))


lim = n+m
i = 0
cnt_a = 0
loop = len(a)
while k > 0 and i < loop:
    if k - a[i] >= 0:
        k -= a[i]
        i += 1
        cnt_a += 1
    else:
        break

i = 0
cnt_b = 0
loop = len(b)
while k > 0 and i < loop:
    if k - b[i] >= 0:
        k -= b[i]
        i += 1
        cnt_b += 1
    else:
        break

cnt = cnt_a + cnt_b
max_cnt = cnt
kk = k

for j in range(cnt_a-1,-1,-1):
    if max_cnt == lim:
        break
    cnt -= 1
    kk += a[j]
    while kk > 0 and i < loop:
        if k - b[i] >= 0:
            k -= b[i]
            i += 1
            cnt += 1
        else:
            break
    if max_cnt < cnt:
        max_cnt = cnt
        print(max_cnt,j)

print(max_cnt)

Submission status: Wrong Answer

Solution code:
[N, M, K] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

c = 0

A.append(10**10)
A.reverse()
B.append(10**10)
B.reverse()
a = A.pop()
b = B.pop()

while True:
  if a < b:
    if K >= a:
      c += 1
      K -= a
      a = A.pop()
    else:
      break
  else:
    if K >= b:
      c += 1
      K -= b
      b = B.pop()
    else:
      break

print(c)

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
i = 0
j = 0
cnt = 0

while t <= K and (i < N or j < M):
    if i >= N:
        t += B[j]
        j += 1
    elif j >= M:
        t += A[i]
        i += 1
    else:
        if A[i] < B[j]:
            t += A[i]
            i += 1
        else:
            t += B[j]
            j += 1

    if t <= K:
        cnt += 1


print(cnt)

Submission status: Wrong Answer

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

n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
cnt = 0
idx = 0
res = [0]

na, nb = [0, a[0]], [0, b[0]]

for x in range(1, n):
    na.append(na[-1] + a[x])

for x in range(1, m):
    nb.append(nb[-1] + b[x])

a.insert(0, 0)
b.insert(0, 0)

for x in range(n, 0, -1):
    if na[x] > k:
        continue

    while True:
        if idx + 1 <= m and na[x] + nb[idx + 1] <= k:
            idx += 1
        else:
            break

    res.append(x + idx)

print(max(res))

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

akari = [0]*(n+1)
bkari = [0]*(m+1)
for i in range(n):
	akari[i+1] = akari[i] + a[i]

for i in range(m):
	bkari[i+1] = bkari[i] + b[i]

def bin(ls,s,e,sikii):
	if e - s <= 1:
		return s
	mid = (s+e)//2
	if sikii < ls[mid]:return bin(ls,s,mid,sikii)
	else:return bin(ls,mid,e,sikii)

ans = 0
for i in range(n+1):
	time = akari[i]
	if k - time <= 0:break
	ref = bin(bkari,0,m+1,k-time)
	ans = max(ans,ref+i)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = (int(x) for x in input().split())
alist = [int(i) for i in input().split()]
blist = [int(i) for i in input().split()]
count = 0
minu = 0
while minu<k:
    count += 1
    if (alist==[] and blist==[]):
        break
    elif alist==[] and blist!=[]:
        minu += blist[0]
        del blist[0]
    elif blist==[] and alist!=[]:
        minu += alist[0]
        del alist[0]
    else:
        if alist[0]<blist[0]:
            minu +=alist[0]
            del alist[0]
        else:
            minu += blist[0]
            del blist[0]

if alist==[] and blist==[]:
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

a = [int(s) for s in data[1].split()]
b = [int(s) for s in data[2].split()]

counter = 0
time = 0
for i in range(1,n+m+1):
    if a != [] and b!= []:
        if time + a[0] > k and time + b[0] > k:
            break
        else:
            if a[0] >= b[0]:
                counter += 1
                time += b[0]
                b.pop(0)
            else:
                counter += 1
                time += a[0]
                a.pop(0)
    elif a == []:
        if time + b[0] > k:
            break
        else:
            counter += 1
            time += b[0]
            b.pop(0)
    elif b == []:
        if time + a[0] > k:
            break
        else:
            counter += 1
            time += a[0]
print(counter)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
t = 0
ia = 0
ib = 0
ans = 0
#qa = deque()
#qb = deque()
while t <= K:
    #print('ans=' + str(ans), ia,ib)
    if ia == N and ib == M:
        break
    if ia < N and ib < M:
        if A[ia] <= B[ib]:
            t += A[ia]
            ia += 1
            ans += 1
        else:
            t += B[ib]
            ib += 1
            ans += 1
    elif ia == N:
        t += B[ib]
        ib += 1
        ans += 1
    elif ib == M:
        t += A[ia]
        ia += 1
        ans += 1
    #print(ans)
if t > K:
    ans -= 1
print(ans)

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()))
res = 0
tmp = 0
A.append(1000000001)
B.append(1000000001)
Acount = 0
Bcount = 0
for i in range(N + M):
    if A[Acount] < B[Bcount]:
        tmp += A[Acount]
        Acount += 1
    else:
        tmp += B[Bcount]
        Bcount += 1
    if tmp > K:
        break
    res += 1
print(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()))

cnt = 0
remain = k
index_a = 0
index_b = 0
while remain > 0:
    if index_a >= len(a) and index_b >= len(b):
        break

    if index_b >= len(b) and index_a < len(a):
        remain -= a[index_a]
        index_a += 1
    elif index_a >= len(a) and index_b < len(b):
        remain -= b[index_b]
        index_b += 1
    elif a[index_a] < b[index_b]:
        if remain < a[index_a]:
            break
        remain -= a[index_a]
        index_a += 1
    else:
        if remain < b[index_b]:
            break
        remain -= b[index_b]
        index_b += 1
    cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

if __name__ == '__main__':
    n,m,k = list(map(lambda x: int(x), sys.stdin.readline().split()))
    A = list(map(lambda x: int(x), sys.stdin.readline().split()))
    B = list(map(lambda x: int(x), sys.stdin.readline().split()))

    i, j = 0, 0
    summ = 0
    x = 0
    while True:
        if summ > k:
            x -= 1
            break
        if A == [] and B == []:
            break
        if A != [] and (B == [] or A[0] < B[0]):
            summ += A.pop(0) 
            x += 1
        else:
            summ += B.pop(0)
            x += 1
    print(x)