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:
def main():
    N, M, K = map(int, input().split())
    A_int_list = list(map(int, input().split()))
    B_int_list = list(map(int, input().split()))

    min_sum = 0

    for i in range(N + M):
        if len(A_int_list) != 0 and len(B_int_list) != 0:
            if A_int_list[0] < B_int_list[0]:
                min_sum += A_int_list[0]
                A_int_list.pop(0)
            else:
                min_sum += B_int_list[0]
                B_int_list.pop(0)

        elif len(A_int_list) == 0:
            min_sum += B_int_list[0]
            B_int_list.pop(0)

        elif len(B_int_list) == 0:
            min_sum += A_int_list[0]
            A_int_list.pop(0)

        if K < min_sum:
            print(i)
            exit()

    print(N + M)
    exit()


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

dp = [[0] * (M + 1) for _ in range(N + 1)]
  
res = 0

for i in range(1, N + 1):
  dp[i][0] = dp[i - 1][0] + A[i - 1]
  if dp[i][0] <= K:
    res = max(res, i)
  else:
    break

for j in range(1, M + 1):
  dp[0][j] = dp[0][j - 1] + B[j - 1]
  if dp[0][j] <= K:
    res = max(res, j)
  else:
    break

for i in range(1, N + 1):
  for j in range(1, M + 1):
    dp[i][j] = min(dp[i - 1][j] + A[i - 1], dp[i][j - 1] + B[j - 1])
    if dp[i][j] <= K:
      res = max(res, i + j)
    else:
      break

print(res)

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()]
inf = 10**9
a.append(inf)
b.append(inf)
total = 0
count = 0

while a[0]!=inf and b[0]!=inf:

    if a[0] < b[0]:
        mini = a.pop(0)
        total += mini
    else:
        mini = b.pop(0)
        total += mini
        
    if total > k:
        break
    count += 1
    
if len(a) != 1 and len(b) != 1:
    print(count)
    exit()
    
elif len(a) == 1:
    while 1:
        total += b.pop(0)
        if total > k:
            break
        count += 1
elif len(b) == 1:
    while 1:
        total += a.pop(0)
        if total > k:
            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()))
aa=[0]*n
ba=[0]*m
aa[0]=a[0]
for i in range(1,n):
  aa[i]=aa[i-1]+a[i]
for i in range(1,m):
  ba[i]=ba[i-1]+b[i]
aa=[0]+aa
ba=[0]+ba
import bisect as bi
ax=bi.bisect_right(aa,k)-1
ans=0
for i in range(ax+1):
  kk=k-aa[ax-i]
  bx=bi.bisect_right(ba,kk)-1
  t=ax+bx-i
  ans=max(ans,t)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M, K = LI()
A = LI()
B = LI()
A.append(INF)
B.append(INF)

now = 0
a = 0
b = 0
ans = 0
while True:
    m = min(A[a], B[b])

    if now + m <= K:
        now += m
        ans += 1

        if m == A[a]:
            a += 1
        else:
            b += 1
        if a >= N:
            a = N
        if b >= M:
            b = M        
    else:
        break

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

    r = 0
    a = 0
    b = 0
    while k > 0 and (a < n or b < m):
        if a == n:
            time = B[b]
        elif b == m:
            time = A[a]
        else:
            time = min(A[a], B[b])

        if k - time < 0:
            break

        r += 1
        k -= time

        if a == n:
            b += 1
        elif b == m:
            a += 1
        else:
            if A[a] >= B[b]:
                b += 1
            else:
                a += 1

    print(r)


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

from collections import deque
d = deque()

buf_K = K
ans = 0
max_i = 0
for i in range(N):
    if buf_K >= A[i]:
        buf_K -= A[i]
        d.append(A[i])
        ans += 1
    else:
        break
max_num = ans

for j in range(M):
    if buf_K >= B[j]:
        buf_K -= B[j]
        ans += 1
        if ans > max_num:
            max_num = ans
    else:
        while d:
            buf_K -= d.popleft()
            ans -= 1
            if buf_K >= B[j]:
                buf_K -= B[j]
                ans += 1
                if ans > max_num:
                    max_num = ans
                break

        # for i in range(max_i,-1,-1):
        #     buf_K -= A[i]
        #     ans -= 1
        #     if buf_K > B[j]:
        #         buf_K -= B[j]
        #         ans += 1
        #         max_i = i-1
        #         if ans > max_num:
        #             max_num = ans
        #         break
        #     elif i == 0:
        #         break

print(max_num)

Submission status: Wrong Answer

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

from collections import deque
a = deque(a)
b = deque(b)
# print(len(a),len(b))
c = 0
ans = 0
while (len(a)>0 or len(b)>0)&(k>0):
    if len(a)>0 and len(b)>0: 
        if (a[0]<b[0])&(a[0]<=k):
                k-=a[0]
                a.pop()
                ans +=1
                # print("a")
        elif (a[0]>=b[0])&(b[0]<=k):
                k-=b[0]
                b.pop()
                ans+=1

                # print("b")
        
        else:
                c=1
                break
    elif len(a)==0 :
        if b[0]>k:
            break
        else:
            k-=b[0]
            b.pop()
            ans +=1

    elif len(b)==0 :
        if a[0]>k:
            break
        else:
            k-=a[0]
            a.pop()
            ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    m = kwargs["m"]
    k = kwargs["k"]
    A = collections.deque(kwargs["A"])
    B = collections.deque(kwargs["B"])
    tmp_time = sum(A)
    tmp_num = len(A)
    res = 0

    while len(A) > 0:
        while tmp_time <= k and len(B) > 0:
            tmp_time += B.popleft()
            tmp_num += 1

            if tmp_time <= k:
                res = max(tmp_num, res)

        tmp_time -= A.pop()
        tmp_num -= 1

        if tmp_time <= k:
            res = max(tmp_num, res)

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"], kwargs["m"], kwargs["k"] = [int(i) for i in cin]

    cin = input().split()
    kwargs["A"] = [int(i) for i in cin]

    cin = input().split()
    kwargs["B"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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()))
book=0
ai=0
bi=0
if K>=sum(A)+sum(B):
    print(N+M)
else:
    while K>=0:
        #print(K,ai,bi)
        if ai==N:
            K-=B[bi]
            bi+=1
            book+=1
        elif bi==M:
            K-=A[ai]
            ai+=1
            book+=1
        elif A[ai]<B[bi]:
            K-=A[ai]
            ai+=1
            book+=1
        elif A[ai]>=B[bi]:
            K-=B[bi]
            bi+=1
            book+=1
    print(book-1)

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()))
ca = A[:]
cb = B[:]

for i in range(N-1):
  ca[i+1] += ca[i]
for i in range(M-1):
  cb[i+1] += cb[i]
ans = 0
for i in range(N):
  if ca[i] <= K:
    idx = bisect.bisect_right(cb, K-ca[i])
  else:
    continue

  ans = max(ans, i+idx+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()))
current = 0
count = 0

while True:
    if(current > k):
        count -= 1
        break;
    if bool(a) == False and bool(b) == False:
        break;
    elif bool(a) == False:
        current += b[0]
        b.pop(0)
        count += 1
    elif bool(b) == False:
        current += a[0]
        a.pop(0)
        count += 1

    
    else:
        if(a[0] >= b[0]):
            current += b[0]
            b.pop(0)
            
        else:
            current += a[0]
            a.pop(0)
        count += 1

print(count)

Submission status: Wrong Answer

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

N = a[0]
M = a[1]
K = a[2]

t = 0
i = 0
j = 0
count = 0
time = 0
TT = 0
while TT == 0 :
  if len(b) == 0 and len(c) == 0 :
    break
  if len(b) == 0 :
    time = time + c[0]
    if time > K :
      time = time - c[0]
      break
    count = count + 1
    c.remove(c[0])
  elif len(c) == 0 :
    if time > K :
      time = time - b[0]
      break
    time = time + b[0]
    b.remove(b[0])
    count = count + 1
  elif b[0] <= c[0] :
    time = time + b[0] 
    if time > K :
      time = time - b[0]
      break
    b.remove(b[0])
    count = count + 1
  else :
    time = time + c[0]
    if time > K :
      time = time - c[0]
      break
    c.remove(c[0])
    count = 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()))

count = 0

while(k > 0):
    if len(a) == 0:
        if b[0] <= k:
            k -= b[0]
            count += 1
            del b[0]
        else:
            break
    elif len(b) == 0:
        if a[0] <= k:
            k -= a[0]
            count += 1
            del a[0]
        else:
            break
    elif a[0] < b[0]:
        if a[0] <= k:
            k -= a[0]
            count += 1
            del a[0]
        else:
            break

    else:
        if b[0] <= k:
            k -= b[0]
            count += 1
            del b[0]
        else:
            break

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

def main():
    N,M,K  = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AS = list(itertools.accumulate(A))
    BS = list(itertools.accumulate(B))
    Amaxin = bisect.bisect_right(AS, K)
    Bmaxin = bisect.bisect_right(BS, K)
    ans = max(Amaxin-1,Bmaxin-1)
    index = 0
    for i in reversed(range(0,Amaxin)):
        while index<M and AS[i] + BS[index] <=K:
            index+=1
        ans = max(i+index+1,ans)
    index = 0
    for i in reversed(range(0,Bmaxin)):
        while index<N and BS[i] + AS[index] <=K:
            index+=1
        ans = max(i+index+1,ans)



    print(max(ans,0))

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

c = 0
ac = 0
bc = 0
time = 0

while True:
    if time > k:
        c = c - 1
        print(c)
        break
    elif len(a_list) == ac and len(b_list) == bc:
        print(c)
        break
    else:
        c += 1
        if len(a_list) == ac:
            time += b_list[bc]
            bc += 1
        elif len(b_list) == bc:
            time += a_list[ac]
            ac += 1
        else:
            if a_list[ac] < b_list[bc]:
                time += a_list[ac]
                ac += 1
            else:
                time += b_list[bc]
                bc += 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()))
MAX = 10 ** 9 +1
A.append(MAX)
B.append(MAX)
a, b, time = 0, 0, 0
for i in range(0,len(A)+len(B)):
    if A[a] < B[b]:
        time += A[a]
        a += 1
    else:
        time += B[b]
        b += 1
    if time >= K:
        break
print(i)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ai, bi = 0, 0
a.append(10**10)
b.append(10**10)
cnt = 0
tt = 0
while True:
    if a[ai] > b[bi]:
        if (tt + b[bi] > k):
            break
        cnt += 1
        tt += b[bi]
        bi += 1
    else:
        if (tt + a[ai] > k):
            break
        cnt += 1
        tt += a[ai]
        ai += 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()))

ansA = 0
ansB = 0
cntA = 0
a = 0
cntB = 0
b = 0
ta = 0
tb = 0
while cntA < N:
    if ta + A[cntA] <= K:
        ta += A[cntA]
        cntA += 1
        ansA += 1
    else:
        break
while b < M:
    if ta + B[b] <= K:
        ta += B[b]
        b += 1
        ansA += 1
    else:
        break

while cntB < M:
    if tb + B[cntB] <= K:
        tb += B[cntB]
        cntB += 1
        ansB += 1
    else:
        break
while a < N:
    if tb+ A[a] <= K:
        tb += A[a]
        a += 1
        ansB += 1
    else:
        break

print(max(ansA, ansB))

Submission status: Wrong Answer

Solution code:
anum, bnum, time= map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
counta = 0
countb = 0
temp = [0]

for i in range(anum + bnum):
    if counta >= anum:
        temp.append(temp[-1] + b[countb])
        countb += 1
    elif countb >= bnum:
        temp.append(temp[-1] + a[counta])
        counta += 1
    else:
        if a[counta] <= b[countb]:
            temp.append(temp[-1] + a[counta])
            counta += 1
        else:
            temp.append(temp[-1] + b[countb])
            countb += 1

for i in range(anum + bnum):
    if temp[i] > time:
        print(i - 1)
        break
else:
    print(anum + bnum)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, m, k = map(int, input().split())
    from collections import deque
    A = deque(list(map(int, input().split())))
    B = deque(list(map(int, input().split())))
    t = 0
    count = 0
    while A or B:
        if len(A) == 0:
            t += B.popleft()
        elif len(B) == 0:
            t += A.popleft()
        else:
            if A[0]> B[0] :
                t += B.popleft()
            else:
                t += A.popleft()

        if t <= k:
            count +=1
        else:
            break
        
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    now_A = 0
    now_B = 0
    ans = 0
    minute = 0

    for _ in range(N + M):
        AA = A[now_A] if now_A < N else 10 ** 9 + 1
        BB = B[now_B] if now_B < M else 10 ** 9 + 1

        minute += min(AA, BB)
        if (minute > K or (AA == BB and BB == 10 ** 9 + 1)):
            break

        ans += 1
        if (AA < BB):
            now_A += 1
        if (AA >= BB):
            now_B += 1

    print(ans)

resolve()

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()))
kotei=k
ans=0
cnt=0

if kotei>=sum(a):
  cnt+=len(a)
  ans=max(ans,cnt)
else:
  x=kotei
  i=0
  while x>0:
    x-=a[i]
    i+=1
    cnt+=1
  ans=max(ans,cnt-1)

for j in range(m):
  kotei-=b[j]
  if kotei<0:
    break
  cnt=j+1
  if kotei>=sum(a):
    cnt+=len(a)
    ans=max(ans,cnt)
    continue
  else:
    x=kotei
    i=0
    while x>0:
      x-=a[i]
      i+=1
      cnt+=1
    ans=max(ans,cnt-1)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
m = 0 
for i in range(len(A) + len(B)):
    if len(A) == 0 and len(B) == 0:
        print(ans-1)
        exit()
    elif len(A) > 0 and len(B) > 0:
        if A[0] < B[0]:
            m += A[0]
            A.pop(0)
            ans += 1
        else:
            m += B[0]
            B.pop(0)
            ans += 1
    elif len(A) > 0 and len(B) == 0:
        m += A[0]
        A.pop(0)
        ans += 1
    elif len(A) == 0 and len(B) > 0:
        m += B[0]
        B.pop(0)
        ans += 1
    if m > K:
        print(ans-1)
        exit()
    elif m == K:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque

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


count = 0
time = 0
#もし先にどっちかの玉が尽きた時の問題。
for i in range(200001):
    #本が尽きていない。
    if len(A) != 0 and len(B) != 0:

        if A[0] < B[0]:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()

        elif A[0] > B[0]:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        else:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
    else:
        #どっかの本が尽きている。
        if len(A) == 0 and len(B) != 0:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        elif len(A) != 0 and len(B) == 0:
            time = time +A[0]
            if time <= K:
                count = count + 1
                A.popleft()
        elif len(A) == 0 and len(B) == 0:
            print(count)
            sys.exit()
               


print(count)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a_list = [0]+list(map(int,input().split()))
b_list = list(map(int,input().split()))
max_book = 0
temp_ki = 0
break_flag = False
for i in range(len(a_list)):
    temp_ki += a_list[i]
    if temp_ki > k:
        if i-1>max_book:
            max_book = i-1
        break_flag = True
        break
    temp_kj = temp_ki
    for j in range(len(b_list)):
        temp_kj += b_list[j]
        if temp_kj > k:
            if i+j>max_book:
                max_book = i+j
            break_flag = False
            break
if break_flag:
    print(max_book)
else:
    print(n+m)

Submission status: Wrong Answer

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

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

i,a_summ=0,0
mx=0
while(a_summ<=k and i<len(a)):
    a_summ+=a[i]
    if a_summ<=k:
        j,summ=0,a_summ
        count = i+1
        while(summ<=k and j<len(b)):
            if summ+b[j]<=k:
                count+=1
            summ+=b[j]
            j+=1
        if count>mx:
            mx=count
    i+=1
print(mx)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.array(A)
B = np.array(B)

A_sum = np.array( list(map(lambda i: np.sum(A[:i+1]), range(N))) )
B_sum = np.array( list(map(lambda i: np.sum(B[:i+1]), range(M))) )

A_sum_lim = A_sum[np.where(A_sum<=K)]
B_sum_lim = B_sum[np.where(B_sum<=K)]
ans = 0

for i in range(len(A_sum_lim)):
    for j in range(len(B_sum_lim)):
        if A_sum_lim[i]+B_sum_lim[j]<=K and ans<i+j+2:
            ans = i+j+2

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

total = 0
i = 0
cnt = 0

while total < k:
    if len(A) == 0 and len(B) == 0:
        break
    
    if len(A) == 0:
        A = B
        
    if len(B) == 0:
        B = A
        
    total += min(A[0],B[0])
    if total > k:
        break
    
    if min(A[0],B[0]) == A[0]:
        A.pop(0)
    else:
        B.pop(0)
        
    cnt += 1
    
print(cnt)

Submission status: Wrong Answer

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

A = input().split(" ")
B = input().split(" ")

Num = N + M

read_time = 0
count = 0
for i in range(Num):
  if len(A) > 0 and len(B) > 0:
    if int(A[0]) >= int(B[0]):
      read_time = read_time + int(B[0])
      del B[0]
    elif int(A[0]) < int(B[0]):
      read_time = read_time + int(A[0])
      del A[0]
    if read_time > K:
      break
    else:
      count = count + 1
      
  elif len(A) == 0:
    read_time = read_time + int(B[0])
    del B[0]
    if read_time > K:
      break
    else:
      count = count + 1
      
  elif len(B) == 0:
    read_time = read_time + int(A[0])
    del A[0]
    if read_time > K:
      break
    else:
      count = count + 1

print(count)

Submission status: Wrong Answer

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

a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]

read = 0
cnt = 0
ai = 0
bi = 0
while read < k:
	if ai >= n and bi >= m:
		break
	elif ai >= n:
		read += b[bi]
		cnt += 1
		bi+= 1
	elif bi >= m:
		read += a[ai]
		cnt += 1
		ai += 1
	elif a[ai] < b[bi]:
		read += a[ai]
		cnt += 1
		ai += 1
	else:
		read += b[bi]
		cnt += 1
		bi += 1
	if read > k:
		cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
an,bm,khun = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
alist.append(khun)
blist.append(khun)
count = 0
for i in range(min(an,bm)):
    if alist[i]<=blist[i] and khun >= alist[i]:
        khun -= alist[i]
        count += 1
        if alist[i+1]>=blist[i]:
            khun -= blist[i]
            count += 1
    elif khun >= blist[i]:
        khun -= blist[i]
        count += 1
        if alist[i]<=blist[i+1]:
            khun -= alist[i]
            count +=1
    else:
        break;
print(count)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(100000000000000000)
B.append(100000000000000000)
A.reverse()
B.reverse()


ans = 0
c = 0
while True:
  if A[-1] >= B[-1]:
    b = B.pop()
    if ans+b > X:
      break
    ans += b
    c += 1
  else:
    a = A.pop()
    if ans+a > X:
      break
    ans += a
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answer=0
numbers=[]
a=0
b=0
while a<N and b<M:
    if A[a]>=B[b]:
        numbers.append(B[b])
        b+=1
    else:
        numbers.append(A[a])
        a+=1

if b==M:
    for a in A[a:]:
        numbers.append(a)
else:
    for b in B[b:]:
        numbers.append(b)
whole=0
for a in range(N+M):
    whole+=numbers[a]
    if whole<=K:
        answer+=1
    else:
        break
print(answer)

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で上から何番目の本をみているか管理する
i, j = 0, 0
ans = 0
while True:
    if i is None and j is None:
        break
    elif i is None and j is not None:
        now_book_cost = b[j]
        if j == len(b)-1:
            i = None
        else:
            j += 1
    elif j is None and j is not None:
        now_book_cost = a[i]
        if i == len(a)-1:
            i = None
        else:
            i += 1
    elif a[i] <= b[j]:
        now_book_cost = a[i]
        if i == len(a)-1:
            i = None
        else:
            i += 1
    else:
        now_book_cost = b[j]
        if j == len(b)-1:
            i = None
        else:
            j += 1
    
    if now_book_cost <= k:
        ans += 1
        k -= now_book_cost
    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()))

AL = []
BL = []
a = 0
for i in A:
    a += i
    AL.append(a)
a = 0
for i in B:
    a += i
    BL.append(a)

#print(AL)
#print(BL)

a = 0
for i in range(len(AL)):
    if AL[i] > k:
        a = i
        break
else:
    a = len(AL)

b = 0
for i in range(len(BL)):
    if BL[i] > k:
        b = i
        break
else:
    b = len(BL)

#print(a,b)

m = a

while True:
    t = k-AL[a-1]
    for i in reversed(range(b)):
        if t-BL[i]>=0:
            if m < a + i +1:
                m = a + i +1
            break
    a += -1
    if a < 0:
        break
print(m)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

def main(N, M, K, A, B):
    count = 0
    time = 0
    while time >= 0 and time <= K:
        if len(A) == 0 and len(B) == 0:
            break
        elif len(A) != 0 and (len(B) == 0 or A[0] <= B[0]):
            if time + A[0] > K:
                break
            count += 1
            time += A[0]
            A = A[1:]
        elif len(B) != 0 and (len(A) == 0 or A[0] > B[0]):
            if time + B[0] > K:
                break
            count += 1
            time += B[0]
            B = B[1:]
    return count


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8, i8, i8, i8)

    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(main(N, M, K, 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()))

ai = 0
bi = 0
ans = 0

for _ in range(n+m):
    if ai < n:
        a = A[ai]
    else: 
        a = 10e10
    if bi < m:
        b = B[bi]
    else:
        b = 10e10
    if a > b:
        k -= b
        bi += 1
    else:
        k -= a
        ai += 1
    if k < 0:
        break
    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()))
ans1=0
tot=0
i=0
j=0
while(i<n and j<m):
    if(a[i]<=b[j]):
        if(tot+a[i]<=k):
            ans1+=1;
            tot+=a[i]
            i+=1
        else:
            break
    else:
        if(tot+b[j]<=k):
            ans1+=1
            tot+=b[j]
            j+=1
        else:
            break
if(tot<k):
    while(j<m):
        if(tot+b[j]<=k):
            ans1+=1
            tot+=b[j]
            j+=1
        else:
            break
    while(i<n):
        if(tot+a[i]<=k):
            ans1+=1;
            tot+=a[i]
            i+=1
        else:
            break
ans2=0
tot=0
i=0
j=0
while(i<n and j<m):
    if(a[i]<b[j]):
        if(tot+a[i]<=k):
            ans2+=1;
            tot+=a[i]
            i+=1
        else:
            break
    else:
        if(tot+b[j]<=k):
            ans2+=1
            tot+=b[j]
            j+=1
        else:
            break
if(tot<k):
    while(j<m):
        if(tot+b[j]<=k):
            ans2+=1
            tot+=b[j]
            j+=1
        else:
            break
    while(i<n):
        if(tot+a[i]<=k):
            ans2+=1;
            tot+=a[i]
            i+=1
        else:
            break
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

ans=0
now=0
acnt=0
bcnt=0
for i in range(n):
    if now+a[i]<=k:
        now+=a[i]
        acnt+=1
for i in range(m):
    if now+b[i]<=k:
        now+=b[bcnt]
        bcnt+=1
ans=acnt+bcnt

tmp=acnt
for i in range(tmp):
    now-=a[tmp-i-1]
    acnt-=1
    # print(a[acnt-i-1],a[tmp-i-1],now)
    while bcnt!=m and now+b[bcnt]<=k:
        now+=b[bcnt]
        bcnt+=1
    ans=max(ans,acnt+bcnt)
    # print(now,bcnt)
for i in range(n):
    if now+a[i]<=k:
        now+=a[i]
        acnt+=1
ans=max(ans,acnt+bcnt)

tmp=bcnt
for i in range(tmp):
    now-=b[tmp-i-1]
    bcnt-=1
    while acnt!=n and now+a[acnt]<=k:
        now+=a[acnt]
        acnt+=1
    ans=max(ans,acnt+bcnt)


print(ans)