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

count = 0
while(True):
    if len(A)==0 and len(B)==0:
        break

    elif len(A)==0:
        if K-B[0]<0:
            break
        K -= B[0]
        B = B[1:]
    elif len(B)==0:
        if K-A[0]<0:
            break
        K -= A[0]
        A = A[1:]
    else:
        if K-A[0]<0 and K-B[0]<0:
            break
        if A[0] < B[0]:
            K -= A[0]
            A = A[1:]
        else:
            K -= B[0]
            B = B[1:]
    count += 1

Submission status: Wrong Answer

Solution code:
from collections import deque
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = deque(LI())
B = deque(LI())
res = 0
rem = K

for _ in range(N+M):
  if len(A) == 0 and len(B) == 0: break

  if len(A) == 0:
    book = B.popleft()
  elif len(B) == 0:
    book = A.popleft()
  else:
    if A[0] > B[0]:
      book = B.popleft()
    elif A[0] < B[0]:
      book = A.popleft()
    else:
      if len(A) > 1 and len(B) > 1:
        if A[1] > B[1]:
          book = B.popleft()
        else:
          book = A.popleft()
      elif len(A) > 1:
        book = A.popleft()
      else:
        book = B.popleft()

  if rem - book >= 0:
    res += 1
    rem -= book
  else:
    break

print(res)

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 = []

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

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

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

while (T<=K):
    if (len(A) ==0) and (len(B) == 0):
        break
    elif (len(A) == 0) and (len(B) != 0):
        T += B[0]
        ans += 1
        B.pop(0)
    elif (len(A) != 0) and (len(B) == 0):
        T += A[0]
        ans += 1
        A.pop(0)
    else:
        if A[0]<B[0]:
            T += A[0]
            ans += 1
            A.pop(0)
        else:
            T += B[0]
            ans += 1
            B.pop(0)

if (len(A)!=0) or (len(B)!=0):
    ans -=1

print(ans)

Submission status: Wrong Answer

Solution code:
def read(a,b,k):
    book = 0
    block_a = 0
    block_b = 0
    for i in range(max(len(a),len(b))):
        if i<len(a):
            if k<a[i]:
                block_a = 1
            if k>=a[i] and block_a==0:
                k-=a[i]
                book +=1
        if i<len(b):
            if k<b[i]:
                block_b = 1
            if k>=b[i] and block_b==0:
                k-=b[i]
                book +=1
    return book


if __name__ == "__main__":
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    print(read(a,b,k))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n + m):
    if len(a) == 0:
        a.append(10 ** 9 + 1)
    if len(b) == 0:
        b.append(10 ** 9 + 1)
    if a[0] > k and b[0] > k:
        break
    if a[0] < b[0]:
        k -= a[0]
        a.pop(0)
    else:
        k -= b[0]
        b.pop(0)
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
"""
AtCoder :: Beginner Contest 172 :: C :: Tsundoku
https://atcoder.jp/contests/abc172/tasks/abc172_c

"""
import sys


def solve(A, B, K):
    """Solve puzzle."""
    a = b = 0
    books_read = 0
    read_time = 0
    while read_time < K:
        book_time = 0
        if a >= len(A) and b >= len(B):
            break
        if a >= len(A):
            book_time = B[b]
            b += 1
        elif b >= len(B):
            book_time = A[a]
            a += 1
        elif A[a] < B[b]:
            book_time = A[a]
            a += 1
        else:
            book_time = B[b]
            b += 1

        if book_time + read_time > K:
            break
        
        read_time += book_time
        books_read += 1
    return books_read


def main():
    """Main program."""
    N, M, K = (int(i) for i in sys.stdin.readline().split())
    A = [int(i) for i in sys.stdin.readline().split()]
    B = [int(i) for i in sys.stdin.readline().split()]
    print(solve(A, B, K))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    n, m, k = map(int, input().split())
    a_li = list(map(int, input().split()))
    b_li = list(map(int, input().split()))
    
    rt = 0
    ai = 0
    bi = 0
    a_li_len = len(a_li)
    b_li_len = len(b_li)

    ans = 0

    for i in range(n + m):
        if rt >= k:
            break

        if ai >= a_li_len:
            if k - (rt + b_li[bi]) < 0:
                break
            rt += b_li[bi]
            bi += 1
            
        elif bi >= b_li_len:
            if k - (rt + a_li[ai]) < 0:
                break
            rt += a_li[ai]
            ai += 1
            
        else:
            if k - (rt + min(a_li[ai], b_li[bi])) < 0:
                break
            
            if a_li[ai] < b_li[bi]:
                rt += a_li[ai]
                ai += 1
            else:
                rt += b_li[bi]
                bi += 1

        ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M,K = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
c = m = i = j = 0
while m <= K:
    if i >= N:
        if j >= M: break
        elif m + B[j] <= K:
            c += 1
            m += B[j]
            j += 1
        else: break
    else:
        if j >= M:
            if m + A[i] <= K:
                c += 1
                m += A[i]
                i += 1
            else: break
        else:
            if A[i] < B[j] and m + A[i] <= K:
                c += 1
                m += A[i]
                i += 1
            elif A[i] >= B[j] and m + B[j] <= K:
                c += 1
                m += B[j]
                j += 1
            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()))

A.append(10000000000000)
B.append(10000000000000)

time = 0
a_num = 0
b_num = 0
flag = 0
for i in range(N+M):
    if time + A[a_num] > K and time + B[b_num] > K:
        break
    elif A[a_num] < B[b_num]:
        time += A[a_num]
        a_num+=1
    else:
        time += B[b_num]
        b_num+=1

print(a_num+b_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()))
k=0
c=0
while 1:
    if len(a) > 0 and len(b)>0:
        if a[0] < b[0] and (k+a[0]) <=K :
            k+=a[0]
            c+=1
            a.pop(0)

        elif a[0] > b[0] and (k+b[0]) <=K:
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            break
    elif len(a) > 0 and len(b) ==0:
        if (k+a[0]) <=K :
            k+=a[0]
            c+=1
            a.pop(0)
        else:
            break
    elif len(b) > 0 and len(a) ==0:
        if (k+b[0]) <=K :
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            break
    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()))

counter = 0
ans = 0

for i in range(n):
  for j in range(m):
    if sum(A[:i+1])+sum(B[:j+1])<=k:
      ans = max(ans, i+1+j+1)
      
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

N, M, K = map(int, input().split())
A0 = [int(x) for x in input().split()]
B0 = [int(x) for x in input().split()]

A = [0] * N
B = [0] * M
a = 0
for i in range(N):
    a += A0[i]
    A[i] = a
b = 0
for i in range(M):
    b += B0[i]
    B[i] = b
import sys
#print(A[-1], B[-1], file=sys.stderr)
answer = 0
for a in range(N):
    if A[a] <= K:
        Kb = K - A[a]
        b = bisect_right(B, Kb)
        #print(a, b, A[a], B[min(M-1, b)], A[a]+ B[min(M-1, b)])
        answer = max(answer, a+b+1)
    else:
        break
print(answer)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest



def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    a = list(map(int, lines[1].strip().split(' ')))
    b = list(map(int, lines[2].strip().split(' ')))
    c_max = 0
    c = 0
    s = 0
    for q in b:
        s += q
        if s > k:
            break
        c += 1
    c_max = max(c, c_max)
    s = 0
    c = 0
    for p in a:
        s += p
        c += 1
        if s > k:
            break
        sb = s
        cb = c
        for q in b:
            sb += q
            if sb > k:
                break
            cb += 1
        if c_max > cb:
            break
        c_max = max(cb, c_max)

    print(c_max)
resolve()

Submission status: Wrong Answer

Solution code:
m,n,k=map(int,input().split())
l=list(map(int,input().split()))
li=list(map(int,input().split()))
z=0
ans=0
while(True):
  l1=len(l)
  l2=len(li)
  if l1>0 and l2>0:
    if l[0]>li[0]:
      z+=li[0]
      li.pop(0)
    else:
      z+=l[0]
      l.pop(0)
  elif l1==0 and l2>0:
    z+=li[0]
    li.pop(0)
  elif l1>0 and l2==0:
    z+=l[0]
    l.pop(0)
  else:
    break
  if z<=k:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

i, j = 0, 0
total = 0
for _ in range(n + m):
  # print(i, j, m, n)
  current = 0
  if i == n and j == m:
    print(i + j)
    exit()
  elif j == m:
    current += a[i]
    i += 1
  elif i == n:
    current += b[j]
    j += 1
  elif a[i] < b[j]:
    current += a[i]
    i += 1
  else:
    current += b[j]
    j += 1
  if total + current > k:
    print(i + j - 1)
    exit()
  else:
    total += current
print(i + j)

Submission status: Wrong Answer

Solution code:
n,m,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
cont = 0
p,u = 0,0
while k>0 and p!=n and u != m:
    #if p == n-1 or u == m-1: break
    if a[p] < b[u]:
        k-=a[p]
        if k<0: break
        p+=1
        cont+=1
    else:
        k-=b[u]
        if k<0: break
        u+=1
        cont+=1
    #print(k,p,u)
#beleza, agora acabou uma das estantes
if p == n:
    for i in range(u,m):
        k-=b[i]
        if k<0: break
        cont+=1
        
else:
    for i in range(p,n):
        k-=a[i]
        if k<0: break
        cont+=1
        

print(cont)

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 = -1
while time <= k:
  try:
    if a[0] == b[0]:
      if a[1] < b[1]:
        top = a.pop(0)
      else:
        top = b.pop(0)
    elif a[0] < b[0]:
      top = a.pop(0)
    else:
      top = b.pop(0)
  except IndexError:
    if a:
      top = a.pop(0)
    elif b:
      top = b.pop(0)
    else:
      count += 1
      break
  time += top
  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()))
total = a + b
total.sort()
ans = 0
if sum(total) > k:
    for i in range(len(total))[::-1]:
        if sum(total) < k:
            break
        else:
            del total[i]
    print(len(total))

else:
    print(n+m)

Submission status: Wrong Answer

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

a= list(map(int,input().split())) #n冊

b= list(map(int,input().split())) #m冊
#ab=a+b
#print(ab)
ab=[0]*(n+m)
ans=0
count=0
i=0
A=0
B=0
if sum(a)+sum(b)<=k:
    ans=len(a)+len(b)
    print(ans)
else:
    while i<(n+m) and A<n and B<m:
        ab[i]=min(a[A],b[B])
        if a[A]>=b[B]:
            B+=1
            i+=1
        else :
            A+=1
            i+=1
    for i in range(n+m):
        ans+=ab[i]
        if ans>k:
            break
        else:
            count+=1
    #print(ab)
    print(count)

Submission status: Wrong Answer

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

import bisect

alist = [0]
blist = [0]

for i in range(n):
  alist.append(alist[i]+a[i])  
for i in range(m):
  blist.append(blist[i]+b[i])

res = 0
ans = 0
for i in range(n+1):
  border = k - alist[i]
  if border <= 0:
    continue
  ans = i
  ans += bisect.bisect_right(blist, border)-1
  res = max(res, ans)
  
print(res)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    from itertools import accumulate
    from bisect import bisect_right

    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))
    a = list(accumulate(a))
    b = list(accumulate(b))
    ans = bisect_right(b, k)
    for i, aa in enumerate(a):
        if k > aa:
            ans = max(ans, bisect_right(b, k - aa) + i + 1)
        else:
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M,K = [int(item) for item in input().split(" ")]
A = [int(item) for item in input().split(" ")] 
B = [int(item) for item in input().split(" ")] 
count = 0
while len(A) and len(B) and (K > 0):
    a,b = A[0],B[0]
    if a > b : # read B
        K -= b
        B.pop(0)
        count += 1
    else:
        K -= a
        A.pop(0)
        count += 1
if K > 0: # Kが0以下になる前にA,Bのどちらかが空になった場合
    if len(A):
        while K > 0:
            K -= A.pop()
            count += 1
    if len(B):
        while K > 0:
            K -= B.pop()
            count += 1
if K is not 0:
    count -= 1
print(count)

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
max_value = 10 ** 9 + 1
ans = 0

for i in range(n + m):
    if min(a_list[0], b_list[0]) + time > k:
        break
    elif a_list[0] < b_list[0]:
        time += a_list[0]
        a_list.pop(0)
        ans += 1
        if len(a_list) == 0:
            a_list.append(max_value)
    else:
        time += b_list[0]
        b_list.pop(0)
        ans += 1
        if len(b_list) == 0:
            b_list.append(max_value)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))[::-1]
B = list(map(int,input().split()))[::-1]
ans = 0
time = 0

for n in range(N+M):
  if len(A)==0:
    ans+=1
    time+=B[-1]
    B.pop()
  elif len(B)==0:
    ans+=1
    time+=A[-1]
    A.pop()
  else:
    if A[-1]<=B[-1]:
      ans+=1
      time+=A[-1]
      A.pop()
    else:
      ans+=1
      time+=B[-1]
      B.pop()
  
  if K<time:
    print(ans-1)
    exit()
  
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()))

sum_time = 0
L = []
while True:
    if (sum_time == K):
        print(len(L))
        exit()
    elif(sum_time > K):
        print(len(L) - 1)
        exit()
    # どちらかがなくなったらとりあえず、break
    if (len(A) == 0 or len(B) == 0):
        break

    if (A[0] <= B[0]):
        sum_time += A[0]
        L.append(A[0])
        A = A[1:]
    else:
        sum_time += B[0]
        L.append(B[0])
        B = B[1:]

if (sum(L) == K):
    print(len(L))
    exit()

if (len(A) == 0 and len(B) != 0 and sum(L) < K):
    for i in B:
        L.append(i)
        if (sum(L) == K):
            print(len(L))
            exit()
        elif (sum(L) > K):
            print(len(L) - 1)
            exit()
    print(len(L))
elif (len(A) != 0 and len(B) == 0 and sum(L) < K):
    for i in A:
        L.append(i)
        if (sum(L) == K):
            print(len(L))
            exit()
        elif (sum(L) > K):
            print(len(L) - 1)
            exit()
    print(len(L))

Submission status: Wrong Answer

Solution code:
INT_MAX=10**30+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=====================================================================
from collections import deque as D
n,m,k=INPUT()
A=INPUT()
B=INPUT()
if sum(A)+sum(B)<=k:
    print(n+m)
else:
    Qa=D()
    Qb=D()
    for i in range(n):
        Qa.append(A[i])
    for j in range(m):
        Qb.append(B[j])
    sum=0
    ans=0
    while(sum<k and len(Qa)>0 and len(Qb)>0):
        if Qa[0]<Qb[0]:
            if sum+Qa[0]<=k:
                sum+=Qa.popleft()
                ans+=1
            else:
                break
        else:
            if sum+Qb[0]<=k:
                sum+=Qb.popleft()
                ans+=1
            else:
                break
    if sum<k:
        if len(Qb)==0:
            if sum+Qa[0]<=k:
                while(len(Qa)>0 and sum<k):
                    if sum+Qa[0]<=k:
                        sum+=Qa.popleft()
                        ans+=1
                    else:
                        break
        elif len(Qa)==0:
            if sum+Qb[0]<=k:
                while(len(Qb)>0 and sum<k):
                    if sum+Qb[0]<=k:
                        sum+=Qb.popleft()
                        ans+=1
                    else:
                        break

    print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=list(a)
sb=list(b)
s = 0
for i in range(n):
	s+=a[i]
	sa[i]=s

s = 0
for i in range(m):
	s+=b[i]
	sb[i]=s

ans = 0
pt1 = -1
pt2 = m-1
while pt1<n:
	s = 0
	if(pt1!=-1):
		s+=sa[pt1]
	while pt2>-1 and (sb[pt2]+s)>k:
		pt2-=1
	if(pt2==-1):
		ans = max(ans,pt1+1+pt2+1)
		break
	else:
		ans = max(ans,pt1+1+pt2+1)
	pt1+=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()))
count=0
ans=0
while count<K:
    if len(A)==0 and len(B)==0:
        print(ans)
        exit()
    elif len(A)==0:
        m=B[0]
    elif len(B)==0:
        m=A[0]
    else:
        m=min(A[0],B[0])
    count+=m
    if len(A)==0:
        B.pop(0)
    elif len(B)==0:
        A.pop(0)
    else:
        if m==A[0]:
            A.pop(0)
        else:
            B.pop(0)
    ans+=1
    if count>K:
        ans-=1
print(ans)

Submission status: Wrong Answer

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

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

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

for j in range(1, M + 1):
  dp[0][j] = dp[0][j - 1] + B[-j]
  
res = 0

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

print(res)

Submission status: Wrong Answer

Solution code:
import sys

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

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

time = 0
total = 0

if n > m:
    a = n
else:
    a = m

if sum(A) + sum(B) <= k:
    print(n+m)
    sys.exit()

for i in range(a):
    
    if i >= len(A):
        pass
    else:
        time += A[i]
        total +=1
        if time >= k:
            print(total-1)
            sys.exit()
    if i >= len(B):
        pass
    else:
        time += B[i]
        total += 1
        if time >= k:
            print(total-1)
            sys.exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.reverse()
b.reverse()
ans = 0

for i in range(n + m):
    cost = 0
    if a[-1] > b[-1]:
        cost = b[-1]
        b.pop(-1)
    else:
        cost = a[-1]
        a.pop(-1)
    
    k -= cost
    if k <= 0:
        break
    elif len(a) == 0:
        a.append(float('inf'))
    elif len(b) == 0:
        b.append(float('inf'))
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

import sys
input=sys.stdin.readline
n,m,k=L()
a=L()
b=L()
ans=0
maxi=n+m
time=0
ai=0
bi=0
while time<k and ans<maxi:
    if ai>=n:
        time+=b[bi]
        bi+=1
        if time<=k:
            ans+=1
        continue
        
    elif bi>=m:
        time+=a[ai]
        ai+=1
        if time<=k:
            ans+=1
        continue
        
    if a[ai]<b[bi]:
        time+=a[ai]
        ai+=1
        
    else:
        time+=b[bi]
        bi+=1
        
    if time<=k:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right as br


def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    tmp = 0
    a = 0
    b = 0
    Sb = [B[0]]
    for i in range(1, m):
        Sb.append(Sb[-1] + B[i])
    Sa = [A[0]]
    for i in range(1, n):
        Sa.append(Sa[-1] + A[i])
    mx = 0
    for j in range(n):
        index = br(Sb, k - Sa[j]) - 1
        tmp = Sa[j] + Sb[index] if index > 0 else Sa[j]
        if tmp < k:
            mx = max(mx, j + index + 2)
    print(mx)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
temp = [int(i) for i in input().split(" ")]
n = temp[0]
m = temp[1]
k = temp[2]

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

time = 0
counter = 0
max = len(a) + len(b)

while max > counter:

    candidate = None
    if len(a) > 0 and len(b) > 0:

        can_a = a[0]
        can_b = b[0]

        if can_a <= can_b:
            candidate = a.pop(0)
        else:
            candidate = b.pop(0)

    elif len(a) > 0:
        candidate = a.pop(0)

    elif len(b) > 0:
        candidate = b.pop(0)

    time += candidate

    if k >= time:
        counter += 1
    else:
        break

print(counter)

Submission status: Wrong Answer

Solution code:
import math
def main():

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

    ans = 0
    t = 0
    i, j = 0, 0
    while i < len(A) and j < len(B) and t + min(A[i], B[j]) <= K:
        if A[i] <= B[j]:
            ans += 1
            t += A[i]
            i += 1
        else:
            ans += 1
            t += B[j]
            j += 1

    if i < len(A) and j < len(B):
        return ans

    if i < len(A):
        while i < len(A) and t + A[i] <= K:
            t += A[i]
            i += 1
            ans +=1
    if j < len(B):
        while j < len(B) and t + B[j] <= K:
            t += B[j]
            j += 1
            ans +=1
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
import sys
import math as mt
input=sys.stdin.buffer.readline  
t=1
#t=int(input())
for _ in range(t):
    #n=int(input())
    n,m,k=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    ans=0
    suma=0
    i,j=0,0
    while i<n and j<m and suma<k:
        if l1[i]<l2[j]:
            if suma+l1[i]<=k:
                suma+=l1[i]
                ans+=1
            i+=1
            
        else:
            if suma+l2[j]<=k:
                suma+=l2[j]
                ans+=1
            j+=1
           
    if  j<m and suma<k:
        for i1 in range(j,m):
            if suma+l2[i1]<=k:
                suma+=l2[i1]
                ans+=1
    if  i<n and suma<k:
        for i1 in range(i,n):
            if suma+l1[i1]<=k:
                ans+=1
                suma+=l1[i1]
                
        
    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()))
for _ in range(m):
    A.append(10 ** 9 + 1)
for _ in range(n):
    B.append(10 ** 9 + 1)

total = 0
count = 0
for i in range(n + m):
    if A[0] == min(A[0], B[0]):
        total += A.pop(0)
    elif B[0] == min(A[0], B[0]):
        total += B.pop(0)
    if total > k:
        break
    count += 1
print(count)

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()))
t=0
ans=0
aq=deque(a)
bq=deque(b)
aq.append(k)
bq.append(k)
while t<k:
    if aq[0]<bq[0]:
        t+=aq.popleft()
    elif aq[0]>bq[0]:
        t+=bq.popleft()
    else:
        if aq[1]>=bq[1]:
            t+=bq.popleft()
        else:
            t+=aq.popleft()
    if t<=k:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

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

print(read_cnt)

Submission status: Wrong Answer

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

# 全部Aから選んでみる
minutes_a = 0
count_a = 0
for i in range(N):
    if minutes_a + A[i] > K:
        break
    minutes_a += A[i]
    count_a += 1

minutes_b = 0
count_b = 0

if minutes_a < K:
    for i in range(M):
        if minutes_a + minutes_b + B[i] > K:
            break
        minutes_b += B[i]
        count_b += 1

max_count = count_a + count_b

for i in range(count_b, M):
    if count_a > 0:
        minutes_a -= A[count_a - 1]
        count_a -= 1
    if minutes_a + minutes_b + B[i] > K:
        break
    minutes_b += B[i]
    count_b += 1

print(max(max_count, count_a + count_b))

Submission status: Wrong Answer

Solution code:
from queue import deque

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

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

count = 0

while 1:
    a = int(A.popleft()) if A else 10**9+1
    b = int(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()))

cnt=0
time=0

for i in range(400000):

    if not a and not b:
        break

    elif not a:
        book_min=b[0]
        
    elif not b:
        book_min=a[0]

    else:
        book_min=min(a[0],b[0])
        
    if k<(book_min+time):
        break

    else:
        if not a and not b:
            break

        elif not a:
            book_min=b[0]
            time+=b[0]
            cnt+=1
            b.pop(0)

        elif not b:
            book_min=a[0]
            time+=a[0]
            cnt+=1
            a.pop(0)

        elif book_min==a[0]:
            time+=a[0]
            cnt+=1
            a.pop(0)

        elif book_min==b[0]:
            time+=b[0]
            cnt+=1
            b.pop(0)

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()))
books = 0
cost = 0
for i in range(N+M):
    if cost > K:
        books -= 1
        break
        
    if len(B) == 0:
        cost += A.pop(0)
        books += 1
    elif len(A) == 0 or A[0] >= B[0]:
        cost += B.pop(0)
        books += 1
    else:
        cost += A.pop(0)
        books += 1
if books <= 0:
    print(0)
else:
    print(books)

Submission status: Wrong Answer

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

time = 0
ans = 0
flag = True
while True:
  tar = min(a[0], b[0])
  if (tar == a[0]):
    del a[0]
  else:
    del b[0]

  time += tar
  ans += 1
  if (time > k):
    ans -= 1
    break

  if (len(a) == 0):
    flag = False
    lis = b
    break
  if (len(b) == 0):
    flag = False
    lis = a
    break

if (flag is False):
  while time < k:
    time += lis[0]
    ans += 1
    if (time > k):
      time -= lis[0]
      ans -= 1
      break
    
    del lis[0]
    if (len(lis) == 0):
      break

print(ans)