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:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


class cumsum1d:  # 一次元累積和クラス
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        # もとの配列lsにおける[i,j)の中合計
        return self.ls_accum[j] - self.ls_accum[i]


def two_pointers(ls: list):
    '''すべてのlに対して、条件is_okをみたすls[l:r]の中で
    r - lが最大になるような(l,r)の集合を返す'''
    n_ls = len(ls)
    ret = []

    def append(r, pre_states):
        '''状態にls[r]を考慮して更新する'''
        # 問題によって自分で定義
        return pre_states + ls[r]
        # 掛け算の例 return pre_state*ls[r]

    def pop(l, pre_states):
        '''状態からls[l]を抜く更新をする'''
        # 問題によって自分で定義
        # 掛け算の例 return pre_state//ls[l]
        return pre_states - ls[l]

    def is_ok(r, pre_states):
        # 問題によって自分で定義
        states = append(r, pre_states)
        # 114以下の最長の範囲が知りたい例 return states<=114
        return states <= K

    r = 0
    states = 0
    for l in range(n_ls):
        while r < n_ls and is_ok(r, states):
            # 更新式
            states = append(r, states)
            r += 1
        ret.append((l, r))
        # 抜けるときの更新
        states = pop(l, states)
    return ret


# K冊の組み合わせを試せば良い
# 合計は累積和で高速化
N, M, K = ints()
A = ints()
B = ints()
AB = list(reversed(A)) + B
# AB_cum = cumsum1d(AB)

ans = 0
for l, r in two_pointers(AB):
    if l <= N - 1 and N <= r - 1:
        ans = max(ans, r - l)
print(ans)

Submission status: Wrong Answer

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()]
s = 0
ans = 0
ca = 0
for i in range(n):
  if k >= s + a[i]:
    s += a[i]
    ans += 1
    ca += 1
  else:
    break
cb = 0
for i in range(m):
  if k >= s + b[i]:
    s += b[i]
    ans += 1
    cb += 1
  else:
    break
if ans == n + m or ans == 0:
  print(ans)
else:
  l = []
  l.append(ans)
  for i in range(m):
    if ca > 0:
      s -= a[ca - 1]
      ca -= 1
      ans -= 1
    if k >= s + b[cb]:
      s += b[cb]
      cb += 1
      ans += 1
      l.append(ans)
    if cb >= m:
      break
  print(max(l))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    a_idx = N
    b_idx = M
    ans = 0

    A = list(accumulate([0] + A))
    B = list(accumulate([0] + B))

    if A[a_idx] + B[b_idx] <= K:
        print(M + N)
        return

    while True:
        if a_idx > 0 and b_idx > 0:
            if A[a_idx] < B[b_idx]:
                b_idx -= 1
                ans += 1
            else:
                a_idx -= 1
                ans += 1
        elif a_idx <= 0 and b_idx > 0:
            b_idx -= 1
            ans += 1
        elif a_idx > 0 and b_idx <= 0:
            a_idx -= 1
            ans += 1
        else:
            break

        if A[a_idx] + B[b_idx] <= K:
            break

    # print(a_idx, b_idx)
    # print(ans)
    print(M + N - ans)


if __name__ == '__main__':
    main()

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

max_books = len(A)+len(B)

A.append(1000000001)
B.append(1000000001)

res = -1
K = K
j = 0
k = 0
for i in range(max_books):
    if  K >= 0:
        if A[j] <= B[k]:
            K -= A[j]
            j += 1
        else:
            K -= B[k]
            k += 1
        res += 1
    else:
        break

print(res)

Submission status: Wrong Answer

Solution code:
import itertools as it
def main():
    n,m,k=map(int,input().split())
    a = [0]
    a.extend(it.accumulate(map(int, input().split())))
    b = [0]
    b.extend(it.accumulate(map(int, input().split())))
    M = m
    ans = 0
    for A in range(n,-1,-1):
        aa = a[A]
        Kaa = k-aa
        for B in range(M,-1,-1):
            if b[B] <= Kaa:
                ans = max(ans, A+B)
                M = B
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n, m, k = nm()
a = nl()
b = nl()
ans = 0
sum_a = [0]*(n+1)
sum_b = [0]*(m+1)
for i in range(1, n+1):
    sum_a[i] = sum_a[i-1] + a[i-1]
for i in range(1, m+1):
    sum_b[i] = sum_b[i-1] + b[i-1]
ans = 0
j = m
for i in range(n+1):
    if sum_a[i] >= k:
        break
    while sum_b[j] > k - sum_a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

Solution code:
import io
import sys

_INPUT = """\
1 4 120
100 1 1 1 1 1 1 1 1 1 1
80 10 10 10 10
"""
sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

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


# 累積和
from itertools import accumulate
C = accumulate(A)
D = accumulate(B)

E = [0]
F = [0]
for c in C:
  if c > K: break
  E.append(c)

for d in D:
  if d > K: break
  F.append(d)

p(*E)
p(*F)

c = d = 0
ans = k = 0

for i, e in enumerate(E):
  for j, f in enumerate(F):
    if e + f > K: break
    ans = max(ans, i+j)

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()))
time = k
ans = 0
while (len(A)>0) and (len(B)>0):
    if A[0]>=B[0]:
        time -= B[0]
        ans += 1
        del B[0]
    else:
        time -= A[0]
        ans += 1
        del A[0]
    if time<0:
        print(ans-1)
        break
if time>0:
    C = A+B
    for i in range(len(C)):
        time -= C[0]
        ans += 1
        if ans<0:
            print(ans-1)
            break
    print(ans)

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()))
a=[0]*N
b=[0]*M
a[0]=A[0]
b[0]=B[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]
diff=2*10**9
count=0
for i in range(N):
    if K-a[i]<0:
        break
    j=bisect.bisect(b,K-a[i])-1
    count=max(count,(i+1)+(j+1))
print(count)

Submission status: Wrong Answer

Solution code:
import sys
nums=input().split()
a=int(nums[0])
b=int(nums[1])
n=int(nums[2])
lista=input().split()
listb=input().split()

acount=0
bcount=0
count=0
time=0
atime=0
btime=0
for i in lista:
  val=int(i)
  if val+atime>n:
    break
  atime+=val
  acount+=1
count=acount
btime=atime
for j in listb:
  valb=int(j)
  if valb+btime>n:
    break
  btime+=valb
  count+=1
  bcount+=1

for i in range(1,acount+1):
  bcount=count-i
  btime-=int(lista[acount-i])
  for j in range(bcount,b):
    valb=int(listb[j])
    if valb+btime>n:
      break
    btime+=valb
    bcount+=1
  if count<bcount:
    count=bcount
print(count)

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()))
 
T_A = [0, A[0]]
T_B = [0, B[0]]
for i in range(1, N):
  T_A.append(T_A[i] + A[i])
for j in range(1, M):
  T_B.append(T_B[j] + B[j])
      
book = 0
j = M
for i in range(len(T_A)):
  while 1:
    if K < T_A[i] + T_B[j]:
      break
    else:
      if i + j  > book:
        book = i + j
        j -= 1
      else:
        pass
    
print(book)

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(K)
B.append(K)

sumA = []
sumB = []

sumAi = 0
for i in range(N+1):
    sumAi += A[i]
    if sumAi > K:
        break
    else:
        sumA.append(sumAi)
AA = A[:i]

sumBj = 0
for j in range(M+1):
    sumBj += B[j]
    if sumBj > K:
        break
    else:
        sumB.append(sumBj)
BB = B[:j]

NN = len(AA)
MM = len(BB)

#Ares = [K-x for x in sumA]
#Bres = [K-x for x in sumB]

#invsumA=[]
#invsum=0
#for x in AA[::-1]:
#    invsum += x
#    invsumA.append(invsum)

#ans = NN

#timearray = np.zeros((NN,MM))


        
if NN == 0:
    ans = MM
else:
    ans = NN+MM
    time = sumA[-1]+sumB[-1]
    if time > K:
        for i in range(NN+MM):
            if AA[-1]>BB[-1]:
                nozoku = AA.pop(-1)
                time -= nozoku
                ans -= 1
            else:
                nozoku = BB.pop(-1)
                time -= nozoku
                ans -= 1
            if time <= K:
                break
        
    #    res = K-sumA[-1]
    #    resA = AA
    #    kakuB = []
    #    resN = len(resA)
    #    
    #    for j in range(MM):
    #        if BB[j] <= res:
    #            kakuB.append(BB[j])
    #            res-=BB[j]
    #        else:
    #            break
    #    kakuM = len(kakuB)
    #    
    #    process=True
    #    while process:
    #        invsum = 0
    #        for i in range(max(resN,kakuM)-1):
    #            invsum += resA[-i-1]
    #            if sumB[i+1] - invsum <= res:
    #                resA = resA[:-i-1]
    #                kakuB = BB[:i+2]
    #                resN = len(resA)
    #                kakuM = len(kakuB)
    #                break
    #            if i == max(resN,kakuM)-2:
    #                process= False
    #    
    #    ans = resN+kakuM
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,M,K=pin()
    A=list(reversed([*pin()]))
    B=list(reversed([*pin()]))
    ans=0
    for i in range(5*(10**6)):
        if len(A)==0:
            if len(B)==0:
                break
            else:
                a=10**10
                b=B[-1]
        elif len(B)==0:
            b=10**10
            a=A[-1]
        else:
            a=A[-1]
            b=B[-1]

        if min(a,b)>K:
            break

        if a>b:
            K-=b
            B.pop()
        else:
            K-=a
            A.pop()
        ans+=1
    print(ans)
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
alen,blen,k = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
max = 0

bcount = blen
while sum(blist[:bcount]) > k:
    bcount -= 1

for a in range(alen+1):
    acount = alen-a
    asum = sum(alist[:acount])
    while asum + sum(blist[:bcount+1]) > k:
        bcount -= 1
    if acount + bcount > max and asum + sum(blist[:bcount])<=k:
        max = acount + bcount

print(max)

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()))
s = 0
ans = 0
c = sum(A)
d = sum(B)
if k >= d+c:
  print(n+m)
else:
  while True:
    if A == [] and B == []:
      break
    elif A == []:
      s += B[0]
      B.pop(0)
      if s <= k:
        ans += 1
      else:
        break
    elif B == []:
      s += A[0]
      A.pop(0)
      if s < k:
        ans += 1
      else:
        break
    else: 
      if A[0] >= B[0] :
        s += B[0]
        B.pop(0)
        if s <= k:
          ans += 1
        else:
          break
      else :
        s += A[0]
        A.pop(0)
        if s <= k:
          ans += 1
        else:
          break
  print(ans)

Submission status: Wrong Answer

Solution code:
# 日本語を入力できるようにするために上記一文が必要


n, m, k = map( int, input().split() )
a_list = list( map( int, input().split() ) )
b_list = list( map( int, input().split() ) )

read_time = 0
read_count = 0
while read_time < k:
        if not a_list and not b_list:
                read_count += 1
                break
        elif not a_list and b_list:
                read_count += 1
                read_time += b_list[0]
                b_list.remove( b_list[0])
        elif a_list and not b_list:
                read_count += 1
                read_time += a_list[0]
                a_list.remove( a_list[0])
        elif a_list[0] <= b_list[0]:
                read_time += a_list[0]
                a_list.remove( a_list[0])
                read_count += 1
        else:
                read_time += b_list[0]
                b_list.remove( b_list[0])
                read_count += 1

print(read_count - 1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_N = list(map(int, input().split()))
B_M = list(map(int, input().split()))
 
A_ind = 0
B_ind = 0
count = K
ans = 0
 
for i in range(N+M+1): 
  if A_N[0] < B_M[0]:
    if count >= A_N[0]:
      count -= A_N.pop(0)
      ans += 1
      if len(A_N) == 0:
        A_N.append(1000000001)
  else:
    if count >= B_M[0]:
      count -= B_M.pop(0)
      ans += 1
      if len(B_M) == 0:
        B_M.append(1000000001)
  if A_N[0] == 1000000001:
    if B_M[0] == 1000000001:
      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 = 0
b = 0
ans = 0
sumA = 0
sumB = 0
for i in range(len(A)):
  sumA =sumA +A[i]
  if sumA <= k:
    a += 1
  else:
    break

for i in range(len(B)):
  sumB =sumB +B[i]
  if sumB <= k:
    b += 1
  else:
    break
#print(a)
#print(b)
ab = a+b
su = sum(A[0:a]) + sum(B[0:b])
if su <= k:
  print(ab)
else:
  for i in range(min(a,b)):
    ans += 1
    if A[a-1] >= B[b-1]:
      if su - A[a-1] <= k:
        break
      else:
        a -=1
    else:
      if su - B[b-1] <= k:
        break
      else:
        b -=1   
  print(ab-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_max = 0
B_sum = 0
B_max = 0
best_num = 0

flag = True # Aだけ読んで時間が尽きるかどうか

# Aを最大まで読んだ時の冊数と時間
A_max = N
A_sum = 0
for i in range(N):
    A_sum += A[i]
    if A_sum > K:
        A_sum -= A[i]
        A_max = i
        flag = False
        break
A = A[0:A_max]
now_num = A_max # 今の読んだ数
mixsum = A_sum # A,Bを合わせた時間
b_num = 0 # bを読んだ数
if flag:
    now_num += M
    b_num = M
    for i in range(M):
        mixsum += B[i]
        if mixsum > K:
            mixsum -= B[i]
            now_num = A_max + i
            b_num = i  #i冊読んだので次取るならi番目から
            break
A.reverse()
best_num = now_num
for i in range(A_max):
    mixsum -= A[i]
    now_num -= 1
    for j in range(b_num, M):
        mixsum += B[j]
        now_num += 1
        if mixsum > K:
            mixsum -= B[j]
            now_num -= 1
            b_num = j
            break
    if now_num > best_num:
        best_num = now_num
print(best_num)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.reverse()
b.reverse()
ans=0
while(k>=0):
 if len(a)==0:
     if len(b)>0:
         k-=b[len(b)-1]
         b.pop()
     else:
         break
 elif len(b)==0:
     if len(a)>0:
         k-=a[len(a)-1]
         a.pop()
     else:
         break
 elif a[len(a)-1]>b[len(b)-1]:
     k-=b[len(b)-1]
     b.pop()
 else:
     k-=a[len(a)-1]
     a.pop()
 if k>=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()))
a.append(300000)
b.append(300000)
c = []
e = 0
f = 0
for i in range(len(a)):
    b.append(a[i])
while sum(c) < k:
    if a[e] <= b[f]:
        c.append(a[e])
        e += 1
    else:
        c.append(b[f])
        f += 1
        
if 300000 in c:
    c.remove(300000)
if sum(c) == k:
    print(len(c))
else:
    print(len(c)-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()))
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])
print(a, b)

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

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
A.reverse()
B.reverse()
time = 0
cnt = 0
while A or B:
    if A and B:
        if A[-1] <= B[-1]:
            time += A.pop()
            if time > k:
                print(cnt)
                exit()
            cnt += 1
        else:
            time += B.pop()
            if time > k:
                print(cnt)
                exit()
            cnt += 1
    elif A:
        time += A.pop()
        if time > k:
            print(cnt)
            exit()
        cnt += 1
    else:
        time += B.pop()
        if time > k:
            print(cnt)
            exit()
        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()))

aindex = 0
bindex = 0
timeconsumed = 0
readbooks = 0
L = 10 ** 10
while True:
    if aindex >= n and bindex >= m:
        break
    if aindex >= n:
        timeconsumed += B[bindex]
        bindex += 1
    elif bindex >= m:
        timeconsumed += A[aindex]
        aindex += 1
    else:
        atime = A[aindex]
        btime = B[bindex]
        if atime < btime:
            timeconsumed += atime
            aindex += 1
        else:
            timeconsumed += btime
            bindex += 1
    if timeconsumed > k:
        break
    readbooks += 1
print(readbooks)

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()))
count=0
check=0
i=0
book=0
while(1):
    if(len(a)==0):
        count+=b[0]
        book+=1
        i=b.pop(0)
    elif(len(b)==0):
        count+=a[0]
        book+=1
        i=a.pop(0)
    elif(a[0]<b[0]):
        count+=a[0]
        book+=1
        i=a.pop(0)
    else:
        count+=b[0]
        book+=1
        i=b.pop(0)
    if(count>(k)):
        book=book-1
        break
    elif(len(a)==0):
      	if(len(b)==0):
	        break
print(book)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import sys
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.append(10**10)
b.append(10**10)
l=[]
while len(a)>1 or len(b)>1:
    A=a.pop(0)
    B=b.pop(0)
    if A<=B:
        l.append(A)
        b.insert(0,B)
    else:
        l.append(B)
        a.insert(0,A)
cumsum=list(accumulate(l))
print(bisect.bisect_right(cumsum,k))

Submission status: Wrong Answer

Solution code:
na,nb,k = map(int, input().split())
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))


def get_bcnt( usek,tb=tb ):
    tb_sum = [ sum(tb[:i]) + tt for i, tt in enumerate(tb)]
    tb_sum_tf = [ i <= usek for i in tb_sum]
    
    if False in tb_sum_tf:
        return tb_sum_tf.index(False)
    else:
        return len(tb)
    
 
readbook = [ i+1 + get_bcnt( k - sum( ta[:i] ) )  for i in range(na) if sum( ta[:i] ) <= k ]
readbook.append( get_bcnt(k) )

Submission status: Wrong Answer

Solution code:

def count_book(NMK,A,B):
  i=0
  j=0
  sum = 0
  count = 0
  I = len(A)
  J = len(B)
  while sum<=NMK[2]:
    if i < I and j < J:
      if A[i]<B[j]:
        sum = sum + A[i]
        i = i + 1
        if sum<=NMK[2]:
         count = count + 1
         continue
      else:
        sum = sum + B[j]
        j = j + 1
        if sum<=NMK[2]:
         count = count + 1
         continue
 
    if i < I and j >= J:
      sum = sum + A[i]
      i = i + 1
      if sum<=NMK[2]:
        count = count + 1
        continue

    if i >= I and j < J:
      sum = sum + B[j]
      j = j + 1
      if sum<=NMK[2]:
        count = count + 1
        continue

    if i >= I and j >= J:
      break
      
  print(count)

NMK = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count_book(NMK,A,B)

Submission status: Wrong Answer

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

timer = 0
C = 0
R = 0

while timer <= K and R <= (N+M):
  C += 1
  if A == []:
    A.append(10^9)
  if B == []:
    B.append(10^9)
  if A[0] <= B[0]:
    timer += A.pop(0)
    
  elif A[0] > B[0]:
    timer += B.pop(0)
  R += 1

    
print(C-1)

Submission status: Wrong Answer

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

dp = {}



def solve(K: int, A: "List[int]", B: "List[int]"):
    cost_a = calc_cost2(A)
    cost_b = calc_cost2(B)
    i, j = 0, 0
    c = K
    num = 0
    # print(cost_a)
    # print(cost_b)
    while i < len(cost_a) or j < len(cost_b):
        if i == len(cost_a):
            if c < B[j]:
                break
            c -= B[j]
            j += 1
        elif j == len(cost_b):
            if c < A[i]:
                break
            c -= A[i]
            i += 1
        elif cost_b[j] <= cost_a[i]:
            if c < B[j]:
                break
            c -= B[j]
            j += 1
        elif cost_a[i] < cost_b[j]:
            if c < A[i]:
                break
            c -= A[i]
            i += 1
        else:
            print('????', i, j)
        num += 1

    return num

def calc_cost2(list):
    l2 = [0 for _ in list]
    pre = 0
    for i in range(len(list)):
        l2[i] = pre + list[i]
        pre = l2[i]
    return l2

def solve4(K: int, A: "List[int]", B: "List[int]"):
    queue = deque()
    if A[0] <= K: queue.append((K, 0, 0, 0))
    if B[0] <= K: queue.append((K, 0, 0, 0))
    c_max = 0
    while queue:
        rem, dep, i, j = queue.popleft()
        c_max = max(c_max, dep)
        dp[f'{i}_{j}'] = True
        if i < len(A) and A[i] <= rem and f'{i+1}_{j}' not in dp:
            queue.append((rem - A[i], dep + 1, i + 1, j))
        if j < len(B) and B[j] <= rem and f'{i}_{j+1}' not in dp:
            queue.append((rem - B[j], dep + 1, i, j + 1))
    return c_max


def solve3(K: int, A: "List[int]", B: "List[int]"):
    cost_a = calc_cost(A)
    cost_b = calc_cost(B)
    i, j = 0, 0
    c = K
    num = 0
    print(cost_a)
    print(cost_b)
    while i < len(cost_a) or j < len(cost_b):
        tmp = []
        if i == len(cost_a) or cost_b[j] < cost_a[i]:
            if c < B[j]:
                break
            c -= B[j]
            j += 1
        elif j == len(cost_b) or cost_a[i] < cost_b[j]:
            if c < A[i]:
                break
            c -= A[i]
            i += 1
        else:
            print('????', i, j)
        num += 1

    return num

def calc_cost(list):
    l2 = [0 for _ in list]
    pre = 0
    for i in range(len(list)):
        j = len(list) - 1 - i
        l2[j] = pre + list[j]
        pre = l2[j]
    return l2

def solve2(K: int, A: "List[int]", B: "List[int]"):
    if K == 0: return 0

    r = _solve(0, K, A, B, 0, 0)
    return r


def _solve(current:int, K: int, A: "List[int]", B: "List[int]", i, j):
    key = f'{i}_{j}'
    if key in dp: return dp[key]

    res = [current]
    if i < len(A) and A[i] <= K:
        res.append(_solve(current + 1, K - A[i], A, B, i + 1, j))

    if j < len(B) and B[j] <= K:
        res.append(_solve(current + 1, K - B[j], A, B, i, j + 1))

    dp[key] = max(res)
    return dp[key]


# 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]"
    N, M, K = [int(k) for k in input().split()]
    A = [int(k) for k in input().split()]
    B = [int(k) for k in input().split()]
    print(solve(K, A, B))

if __name__ == '__main__':
    main()

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


while k >= p:
  if len(a) == 0 and len(b) == 0:
    break;
  elif len(a) == 0:
    p = b.pop(0)
  elif len(b) == 0:
    p = a.pop(0)    
  else:
    if a[0] < b[0]:
      p = a.pop(0)
    else:
      p = b.pop(0)

  if k >= p: 
    k -= p
    c += 1
  
print(c)

Submission status: Wrong Answer

Solution code:
nums=input()
nums=nums.split()
M,N,K = int(nums[0]),int(nums[1]),int(nums[2])

al=input()
al2=al.split()
for n in range(M):
    al2[n] = int(al2[n])

bl=input()
bl2=bl.split()
for n in range(N):
    bl2[n] = int(bl2[n])

count=0

ai=0
bi=0

aflag,bflag=0,0

while 1:
    if al2[ai] <= bl2[bi] and al2[ai] <= K and aflag != 1:
        K = K-al2[ai]
        if ai == M-1:
            aflag=1
        else:
            ai+=1
        count+=1
        

    elif al2[ai] > bl2[bi] and bl2[bi] <= K and bflag != 1:
        K = K-bl2[bi]
        if bi == N-1:
            bflag=1
        else:
            bi+=1
        count+=1
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
from bisect import bisect

N, M, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
A = A[:bisect([x for x in itertools.accumulate(A)], K)]
B = B[:bisect([x for x in itertools.accumulate(B)], K)]
ans = []
t = 0
while True:
    if t >= K:
        break
    if len(A) !=0 and len(B)!=0:
        c = min(A[0], B[0])
        if c == A[0]:
            t += A[0]
            ans.append(A.pop(0))
        else:
            t += B[0]
            ans.append(B.pop(0))
    else:
        if len(A)==0:
            ans+=B
            break
        else:
            ans+=A
            break
print(bisect([x for x in itertools.accumulate(ans)], K))

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

A_cum = []
B_cum = []

cum = 0
for a in A:
  cum += a
  A_cum.append(cum)

cum = 0
for b in B:
  cum += b
  B_cum.append(cum)

ans = 0  
for i, a in enumerate(A_cum):
  rest = k-a
  if rest<=0:
    continue
  
  ans = max(ans, bisect.bisect_right(B_cum, rest)+i+1)
  
print(ans)