Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
aa = 0
bb = 0
while True:
    if aa >= n and bb >= m:
        break
    elif aa >= n:
        k -= b[bb]
        bb += 1
    elif bb >= m:
        k -= a[aa]
        aa += 1
    else:        
        if a[aa] > b[bb]:
            k -= b[bb]
            bb += 1
        else:
            k -= a[aa]
            aa += 1        
    if k < 0:
      break

if k < 0:
	print(aa+bb-1)
else:
    print(aa+bb)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

#累積和を取って片方を全探索、もう片方を二分探索


n,m,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst2 = list(map(int,readline().split()))

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
lst3 = cumsum(lst1)
lst4 = cumsum(lst2)


ans = 0
for i in range(-1,n):
    if i == -1:
        res = k
    else:
        res = k-lst3[i]
    if res <= 0:
        break
    res2 = bisect.bisect_right(lst4,res)
    ans = max(ans,i+1+res2)

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()))
  time = 0
  num = 0
  while True:
    if num < N and time + A[num] <= K:
      time += A[num]
      num += 1
    else:
      break
  ans = num
  ans_temp = num
  for i in range(M):
    print(time)
    time += B[i]
    ans_temp += 1
    print(time)
    while time > K:
      if num > 0:
        time -= A[num-1]
        num -= 1
        ans_temp -=1
      else:
        break
    if num == 0 and time > K:
      break
    ans = max(ans, ans_temp)
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split())) + [1000000000]*100
B = list(map(int, input().split())) + [1000000000]*100
c = 0
while K >= 0:
    if K < A[0] and K < B[0]:
        break
    if A[0] < B[0]:
        K -= A.pop(0)
    else:
        K -= B.pop(0)
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    ans = 0
    t = 0
    ai, bi = 0, 0
    la, lb = len(A), len(B)
    while True:
        if ai < la and bi < lb:
            if A[ai] < B[bi]:
                t += A[ai]
                ai += 1
            else:
                t += B[bi]
                bi += 1
        elif ai < la:
            t += A[ai]
            ai += 1
        elif bi < lb:
            t += B[bi]
            bi += 1
        else:
            break

        if t > k:
            break

        ans += 1

    print(ans)


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.sort()
B.sort()
c = 0
ans = 0
ia = 0
ib = 0
while c <= K:
  if ia == N and ib == M:
    break
  elif ia == N:
    c += B[ib]
    ib += 1
     
  elif ib == M:
    c += A[ia]
    ia += 1
    
  elif A[ia] <= B[ib]:
    c += A[ia]
    ia += 1
     
  else:
    c += B[ib]
    ib += 1
  if c <= K:
    ans += 1
print(ans)

Submission status: Wrong Answer

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

a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))

if len(a)>len(b):
	a,b=b,a
i=0
j=0
total=0
cnt=0
while total<k:
	if i<len(a):
		if a[i]<=b[j]:
			total+=a[i]
			i+=1
		else:
			total+=b[j]
			j+=1
	elif j<len(b):
		total+=b[j]
		j+=1

	cnt+=1
	if total>k:
		cnt-=1
	elif total==k:
		break
	if j==len(b) and i==len(a):
		break

print(cnt)

Submission status: Wrong Answer

Solution code:
from queue import LifoQueue


def print_sol(c, sol):
    print('Case #{}: {}'.format(c, sol))


def rd_int():
    return int(input())


def rd_str():
    return input()


def rd_str_lst():
    return input().split(' ')


def sp_str_lst():
    return list(input())


def rd_int_lst():
    return [int(i) for i in rd_str_lst()]


def sp_int_lst():
    return [int(i) for i in sp_str_lst()]


def dfs(g, i, v):
    """
    recursive post order dfs
    Args:
        g: array of graph nodes
        i: node to traverse
        v: visited array

    Returns: a post order dfs of graph g
    """
    v[i] = True
    for j in g[i]:
        if not v[j]:
            dfs(g, j, v)

    print(i)


def dfs_iter(g, i, n):
    v = [False] * n
    stack = LifoQueue()
    stack.put(i)
    while stack.not_empty:
        u = stack.get()
        v[u] = True
        print(u)
        for i in g[u]:
            if not v[i]:
                stack.put(i)


def main():
    inf = 10 ** 9 + 1
    n, m, k = rd_int_lst()
    a = rd_int_lst()
    b = rd_int_lst()

    sol = 0
    i = 0
    j = 0
    while k > 0 and (i < n or j < m):
        ai = a[i] if i < n else inf
        bj = b[j] if j < m else inf

        if ai <= bj:
            x = ai
            i += 1
        else:
            x = bj
            j += 1

        if k < x:
            break

        k -= x
        sol += 1

    print(sol)


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

books = 0

p1 = 0
p2 = 0

while K > 0 and ( p1 < N and p2 < M ):
    books += 1

    if p1 < N and A[p1] < B[p2]:
        # print("chosen", "p1", p1)
        K -= A[p1]
        p1 += 1

    elif p2 < M:
        # print("chosen", "p2", p2)
        K -= B[p2]
        p2 += 1

    # print(K, p1, p2)

# print(K)

if K < 0:
    books -= 1
    print(books)

elif K == 0:
    print(books)

else:
    if p1 < N:
        while K > 0 and p1 < N:
            books += 1
            K -= A[p1]
            p1 += 1

    if p2 < M:
        while K > 0 and p2 < M:
            books += 1
            K -= B[p2]
            p2 += 1

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

ni = 0
mi = 0
ans = 0

for i in range(n+m):
  if n == ni and m == mi:
    break
  elif n == ni:
    ans += b[mi]
    mi += 1
  elif m == mi:
    ans += a[ni]
    ni += 1
  elif a[ni] <= b[mi]:
    ans += a[ni]
    ni += 1
  else:
    ans += b[mi]
    mi += 1

  if ans > k:
    break

cal = ni + mi
if k < ans :
  cal -= 1
print(cal)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())

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

C = deque()
time = 0

while len(A) > 0 and len(B) > 0:
  if A[0] >= B[0]:
    C.append(B[0])
    B.popleft()
  else:
    C.append(A[0])
    A.popleft()

while len(A) > 0:
  C.append(A[0])
  A.popleft()
  
while len(B) > 0:
  C.append(B[0])
  B.popleft()
  
count = 0
for c in C:
  if c + time <= K:
    count += 1
    time += c
  else:
    break

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()))
ans = 0
t = 0
while t<k:
    if len(a)==0 and len(b)==0: break
    if len(a)==0:
        if b[0]+t>k: break
        else:
            t+=b[0]
            tmp=b.pop(0)
    elif len(b)==0:
        if t+a[0]>k: break
        else:
            t+=a[0]
            tmp = a.pop(0)
    elif a[0]<b[0]:
        if a[0]+t>k:
            break
        else:
            t+=a[0]
            tmp=a.pop(0)
    else:
        if b[0]+t>k:
            break
        else:
            t+=b[0]
            tmp=b.pop(0)
    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()))
cnt=0
time=0
for i in range(n+m):
  if len(A)==0 and len(B)>0:
    if time+B[0]<=k:
      cnt+=1
      time+=B[0]
      del B[0]
    else:
      break;
  elif len(B)==0 and len(A)>0:
    if time+A[0]<=k:
      cnt+=1
      time+=A[0]
      del A[0]
    else:
      break; 
  elif A[0]<=B[0]:
    if time+A[0]<=k:
      cnt+=1
      time+=A[0]
      del A[0]
    else:
      break;
  elif A[0]>B[0]:
    if time+B[0]<=k:
      cnt+=1
      time+=B[0]
      del B[0]
    else:
      break;
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()))

maxmin = 0
ct = 0
ai = 0
bi = 0

while(maxmin < k):
  nextbook = 0
  if(ai<n and bi<m):
    if(a[ai]<b[bi]):
      nextbook = a[ai]
      ai += 1
    else:
      nextbook = b[bi]
      bi += 1
  elif(ai>=n and bi>=m):
    break
  elif(bi>=m):
    nextbook = a[ai]
    ai += 1
  else:
    nextbook = b[bi]
    bi += 1
  
  if(maxmin + nextbook <= k):
    maxmin += nextbook
    ct += 1
  else:
    break
    
print(ct)

Submission status: Wrong Answer

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

t = 0
i = 0
j = 0
while (t <= k):
  #print(i,j,t)
  if i < n:
    ai = a[i]
  else:
    ai = 10**10
  if j < m:
    bi = b[j]
  else:
    bi = 10**10
  if ai < bi:
    i += 1
    t += ai
  else:
    j += 1
    t += bi
if t <= k:
  print(n+m)
else:
  print(i+j-1)
#print(t,i,j)

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

import numpy as np

import math

import collections


def calcTime(indexA ,indexB,sumTime,co):
    sys.setrecursionlimit(10 ** 9 +1)
    A = 0
    B = 0
    global count
    if indexA+1 < n and sumTime+a[indexA+1] <=k:
        A = calcTime(indexA+1,indexB,sumTime+a[indexA+1],co+1)
        if count < co+1:
            count +=1
    if indexB+1 < m and sumTime+b[indexB+1] <=k:
        B = calcTime(indexA,indexB+1,sumTime+b[indexB+1],co+1)
        if count < co+1:
            count +=1


if __name__ == '__main__':
    n, m,k = map(int, input().split())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    global count
    count = 0
    calcTime(-1,-1,0,0)

    print(count)

Submission status: Wrong Answer

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


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    cur = sum(A)
    for i in range(N-1,-1,-1):
        if cur>K: cur -= A[i]
        else:break
    if cur==0: max_k = 0
    else: max_k = i+1
    p = 0
    for q in range(i,-1,-1):
        while(p<M):
            if cur+B[p] <= K:
                cur+=B[p]
                max_k = max(i+1+p+1, max_k)
                p+=1
            else:
                break
        cur -= A[q-1]
    print(max_k)





    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq

def solve(A, B, K):

    N = len(A)
    M = len(B)

    min_heap = []

    A_MARKER, B_MARKER = 0, 1
    heapq.heappush(min_heap, (A[0], A_MARKER, 0))
    heapq.heappush(min_heap, (B[0], B_MARKER, 0))

    k = 0
    count = 0
    while k < K and min_heap:

        mins, marker, idx = heapq.heappop(min_heap)
        if k + mins > K:
            return count

        k += mins
        count += 1

        if marker == A_MARKER and idx + 1 < N:
            heapq.heappush(min_heap, (A[idx + 1], A_MARKER, idx + 1))
        elif marker == B_MARKER and idx + 1 < M:
            heapq.heappush(min_heap, (B[idx + 1], B_MARKER, idx + 1))

    return count

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

print(solve(A, B, K))

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()))
la=len(A)
lb=len(B)
ia=0
ib=0
c=10**10
ans=0
while(ia+ib<la+lb):
  a=A[ia] if ia<la else c
  b=B[ib] if ib<lb else c
  dk=min(a,b)
  if a>=b:
    ib+=1
  else:
    ia+=1
  if k>=dk:k-=dk
  else:break
  ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
M, N, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Ai, Bi, ans = 0, 0, 0
len_A, len_B = len(A), len(B)
MX = 1000000001
while K > 0:
    cst = 0
    cst_A = MX if Ai == len_A else A[Ai]
    cst_B = MX if Bi == len_B else B[Bi]
    if cst_A == cst_B == MX: break

    if cst_A < cst_B:
        cst = cst_A
        Ai += 1
    else:
        cst = cst_B
        Bi += 1
    if K-cst >= 0: ans += 1
    K -= cst
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(i) for i in input().split()]
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]

times = 0
book_num = 0
max_num = 10**9+1
while times < k:

    if len(a_list) == 0 and len(b_list) == 0:
        break

    if len(a_list) != 0:
        a_val = a_list[0]
    else:
        a_val = max_num

    if len(b_list) != 0:
        b_val = b_list[0]
    else:
        b_val = max_num

    if a_val >= b_val:
        tmp = b_val
        b_list.pop(0)
    else:
        tmp = a_val
        a_list.pop(0)

    if times + tmp <= k:
        book_num += 1

    times += tmp

print(book_num)

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

alist.append(10**9+1)
blist.append(10**9+1)

ans = 0
tm = 0
while True:
  tm += alist.pop(0) if alist[0] < blist[0] else blist.pop(0)
  if tm > k:
    break
  ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i, j = 0, 0
    while K > 0:
        if i == N:
            if j != M:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    j -= 1
                    break
            else:
                j -= 1
                break

        elif j == M:
            if i != N:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    i -= 1
                    break
            else:
                i -= 1
                break
        else:
            if A[i] >= B[j]:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
    print(i+j)

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()))
cnt=0
ans=0
flag=True
c_a=0
c_b=0
for i in range(n+m):
  if c_b==m:
    cnt+=a[c_a]
    c_a+=1
  elif c_a==n:
    cnt+=b[c_b]
    c_b+=1
  elif a[c_a]<=b[c_b]:
    cnt+=a[c_a]
    c_a+=1
  elif a[c_a]>b[c_b]:
    cnt+=b[c_b]
    c_b+=1
    
  if cnt>k or cnt>10**9:
    print(ans)
    flag=False
    break
  else:
    ans+=1
    
if flag:
  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()))
rem=k
i=0
j=0
count=0
while i<n:
	if rem==0 or rem<a[i]:
		break
	rem=rem-a[i]
	i=i+1
	count=count+1
while j<m:
	if rem==0 or rem<b[j]:
		break
	rem=rem-b[j]
	j=j+1
	count=count+1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_right, bisect_left

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

ap = [0 for i in range(n)]
bp = [0 for j in range(m)]

for i in range(n):
	if i == 0:
		ap[i] = a[i]
	else: 
		ap[i] = a[i] + ap[i - 1]

for i in range(m):
	if i == 0:
		bp[i] = b[i]
	else: 
		bp[i] = b[i] + bp[i - 1]

bestRes = 0

#print(bp)

def search(x):
	left = 0 
	right = m - 1
	while right - left > 1:
		mid = left + (right - left) // 2
		if bp[mid] == x:
			return mid

		if bp[mid] < x:
			right = mid - 1
		else:
			left = mid + 1


	if bp[right] <= x:
		return right
	elif bp[left] <= x:
		return left
	else:
		return left - 1

for i in range(n):
	#print(i)
	if ap[i] > k:
		break

	rest = k - ap[i]

	#print(rest)

	if bp[0] > rest:
		bestRes = max(bestRes, i)

	else:
		count = bisect_right(bp, rest)
		#print(i, rest, count)

		bestRes = max(bestRes, i + count + 1)


#print(bp)
#bisect_right(bp, k)

if k > bp[0]:
	count = bisect_right(bp, k)
	if count != m: 
		count += 1
	bestRes = max(bestRes, count)

print(bestRes)

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

init = 0
init2 = 0
s = 0
for i in range(n):
  if s + a[i] <= k:
    s += a[i]
    init += 1

k2 = k - s
for i in range(m):
  if s + b[i] <= k2:
    s += b[i]
    init2 += 1

max_ = init+init2
while init-1 > 0:
  s -= a[init-1]
  init -= 1
  for i in range(init2, m):
    if s + b[i] <= k:
      s += b[i]
      init2 += 1
    else:
      break
  max_ = max(max_, init+init2)
print(max_)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import bisect

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N, M, K = in_nn()
    A = in_nl()
    B = in_nl()

    Asum = [0] * (N + 1)
    Bsum = [0] * (M + 1)

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

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

    ans = 0
    for i in range(N + 1):
        time = K - Asum[i]
        if time <= 0:
            break
        else:
            ans = max(ans, i + bisect.bisect_right(Bsum, time) - 1)

    print(ans)


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

counter = 0  # min
idx_a = 0
idx_b = 0

for _ in range(n+m):
    if idx_a == n:
        counter += b[idx_b]
        if idx_b != m:
            idx_b += 1
    elif idx_b == m:
        counter += a[idx_a]
        if idx_a != n:
            idx_a += 1
    elif a[idx_a] <= b[idx_b]:
        counter += a[idx_a]
        if idx_a != n:
            idx_a += 1
    elif a[idx_a] > b[idx_b]:
        counter += b[idx_b]
        if idx_b != m:
            idx_b += 1
    if counter > k:
        print(idx_a+idx_b-1)
        break
else:
    print(idx_a+idx_b)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

sum_alist=[alist[0]]
for i in range(1,N):
  sum_alist.append(sum_alist[-1]+alist[i])
sum_blist=[blist[0]]
for i in range(1,M):
  sum_blist.append(sum_blist[-1]+blist[i])

limit_a=bisect.bisect(sum_alist,K)
#print(limit_a)

limit_b=bisect.bisect(sum_blist,K)
#print(limit_b)

answer=0
for i in reversed(range(limit_a)):
  a_sum=sum_alist[i]
  b_sum=K-a_sum
  pos_b=bisect.bisect(sum_blist,b_sum)
  #print(i+1,pos_b)
  answer=max(answer,i+1+pos_b)
  
print(answer)

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

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


ruiB=[0]*M
ruiB[0]=B[0]
for i in range(1,M):
    ruiB[i]=B[i]+ruiB[i-1]
ans=0
for i in range(N):
    totala=ruiA[i]
    if totala>K:
        break
    res=K-totala
    idx=bisect.bisect_right(ruiB, res)
    if idx==0:
        sub=i+1
    else:
        sub=i+1+idx
    ans=max(ans, sub)
print(ans)
#print(ruiA, ruiB)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    sumA = []
    sumB = []

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

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

    #print(K)
    #print(sumA)
    #print(sumB)

    books = 0
    for i in range(N):
        t = K-sumA[i]
        #print(t)
        if t<0:
            break
        idx = np.searchsorted(sumB, t, side="right")
        #print("A: {}, B: {}, books:{}".format(i+1, idx, (i+idx+1)))
        books = max(books, i+idx+1)
    
    print(books)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

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

for i in range(2 * 10 ** 5):
    A.append(float("inf"))
    B.append(float("inf"))

A = A[::-1]
B = B[::-1]

ans = 0
while k >= 0:
    a = A.pop()
    b = B.pop()
    if a < b:
        B.append(b)
        k -= a
        if k >= 0:
            ans += 1
    else:
        A.append(a)
        k -= b
        if k >= 0:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#s = input()
#n = int(input())
#s,t = input().split()
#n,m = map(int,input().split())
#a = list(map(int,input().split()))
#w = [int(input()) for _ in range(N)]

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

ans = 0
ia = 0
ib = 0

while(1):
    if (ia < n) and (ib < m):
        if a[ia] < b[ib]:
            if k >= a[ia]:
                k -= a[ia]
                # print("ia={},k={}".format(ia,k))
                ans += 1
                ia += 1
            else:
                break
        else:
            if k >= b[ib]:
                k -= b[ib]
                # print("ib={},k={}".format(ib,k))
                ans += 1
                ib += 1
            else:
                break
    elif (ia < n): # b の残りなし
        if k >= a[ia]:
            k -= a[ia]
            ans += 1
            ia += 1
        else:
            break
    elif (ib < m): # a の残りなし
        if k >= b[ib]:
            k -= b[ib]
            ans += 1
            ib += 1
        else:
            break
    else: #a, b とも残りなし
        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.append(10**9+1)
b.append(10**9+1)
cnt = 0
cnt2 = 0
mo = 0
for i in range(n+m):
  if a[cnt] >= b[cnt2]:
    mo += b[cnt2]
    if mo > k:
      print(cnt+cnt2)
      exit(0)
    cnt2+=1
  else:
    mo += a[cnt]
    if mo > k:
      print(cnt+cnt2)
      exit(0)
    cnt += 1
print(cnt+cnt2)

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()]
i, j = 0, 0
cnt = 0
while K > 0:
    if i < N and j < M:
        book = min(a[i], b[j])
        if book == a[i]:
            i += 1
        else:
            j += 1
    elif i >= N and j >= M:
        print(cnt)
        break
    elif i >= N:
        book = b[j]
        j += 1
    elif j >= M:
        book = a[i]
        i += 1
    K -= book
    if K >= 0:
        cnt += 1
else:
    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())))
x = y = last = None
ans = 0
while k > 0 and (len(b) or len(a)):
    if not x and not y:
        x,y = a.popleft(), b.popleft()
    elif last:
        if len(b):
            y = b.popleft()
        else:
            y = 1e10
    elif len(a):
        x = a.popleft()
    else:
        x = 1e10
    if x < y:
        if k < x:
            break
        k -= x
        last = 0
    else:
        if k < y:
            break
        k -= y
        last = 1
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
i,j = 0,0
a.append(k+1)
b.append(k+1)
ans = 0
flag = 1
while flag:
    if a[i] <= b[j] and a[i] <= k:
        k -= a[i]
        i += 1
        ans += 1
    elif a[i] > b[j] and b[j] <= k:
        k -= b[j]
        j += 1
        ans += 1
    else:
        flag = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N,M,K=map(int,input().split())
As=list(map(int,input().split()))
As=[a for a in accumulate(As) if a <= K]
Bs=list(map(int,input().split()))
Bs=[b for b in accumulate(Bs) if b <= K]
# print(As)
# print(Bs)

ans = []
for ai, a in enumerate(As):
    nokori = K-a
    for bi in range(len(Bs)-1, 0-1, -1):
        if Bs[bi] <= nokori:
            ans.append(ai+1 + bi+1)
            break

if ans == []:
    print(0)
else:
    print(max(ans))

Submission status: Wrong Answer

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


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    SA = [A[0]]
    SB = [B[0]]
    for i in range(1,N):
        SA.append(SA[-1]+A[i])
    for i in range(1,M):
        SB.append(SB[-1]+B[i])
    acount = 0
    acost = 0
    for i in range(len(SA)):
        if SA[i] <= K:
            acount += 1
            acost = SA[i]
        else:
            break
    bcost = 0
    bcount = 0
    for i in range(len(SB)):
        if SB[i] + acost <= K:
            bcount += 1
            bcost = SB[i]
        else:
            break
    if bcost + acost <= K:
        print(acount+bcount)
    else:
        mb = acount + bcount
        bi = bcount-1
        #Find optimize bcount from priortirize A
        for ac in range(acount,-1,-1):
            acost = SA[ac]
            while bi < M and acost + SB[bi] <=K:
                bi += 1
            mb = max(mb,bi+1,ac)
        print(mb)


    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

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

cumsum=0
cnt=0
i=0
j=0
while cumsum<=k:
    if i>n-1:
        a_i=float('inf')
    else:
        a_i=a[i]

    if j>m-1:
        a_i=float('inf')
    else: 
        b_i=b[j]   

    if a_i<=b_i:
        cumsum+=a_i
        i+=1
    else:
        cumsum+=b_i
        j+=1
        
    if cumsum<=k:   
        cnt+=1
    else:
        break
    if i>n-1 and j>m-1:
        break
    
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
INF = 10**18
A = list(map(int, input().split()))+[INF]
B = list(map(int, input().split()))+[INF]
all = sum(A) + sum(B)
if k >= all:
    print(n+m)
    exit()

A = deque(A)
B = deque(B)
total = 0
cnt = 0
while total <= k:
    if A[0] > B[0]:
        b = B.popleft()
        total += b
    else:
        a = A.popleft()
        total += a
    cnt += 1

print(cnt-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()))
time=0
count=0
while time<k:
    if count==(n+m-1):
        count=n+m+1
        break
    elif count//2>=n or count//2>=m:
        count+=1
        continue
    elif count%2==0:
        time+=a[count//2]
        count+=1
    else:
        time+=b[count//2]
        count+=1
print(count-1)