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
while k > 0:
    if n > 0 and m > 0:
        if a[0] < b[0]:
            if k >= a[0]:
                k -= a.pop(0)
                n -= 1
                ans += 1
            else:
                break
        else:
            if k >= b[0]:
                k -= b.pop(0)
                m -= 1
                ans += 1
            else:
                break
    elif n > 0 and m == 0:
        if k >= a[0]:
            k -= a.pop(0)
            n -= 1
            ans += 1
        else:
            break
    elif n == 0 and m > 0:
        if k >= b[0]:
            k -= b.pop(0)
            m -= 1
            ans += 1
        else:
            break
    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()))

ans = 0
time = 0
while True:
    m = min(a[0], b[0])
    if m == a[0]:
        a.pop(0)
        if not a:
            a.append(9999999999)
    if m == b[0]:
        b.pop(0)
        if not b:
            b.append(9999999999)
    time += m
    if time > k:
        break

    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N,M,K = map(int,input().split())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))

AList.append(10**10)
BList.append(10**10)

AList= deque(AList)
BList= deque(BList)

cnt = 0
s = 0

for i in range(N+M+2):
  a = AList[0]
  b = BList[0]
  if a <= b and s+a<=K:
    s += a
    AList.popleft()
    cnt += 1
  elif b <= a and s+b<=K:
    s += b
    BList.popleft()
    cnt += 1
    
    
print(int(cnt))

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
for i in range(N+M):
  if len(A)>0 and len(B)>0 and A[0]>=B[0]:
    if K-B[0]>=0:
      c+=1
      K-=B[0]
      B=B[1:]
    else:
      break
  elif len(A)>0 and len(B)>0 and A[0]<=B[0]:
    if K-A[0]>=0:
      c+=1
      K-=A[0]
      A=A[1:]
    else:
      break
  elif len(A)>0 and K-A[0]>=0:
      c+=1
      K-=A[0]
      A=A[1:]
  elif len(B)>0 and K-B[0]>=0:
      c+=1
      K-=B[0]
      B=B[1:]
print(c)

Submission status: Wrong Answer

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

while True:
    x = 10**10
    y = 10**10
    if len(a) > 0:
        x = a[0]
    if len(b) > 0:
        y = b[0]

    if x < y:
        s += a.pop(0)
    elif x > y:
        s += b.pop(0)
    else:
        for i in range(min(len(a),len(b))-1):
            if a[i+1] < b[i+1]:
                s += a.pop(0)
                break
            elif a[i+1] > b[i+1]:
                s += b.pop(0)
                break
            if i+1 == min(len(a),len(b))-1:
                s += a.pop(0)

    if s > k:
        break

    ans += 1

    if ans == n+m:
        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()))
c=a+b
cnt_a=0
cnt_b=0
ans=0
while k>0:
    if cnt_a<n and cnt_b<m:
        if a[cnt_a]<=b[cnt_b]:
            k-=a[cnt_a]
            if k<0:
                break
            ans+=1
            cnt_a+=1
        else:
            k-=b[cnt_b]
            if k<0:
                break
            ans+=1
            cnt_b+=1
    elif cnt_a<n and cnt_b>=m:
        k-=a[cnt_a]
        if k<0:
            break
        ans+=1
        cnt_a+=1
    elif cnt_a>=n and cnt_b<m:
        k-=b[cnt_b]
        if k<0:
            break
        ans+=1
        cnt_b+=1
    else:
        break
print(ans)

Submission status: Wrong Answer

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


maxNum = 0
cnt = 0


for i in a:
    if k - i > 0:
        k -= i
        cnt += 1
    else:
        break

    for j in b:
        if k - j > 0:
            k -= j
            cnt += 1
        else:
            break
    
    maxNum = max(maxNum, cnt)


print(maxNum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N, M, K = LI()
    AArray = LI()
    BArray = LI()

    cnt = 0

    while K > 0 and (len(AArray) > 0 or len(BArray) > 0):
        if len(AArray) > 0 and len(BArray) > 0:
            if AArray[0] >= BArray[0]:
                b = BArray.pop(0)
                if K-b >= 0:
                    K -= b
                    cnt += 1
                else:
                    break
            elif AArray[0] < BArray[0]:
                a = AArray.pop(0)
                if K-a >= 0:
                    K -= a
                    cnt += 1
                else:
                    break
        elif len(AArray) == 0:
            b = BArray.pop(0)
            if K-b >= 0:
                K -= b
                cnt += 1
            else:
                break
        else:
            a = AArray.pop(0)
            if K-a >= 0:
                K -= a
                cnt += 1
            else:
                break

    print(cnt)


if __name__ == '__main__':
    main()

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

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

ret = 0
a = N - 1
b = 0
while b < M :
  while a >= 0 and A[a] + B[b] > K :
    a -= 1
  if a >= 0 and A[a] + B[b] <= K :
    ret = max(ret, a + b + 2)
  b += 1
  
print(ret)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect
n,k,m = map(int,readline().split())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

aa = [0]*(n+1)
bb = [0]*(k+1)
for i in range(n):
  aa[i+1] = aa[i]+a[i]
for i in range(k):
  bb[i+1] = bb[i]+b[i]
  
ans = 0
for num,i in enumerate(bb):
  M = m-i
  if M > 0:
    ind = bisect(aa,M)
    ans = max(ans,num+ind-1)
  
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())]
book_num = 0
n_t = 0

while True:
    if A and B:
        if A[0] > B[0]:
            n_t += B[0]
            B.pop(0)
        else:
            n_t += A[0]
            A.pop(0)
    elif A:
        n_t += A[0]
        A.pop(0)
    else:
        n_t += B[0]
        B.pop(0)
    if n_t > K or not (A or B):
        break
    book_num += 1

if n_t == K:
    book_num += 1
print(book_num)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
time = 0
ans = 0
aaa = deque(a)
bbb = deque(b)
while (time < k) & ((len(aaa) > 0)  |  (len(bbb) > 0)):
    if (len(aaa) > 0  |  len(bbb) > 0):
        if aaa[0] <= bbb[0]:
            time += aaa.popleft()
            ans += 1
        else:
            time += bbb.popleft()
            ans += 1
    elif aaa:
        time += aaa.popleft()
        ans += 1
    elif bbb:
        time += bbb.popleft()
        ans += 1
if time <= k:
    print(ans)
else:
    print(ans - 1)

Submission status: Wrong Answer

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

books_total = 0
possible = True
while books_total <= n + m:
    books_total += 1
    possible = False
    for books_a in range(books_total+1):
        books_b = books_total - books_a
        time_total = sum(a[0:books_a]) + sum(b[0:books_b])
        if time_total <= k:
            possible = True
            break
    if not possible:
        break

ans = books_total - 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()))

prog=0
a_idx=0
b_idx=0

while prog<k and a_idx<n and b_idx<m:
    if a[a_idx]<b[b_idx]:
        if prog+a[a_idx]>k:
            break
        else:
            prog+=a[a_idx]
            a_idx+=1
    else:
        if prog+b[b_idx]>k:
            break
        else:
            prog+=b[b_idx]
            b_idx+=1

if a_idx==n:
    while b_idx<m and prog+b[b_idx]<=k:
        prog+=b[b_idx]
        b_idx+=1
if b_idx==m:
    while a_idx<n and prog+a[a_idx]<=k:
        prog+=a[a_idx]
        a_idx+=1
print(a_idx+b_idx)

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]
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
if total > INF:
    print(n+m)
else:
    print(cnt-1)

Submission status: Wrong Answer

Solution code:
from queue import deque

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

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

count = 0

while 1:
    a = A.popleft() if A else 10**9+1
    b = B.popleft() if B else 10**9+1
    
    if min(a, b) <= K:
        count += 1
        K -= min(a, b)
        if a <= b:
            B.appendleft(b)
        else:
            A.appendleft(a)
    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_time = 0
ans = 0
while K >= ans_time:

    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        ans_time += B.pop(0)
    elif len(B) == 0:
        ans_time += A.pop(0)
    else:
        if A[0] >= B[0]:
            ans_time += B.pop(0)
        else:
            ans_time += A.pop(0)

    if K >= ans_time:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=a+[10**18]
b=b+[10**18]
ans,t=0,0
i,j=0,0
while t<=k:
    if i>=n and j>=m:
        break
    if a[i]<=b[j]:
        t+=a[i]
        i+=1
    else:
        t+=b[j]
        j+=1
    if t<=k:
        ans+=1
print(ans)
#print(t)

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
t = 0

while True:
    if Ai < N and Bi < M:
        if A[Ai] <= B[Bi]:
            if t + A[Ai] <= K:
                t += A[Ai]
                Ai += 1
            else:
                break
        else:
            if t + B[Bi] <= K:
                t += B[Bi]
                Bi += 1
            else:
                break
    else:
        if Ai >= N and Bi < M:
            if t + B[Bi] <= K:
                t += B[Bi]
                Bi += 1
            else:
                break
        elif Ai < N and Bi >= M:
            if t + A[Ai] <= K:
                t += A[Ai]
                Ai += 1
            else:
                break
        else:
            break

print(Ai+Bi)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

#a = int(input())
#b = list(map(int, input().split()))
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

from collections import deque

a.sort()
b.sort()

a = deque(a)
b = deque(b)

ans = 0
time = 0

while time <= k:
    if a and b:
        tmp_a = time+a[0]
        tmp_b = time+b[0]
        if tmp_a <= k and tmp_b <= k and a[0] <= b[0]:
            time += a[0]
            a.popleft()
            ans += 1
        elif tmp_a <= k and tmp_b <= k and b[0] <= a[0]:
            time += b[0]
            b.popleft()
            ans += 1
        elif tmp_a <= k:
            time += a[0]
            a.popleft()
            ans += 1
        elif tmp_b <= k:
            time += b[0]
            b.popleft()
            ans += 1
        else:
            break
    elif a:
        tmp_a = time+a[0]
        if tmp_a <= k:
            time += a[0]
            a.popleft()
            ans += 1
        else:
            break
    elif b:
        tmp_b = time+b[0]
        if tmp_b <= k:
            time += b[0]
            b.popleft()
            ans += 1
        else:
            break
    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()))
ans = 0
count = 0
A_count = 0
B_count = 0
while count <= K:
    if len(A)==0 and len(B)==0:
        ans+=1
        break
    elif len(A)==0:
        ans +=1
        count += B.pop(0)
        continue
    elif len(B)==0:
        ans+=1
        count += A.pop(0)
        continue
        
    if A[0] < B[0]:
        ans += 1
        count += A.pop(0)
    else:
        ans += 1
        count += B.pop(0)
print(ans-1)

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()))
time = 0
a_idx = 0
b_idx = 0
cnt = 0
while True:
  if a_idx < N and b_idx < M:
    if A_list[a_idx] >= B_list[b_idx]:
      time += B_list[b_idx]
      b_idx += 1
      cnt += 1
    else:
      time += A_list[a_idx]
      a_idx += 1
      cnt += 1
  elif a_idx >= N and b_idx < M:
    time += B_list[b_idx]
    b_idx += 1
    cnt += 1
  elif a_idx < N and b_idx >= M:
    time += A_list[a_idx]
    a_idx += 1
    cnt += 1
  else:
    break
  
  if time > K:
    cnt -= 1
    break
print(cnt)

Submission status: Wrong Answer

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

n,m,k = map(int,input().split())
a = list(map(int,input().split())) + [float('inf')]
b = list(map(int,input().split())) + [float('inf')]
aind = 0
bind = 0
ans = 0
while True:
    if min(a[aind],b[bind]) > k:
        print(ans)
        break
    else:
        if a[aind] == float('inf') and b[bind] == float('inf'):
            print(ans)
            break
        if a[aind] <= b[bind]:
            ans += 1
            k -= a[aind]
            if aind < n:
                aind += 1


        else:
            ans += 1
            k -= b[bind]
            if bind < n:
                bind += 1

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()))
count = 0
ans = 0
while a or b:
    if a and b:
        if a[0] > b[0]:
            ans += b[0]
            b.popleft()
            count += 1
        else:
            ans += a[0]
            a.popleft()
            count += 1
    elif a:
        ans += a[0]
        a.popleft()
        count += 1
    elif b:
        ans += b[0]
        b.popleft()
        count += 1
    if ans > k:
        print(count - 1)
        exit()
print(n+m)

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()))
sa = [0] * (n+1)
for i in range(n):
    sa[i+1] = sa[i] + a[i]
sb = [0] * (m+1)
for i in range(m):
    sb[i+1] = sb[i] + b[i]

ans = 0
for i in range(1,n+1):
    bi = min(m, bisect.bisect_right(sb, max(0, k-sa[i]))-1)
    if sa[i] + sb[bi] <= k:
        ans = max(ans, i + bi)
print(ans)

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
# print(acnt)
while bcnt!=m and now+b[bcnt]<=k:
    now+=b[bcnt]
    bcnt+=1
ans=acnt+bcnt
# print(now,ans,acnt,bcnt)
tmp=acnt
for i in range(tmp):
    now-=a[acnt-i-1]
    acnt-=1
    # print(now)
    while bcnt!=m and now+b[bcnt]<=k:
        now+=b[bcnt]
        bcnt+=1
    ans=max(ans,acnt+bcnt)
    # print(ans,acnt,bcnt)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
def p(a):print(" ".join(list(map(str,a))))
from collections import Counter

n,m,k=MAP()
a=LI()
b=LI()
bo=0
while k>0:
    if len(a)>0 and len(b)>0:
        if a[0]>=b[0]:
            if k>=b[0]:
                bo+=1
                k-=b[0]
                b.pop(0)
            else:
                print(bo)
                exit()
        else:
            if k>=a[0]:
                bo+=1
                k-=a[0]
                a.pop(0)
            else:
                print(bo)
                exit()
    elif len(a)>0:
        if k>=a[0]:
            k-=a[0]
            bo+=1
            a.pop(0)
    elif len(b)>0:
        if k>=b[0]:
            k-=b[0]
            bo+=1
            b.pop(0)
    if len(a)==0 and len(b)==0:
        print(bo)
        exit()

Submission status: Wrong Answer

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

Time = 0
AC = 0
BC = 0
Flag = True
while Flag:
    if AC==len(A) and BC==len(B):
        break
        
    if AC==len(A):
        Time += B[BC]
        BC += 1
    elif BC==len(B):
        Time += A[AC]
        AC += 1
    else:
        if A[AC]<=B[BC]:
            Time += A[AC]
            AC += 1
        else:
            Time += B[BC]
            BC += 1
    if Time>K:
        Flag = False
        
if Flag:
    print(AC+BC)
else:
    print(AC+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()))

t = 0
cnt = 0
while t <= K:
    if len(a)==0 and len(b)==0:
        cnt += 1
        break
    elif len(a) == 0:
        t += b.pop(0)
    elif len(b) == 0:
        t += a.pop(0)
    else:
        if a[0] <= b[0]:
            t += a.pop(0)
        elif a[0] > b[0]:
            t += b.pop(0)
    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 True:
    if a == [] and b == []:
        break
    if a != [] and b != []:
        if  a[0] <= b[0]:
            l = a.pop(0)
            time += l
            count += 1
        else:
            l = b.pop(0)
            time += l
            count += 1
    elif a == []:
        l = b.pop(0)
        time += l
        count += 1
    else:
        l = a.pop(0)
        time += l
        count += 1
    if time > k:
        count -= 1
        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
ans = 0
while t <= k:
  if len(a) > 0 and len(b) > 0:
    if a[0] <= b[0]:
      if t + a[0] <= k:
        t += a[0]
        a.pop(0)
        ans += 1
      else:
        break
    else:
      if t + b[0] <= k:
        t += b[0]
        b.pop(0)
        ans += 1
      else:
        break
  elif len(a) > 0 and len(b) == 0:
    if t + a[0] <= k:
      t += a[0]
      a.pop(0)
      ans += 1
    else:
      break
  elif len(a) == 0 and len(b) > 0:
    if t + b[0] <= k:
      t += b[0]
      b.pop(0)
      ans += 1
    else:
      break
  elif len(a) == 0 and len(b) == 0:
    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()))
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:
    print(ans)
    flag=False
    break
  else:
    ans+=1
if flag:
  print(n+m)

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 = 0
while k > 0:
    if c == m+n:
        break;
    if len(a) == 0:
        d = b.popleft()
    elif len(b) == 0:
        d = a.popleft()
    else:
        if a[0] < b[0]:
            d = a.popleft()
        else:
            d = b.popleft()
    if d <= k:
        c += 1
        k -= d
    else:
        break;
print(c)

Submission status: Wrong Answer

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

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

from heapq import heapify, heappop, heappush

heap = []
heapify(heap)

for a in A:
    heappush(heap, a)
for b in B:
    heappush(heap, b)

cnt = 0
t = 0
while t <= K and heap:
    x = heappop(heap)

    if t + x <= K:
        t += x
        cnt += 1

print(cnt)

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()))
time = 0
ans = 0

def judge(data):
    if len(data) == 0:
        return 10 ** 10
    return data[0]
while time + min(judge(a), judge(b)) <= k:
    ans += 1
    if judge(a) < judge(b):
        time += a[0]
        a.popleft()
    else:
        time += b[0]
        b.popleft()
print(ans)

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 = None
ans = 0
while k > 0:
    if not x:
        x,y = a.popleft(), b.popleft()
    elif last and len(b):
        y = b.popleft()
    elif len(a):
        x = a.popleft()
    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()))
A.append(10**10)
B.append(10**10)
i=0
j=0
total = 0
for k in range(N+M):
    a = A[i]
    b = B[j]
    if a < b and total+a<=K:
        total += a
        i += 1
    elif a >= b and total+b<=K:
        total += b
        j += 1
    else:
        break
print(i+j)

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 or (i == n and j == m)):
  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
print(i+j-1)

Submission status: Wrong Answer

Solution code:
n,m,kk=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
k,c=0,[] 
i=0
j=0 

while i<len(a) and j<len(b):
	if a[i]<=b[j]:
		c.append(a[i])
		i+=1 
	else:
		c.append(b[j])
		j+=1 
while i<len(a):
	c.append(a[i])
	i+=1 
while j<len(b):
	c.append(b[j])
	j+=1 
#print(c)
i=0 
ans=-1
s=0
#print(kk)
while i<len(c):
	s=s+c[i]
	if s==kk:
		ans=i 
		break 
	elif s>kk:
		ans=i-1 
		break 
	i+=1
print(ans+1)

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    N, M, K = map(int, input().split())
    ns = deque()
    ms = deque()
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    for n in n_list:
        ns.append(n)
    for m in m_list:
        ms.append(m)
    
    num_book = 0
    time = K
    while len(ns) > 0 or len(ms) > 0:
        if len(ns) > 0 and len(ms) > 0:
            if ns[0] < ms[0]:
                t = ns.popleft()
                if time >= t:
                    num_book += 1
                    time -= t
            else:
                t = ms.popleft()
                if time >= t:
                    num_book += 1
                    time -= t
        elif len(ns) > 0:
            t = ns.popleft()
            if time >= t:
                num_book += 1
                time -= t
        
        else:
            t = ms.popleft()
            if time >= t:
                num_book += 1
                time -= t

    print(num_book)

  
if __name__ == '__main__':
    main()

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
    while k >= 0 and (len(A) > 0 or len(B) > 0):
        if len(A) == 0:
            time = B[0]
        elif len(B) == 0:
            time = A[0]
        else:
            time = min(A[0], B[0])

        if k - time < 0:
            break

        r += 1
        k -= time
        if len(A) == 0:
            B.pop(0)
        elif len(B) == 0:
            A.pop(0)
        else:
            if A[0] >= B[0]:
                B.pop(0)
            else:
                A.pop(0)

    print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

atop = a.popleft()
btop = b.popleft()
time = 0
ans = 0

for i in range(n + m):
    ans += 1
    if atop <= btop:
        time += atop
        if a:
            atop = a.popleft()
        else:
            atop = float('inf')
    else:
        time += btop
        if b:
            btop = b.popleft()
        else:
            btop = float('inf')
    if time > k:
        print(ans - 1)
        exit()
    if atop == float('inf') and btop == float('inf'):
        print(ans)
        exit()

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_read_count = 0
b_read_count = 0
read_time = 0
ans = 0
a_all_read = True

for a in A:
    read_time += a
    if read_time > K:
        read_time -= a
        a_all_read = False
    else:
        a_read_count += 1

while a_read_count >= 0:
    while read_time <= K and b_read_count < M:
        read_time += B[b_read_count]
        if read_time > K:
            read_time -= B[b_read_count]
            break
        b_read_count += 1
    ans = max(ans, a_read_count + b_read_count)
    a_read_count -= 1
    read_time -= A[a_read_count]

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
a = 0
b = 0
time = 0
ans = 0
while True:
  if a < N and b < M:
    if As[a] < Bs[b]:
      if time + As[a] > K:
        break
      time += As[a]
      # print(As[a])
      a += 1
      ans += 1
    else:
      if time + Bs[b] > K:
        break
      time += Bs[b]
      # print(Bs[b])
      b += 1
      ans += 1
  elif a < N:
    if time + As[a] > K:
      break
    time += As[a]
    # print(As[a])
    a += 1
    ans += 1
  elif b < M:
    if time + Bs[b] > K:
      break
    time += Bs[b]
    # print(Bs[b])
    b += 1
    ans += 1
  else:
    break
print(ans)