Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

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

ans = 0
aa = 0
bb = 0


for i in range(n):
    if k - a[i] < 0:
        break
    else:
        k -= a[i]
        aa += 1
ans = aa
#print(ans)

for i in range(m):
    if k - b[i] >= 0:
        k -= b[i]
        bb += 1
        if ans < aa + bb:
            ans = aa + bb
    else:
        while aa > 0:
            aa -= 1

            k += a[aa]
            if k - b[i] >= 0:
                k -= b[i]
                bb += 1
                if ans < aa + bb:
                    ans = aa + bb
                break
            if ans < aa + bb:
                ans = aa + bb

        if ans < aa + bb:
            ans = aa + bb
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, k = map(int, input().split())
n = deque(map(int, input().split()))
m = deque(map(int, input().split()))
minutes = 0
count = 0

while minutes < k:
	if len(n) + len(m) == 0: break
	if len(n) == 0 or len(m) == 0:
		if len(n) > 0:
			if minutes + n[0] > k: break
			minutes += n[0]
			n.popleft()
		else:
			if minutes + m[0] > k: break
			minutes += m[0]
			m.popleft()
	else:
		if n[0] < m[0]:
			if minutes + n[0] > k: break
			minutes += n[0]
			n.popleft()
		else:
			if minutes + m[0] > k: break
			m.popleft()
	count += 1
print(count)

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()))
    
    A_sum = 0
    A_max = N
    tmp_sum = 0
    if A[0] > K:
        flag = False
    else:
        flag = True
    for i in range(N):
        tmp_sum += A[i]
        if tmp_sum > K:
            A_max = i
            break
        else:
            A_sum = tmp_sum
        
    ans = A_max
    tmp_ans = ans
    #B_sum = 0
    B_i = 0
    time = K - A_sum
    count = 0
    for i in range(-1,A_max):
        if i != -1 and flag:
            A_i = A_max -1 -i
            time += A[A_i]
            count = -1
            
        if i == -1 or flag:
            tmp_time = time
            next_B_i = B_i
            for j in range(B_i,M):
                tmp_time -= B[j]
                if tmp_time >= 0:
                    next_B_i += 1
                    count += 1
                    time = tmp_time
                else:
                    break
                    
            B_i = next_B_i
            tmp_ans += count
            if count > 0:
                ans = tmp_ans
            
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0
sum_time = 0
while (n, m) != (0, 0):
    if a[0] < b[0]:
        if sum_time + a[0] > k:
            break
        sum_time += a.pop(0)
        ans += 1
        n -= 1
    else:
        if sum_time + b[0] > k:
            break
        sum_time += b.pop(0)
        ans += 1
        m -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_N = list(map(int, input().split()))
B_M = list(map(int, input().split()))
 
A_ind = 0
B_ind = 0
count = K
ans = 0
 
for i in range(N+M): 
  if A_N[0] < B_M[0]:
    if count >= A_N[0]:
      count -= A_N.pop(0)
      ans += 1
      if len(A_N) == 0:
        A_N.append(1000000001)
  else:
    if count >= B_M[0]:
      count -= B_M.pop(0)
      ans += 1
      if len(B_M) == 0:
        B_M.append(1000000001)
  if A_N[0] == 1000000001:
    if B_M[0] == 1000000001:
      break
print(ans)

Submission status: Wrong Answer

Solution code:


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

A = [i for i in map(int, input().split())]
B = [i for i in map(int, input().split())]
ans = 0
a = 0
b = 0
t = 0

while b != M or a != N:
    if b == M:
        if A[a]+t <= K:
            t += A[a]
            ans += 1
            a += 1
        else:
            break

    elif a == N:
        if B[b]+t <= K:
            t += B[b]
            ans += 1
            b += 1
        else:
            break
    elif B[b] >= A[a] and A[a]+t <= K:
        t += A[a]
        ans += 1
        a += 1
    elif B[b] < A[a] and B[b]+t <= K:
        t += B[b]
        ans += 1
        b += 1
    else:
        break


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

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

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

cnt = 0

c = deque(a)
d = deque(b)

i = c.popleft()
j = d.popleft()

while len(c) != 0 or len(d) != 0 or k >= 0:
    if i > j:
        k -= j
        if len(d) == 0:
            j = 10**10
        else:
            j = d.popleft()
    else:
        k -= i
        if len(c) == 0:
            i = 10**10
        else:
            i = c.popleft()

    if k < 0:
        break

    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
a=list(map(int,input().split()))+[10**9+1]
b=list(map(int,input().split()))+[10**9+1]
suma=0
sumb=0
i=0
j=0
while(True):
    suma+=a[i]
    if(suma>=k):
        break
    i+=1
        
while(True):
    sumb+=b[j]
    if(sumb>=k):
        break
    j+=1
suma-=a[i]
i-=1
sumb-=b[j]
j-=1
while(suma+sumb>k):
    if(a[i]>=b[j]):
        suma-=a[i]
        i-=1
    elif(a[i]<b[j]):
        sumb-=b[j]
        j-=1

print(i+j+2)

Submission status: Wrong Answer

Solution code:
import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

left = 0
right = len(list_)+1
while abs(left-right)>1:
  mid = (left+right) // 2
  if sum(list_[:mid])<=k:
    left = mid
  else:
    right = mid

if sum(list_[:right]) <=k:
  print(len(list_[:right]))
else:
  print(len(list_[:left]))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

    i_A = -1
    time = sum(A)
    for i, a in enumerate(reversed(A)):
        if time <= K:
            i_A = N - 1 - i
            break
        time -= a

    ans = i_A + 1
    cnt = i_A + 1
    for b in range(M):
        time += B[b]
        cnt += 1
        while True:
            if time <= K:
                break
            if i_A == -1:
                break
            time -= A[i_A]
            cnt -= 1
        if time <= K and cnt > ans:
            ans = cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin

conversion_data = []
for l in data:
    conversion_data.append([int(i) for i in l.split()])

table_a = conversion_data[1]
table_b = conversion_data[2]

N = conversion_data[0][0]
M = conversion_data[0][1]
limit = conversion_data[0][2]
max = max([N, M])

total_time = 0
position_a = 0
position_b = 0

for i in range(max):
  if position_a <= N - 1:
      a = table_a[position_a]
      if (a + total_time) < limit:
          total_time += a
          position_a += 1
  
  if position_b <= M - 1:
    b = table_b[position_b]
    if (b + total_time) < limit:
      total_time += b
      position_b += 1
  
print(position_a + position_b)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

Acum = np.cumsum(np.array(A))
Bcum = np.cumsum(np.array(B))

found = False
for n in range(N,-1,-1):
    if n>0:
        tA = Acum[n-1]
    else:
        tA = 0
    if tA>K:
        continue
    
    for m in range(M,-1,-1):
        if m>0:
            tB = Bcum[m-1]
        else:
            tB = 0
        if tA+tB<=K:
            num1 = n+m
            found = True            
            break
    if found:
        break

found = False
for m in range(M,-1,-1):
    if m>0:
        tB = Bcum[m-1]
    else:
        tB = 0
    if tB>K:
        continue
    
    for n in range(N,-1,-1):
        if n>0:
            tA = Acum[n-1]
        else:
            tA = 0
        if tA+tB<=K:
            num2 = n+m
            found = True            
            break
    if found:
        break

print(max(num1,num2))

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

time = 0
i_a = 0; i_b = 0
ans = 0

q = deque()
qa = deque(A); qb = deque(B)
a = qa.popleft(); b = qb.popleft()

while qa or qb:
    if a >= b:
        q.append(b)
        if qb:
            b = qb.popleft()
        else:
            b = 100000000001
    elif a < b:
        q.append(a)
        if qa:
            a = qa.popleft()
        else:
            a = 100000000001

q.append(min(a, b))    
    
for i in range(len(q)):
    time += q.popleft()
    if time > K:
        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()))

a_ac=[]
b_ac=[]

asum=0
bsum=0

for i in range(n):
    asum+=a[i]
    if asum>k:
        break
    a_ac.append(asum)

for i in range(m):
    bsum+=b[i]
    if bsum>k:
        break
    b_ac.append(bsum)
#print(a_ac,b_ac)
n=len(a_ac)
m=len(b_ac)

mx=0

if n ==0:
    print(m)
else:
    for i in reversed(range(n)):
        lim=k-a_ac[i]
        numb=0
        for j in range(numb,m):
            if b_ac[j]>lim:
                numb=j
                break
            if j == m-1:
                numb=m
        mx=max(mx,numb+i+1)
        #print(mx,numb)

    print(mx)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.buffer.readline


def SS(A, K):
    sA = 0
    AA = []
    for a in A:
        sA += a
        if sA > K:
            break
        AA.append(sA)

    return AA


def main():
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    AA = SS(A, K)
    BB = SS(B, K)
    AA = AA[::-1]

    M = max(len(AA), len(BB))

    left = 0
    right = len(BB) - 1

    while left < len(AA):
        if AA[left] + BB[right] <= K:
            m = len(AA) - left + right + 1
            if m >= M:
                M = m
                left += 1
            else:
                right -= 1
                if right < 0:
                    break
        else:
            right -= 1
            if right < 0:
                break

    print(M)


main()

Submission status: Wrong Answer

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



Kc=K
bookc=0

Ai=0
Bi=0

while Kc>0:
    if Ai<N:
        if Bi<M:
            if A[Ai]<=B[Bi] and A[Ai]<=Kc:
                bookc+=1
                Kc-=A[Ai]
                Ai+=1

            elif B[Bi]<=Kc:
                bookc+=1
                Kc-=B[Bi]
                Bi+=1
            else:
                break
        elif A[Ai]<=Kc:
            bookc+=1
            Kc-=A[Ai]
            Ai+=1
        else:
            break
    elif Bi<M:
        if B[Bi]<=Kc:
            bookc+=1
            Kc-=B[Bi]
            Bi+=1
        else:
            break
    if Ai==N and Bi==M:
        break

print(bookc)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = 0
b = 0
t_sum = 0
cnt = 0
flag = True

for _ in range(N+M):
  if A[a] <= B[b]:
    t_sum += A[a]
    cnt += 1
    a += 1
  elif A[a] > B[b]:
    t_sum += B[b]
    cnt += 1
    b += 1
  
  if t_sum >= K:
    cnt -= 1
    break
    
  if a == N:
    for _ in range(M+1):
      if b == M:
        flag = False
        break
      t_sum += B[b]
      cnt += 1
      b += 1
      if t_sum >= K:
        cnt -= 1
        flag = False
        break
  if b == M:
    for _ in range(N+1):
      if a == N:
        flag = False
        break
      t_sum += A[a]
      cnt += 1
      a += 1
      if t_sum >= K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,rem=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
i=0
j=0
k=0
c=list()
count=0
while k<n+m:
	if a[i]<=b[j]:
		c.append(a[i])
		k=k+1
		i=i+1
	else:
		c.append(b[j])
		k=k+1
		j=j+1
	if i==n:
		while j<m:
			c.append(b[j])
			k=k+1
			j=j+1
	if j==m:
		while i<n:
			c.append(a[i])
			k=k+1
			i=i+1
i=0
c.sort()
while i<len(c) and rem>=c[i] :
	rem=rem-c[i]
	i=i+1
	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()))
t = 0
c = 0
if sum(a) + sum(b) <= k:
    print(n+m)
    quit()
for i in range(min(n, m)-1):
    if t + a[i]> k:
        print(c)
        quit()
    t += a[i]
    c += 1
    if t + b[i]> k:
        print(c)
        quit()
    t += b[i]
    c += 1
    
if t < k:
    if max(n, m) == n:
        d = a
        e = b
    else:
        d = b
        e = a
    for i in range (len(e), len(d)-1):
        if t + d[i] > k:
            print(c)
            quit()
        t += d[i]
        c += 1
    print(c)
else:
    print(c)

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
time=0
aa=[]
bb=[]
if a[0]<=k:
    aa.append(a[0])
if b[0]<=k:
    bb.append(b[0])
avoid=False
bvoid=False
if len(aa)==0:
    avoid=True
if len(bb)==0:
    bvoid=True
    
for i in range(1,max(n,m)):
    if not avoid:
        if i<n and max(aa)<=k:
            if aa[-1]+a[i]<=k:
                aa.append(aa[i-1]+a[i])
    if not bvoid:
        if i<m and max(bb)<=k:
            if bb[-1]+b[i]<=k:
                bb.append(bb[i-1]+b[i])

nn=len(aa)
mm=len(bb)

for i in reversed(range(nn)):
    time=aa[i]
    if time+b[-1]<=k:
        ans=ans if ans>(i+1)+mm else (i+1)+mm
        break
    
    ok=0
    ng=mm-1
    while(abs(ok-ng)>1):
        mid=(ok+ng)//2
        if time+b[mid]<=k:
            ok=mid
        else:
            ng=mid
    ans=ans if ans>(i+1)+(ok+1) else (i+1)+(ok+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

left = 0
right = len(list_)+1
while abs(left-right)>1:
  mid = (left+right) // 2
  if sum(list_[:mid])<=k:
    left = mid
  else:
    right = mid

if sum(list_[:right]) <k:
  print(len(list_[:right]))
else:
  print(len(list_[:left]))

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 itertools import accumulate
aa=list(accumulate(a))
bb=list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n):
    if k<aa[i]:
        kmax=max(kmax,i+1)
        break
    kk=k-aa[i]
#    k2=min(bisect(bb,kk),m-1)
    k2=bisect(bb,kk)
    if k2<m-1 and bb[k2+1]==kk:
        k2+=1
#    print(i,k2)
    kmax=max(kmax,k2+i+1)
kmax=min(kmax,m+n)

print(kmax)

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()))
if sum(A)+sum(B)<=K:
  print(len(A)+len(B))
elif sum(A)<K and sum(A)+sum(B)>K:
  ans=len(A)
  time=sum(A)
  for i in range(len(B)):
    time+=B[i]
    if time>K:
      print(ans)
      exit()
    else:
      ans+=1
elif sum(B)<K and sum(A)+sum(B)>K:
  ans=len(B)
  time=sum(B)
  for i in range(len(A)):
    time+=A[i]
    if time>K:
      print(ans)
      exit()
    else:
      ans+=1
else:
  ans=0
  time=0
  while time>K :
    time+=min(A[0],B[0])
    ans+=1
    if A[0]<B[0]:
      del A[0]
    else:
      del B[0]
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

l1 = str(input()).split()

N = int(l1[0])
M = int(l1[1])
K = int(l1[2])

aq = deque([int(v) for v in str(input()).split()])
bq = deque([int(v) for v in str(input()).split()])

t = 0
count = 0
while N > 0 or M > 0:
    if M == 0:
        t = aq.popleft()
        N -= 1
    elif N == 0:
        t = bq.popleft()
        M -= 1
    else:
        ta = aq.popleft()
        tb = bq.popleft()
        if ta < tb:
            t = ta
            bq.appendleft(tb)
            N -= 1
        else:
            t = tb
            aq.appendleft(ta)
            M -= 1

    if (K - t) <= 0:
        break

    K -= t
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
def merge(x, y, a):
    i = 0
    j = 0
    while i < len(x) or j < len(y):
        if i == len(x):
            a[i+j] = y[j]
            j += 1
        elif j == len(y):
            a[i+j] = x[i]
            i += 1
        elif x[i] <= y[j]:
            a[i+j] = x[i]
            i += 1
        else:
            a[i+j] = y[j]
            j += 1
    return a
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[0]*(N+M)
C=merge(A,B,C)
c=sum(C)
if c==K:
    print(N+M)
    sys.exit()
for i in range(N+M):
    c-=C[-(i+1)]
    if c<K:
        print(N+M-i-1)
        break

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()))
ans = 0
#print(a, b)
time = k
for i in range(400010):
    if time > 0:
        if not a and not(not b):
            time -= b[0]
            b.popleft()
            ans += 1
               # print(a, b, time)
        elif not a and not b:
               # print(a, b, time)
                break
        elif not b and not(not a):
            time -= a[0]
            a.popleft()
            ans += 1
            #print(a, b, time)
        elif not(not a) and not(not b):
            if a[0] == b[0]:
                if n < m:
                    time -= b[0]
                    b.popleft()
                    ans += 1
                else:
                    time -= a[0]
                    a.popleft()
                    ans += 1
            elif a[0] < b[0]:
                time -= a[0]
                a.popleft()
                ans += 1
                #print(a, b, time)
            else:
                time -= b[0]
                b.popleft()
                ans += 1
                #print(a, b, time)
if time < 0:
    print(ans - 1)
else:
    print(ans)

Submission status: Wrong Answer

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

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

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

A.append(10**9+1)
B.append(10**9+1)

re = i = 0


while(m > 0 and i < a+b):
    if(A[0] < B[0]):
        s = A[0]
        del A[0]
    else:
        s = B[0]
        del B[0]
    m -= s
    if(m >= 0):
        re += 1
        i+=1
print(re)

Submission status: Wrong Answer

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

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

from collections import deque

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

ans = 0
time = k

while time >= 0:
    if a and b:
        tmp_a = time-a[0]
        tmp_b = time-b[0]
        if tmp_a >= 0 and tmp_b >= 0 and a[0] <= b[0]:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_a >= 0 and tmp_b >= 0 and b[0] < a[0]:
            time -= b[0]
            b.popleft()
            ans += 1
        elif tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    elif a:
        tmp_a = time-a[0]
        if tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        else:
            break
    elif b:
        tmp_b = time-b[0]
        if tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

cnt = 0
for i, a in enumerate(accumulate(A), 1):
    if a > K:
        break
    for j, b in enumerate(accumulate(B), 1):
        if a + b <= K:
            cnt = max(cnt, i + j)

print(cnt)

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
import math
from decimal import *
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
sum = 0
acount = 0
bcount = 0

while(sum < k):
    if acount == len(a) and bcount == len(b):
        break

    elif acount == len(a):
        mi = b[bcount]
        sum = Decimal(sum) + Decimal(mi)
        ans = Decimal(ans) + Decimal(1)
        bcount += 1

    elif bcount == len(b):
        mi = a[acount]
        sum = Decimal(sum) + Decimal(mi)
        ans = Decimal(ans) + Decimal(1)
        acount += 1

    else:
        if a[acount] < b[bcount]:
            mi = a[acount]
            sum = Decimal(sum) + Decimal(mi)
            ans = Decimal(ans) + Decimal(1)
            acount += 1
        else:
            mi = b[bcount]
            sum = Decimal(sum) + Decimal(mi)
            ans = Decimal(ans) + Decimal(1)
            bcount += 1

if k < sum:
    print(Decimal(ans) - Decimal(1))
else:
    print(Decimal(ans))

Submission status: Wrong Answer

Solution code:

def solve():
    total = 0
    cnt = 0
    i = 0
    j = 0
    while cnt<N+M:
#        print(i,j)
        if i==N and j == M:
            break
        elif j >= M:
            if total + A[i] <= K:
                total+=A[i]
                i += 1
            else:
                break
        elif i >= N:
            if total + B[j] <= K:
                total+=B[j]
                j += 1
            else:
                break
        elif A[i] <= B[j]:
            if total + A[i] <= K:
                total+=A[i]
                i += 1
            else:
                break
        elif A[i] > B[j]:
            if total + B[j] <= K:
                total+=B[j]
                j += 1
            else:
                break
    print(i+j)

if __name__=="__main__":
    N,M,K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = A+B
    AB.sort()
#    print(AB)
    solve()

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()))
mix = sorted(A + B)
temp_sum = 0
goal = 0
for i in range(len(mix)):
    temp_sum += mix[i]
    goal = i
    if bool(temp_sum > K):
        print(i)
        exit()
print(goal + 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())) 	

ans = 0
        
a_num = 0
b_num = 0

for _ in range(200000):

    try:
        a_num = A[0]
    except:
        a_num = -1
    try:
        b_num = B[0]
    except:
        b_num = -1

        
    if a_num != -1 and a_num < b_num:
        K = K - a_num
        A.pop(0)
    elif b_num != -1:
        K = K - b_num
        B.pop(0)
    
    if K < 0:
        break

    ans = ans + 1

    if K <= 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import mean
N,M,K=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
k=0
c=0
if sum(a) + sum(b) <= K:
    print(N+M)
else:
    while k <= K:
        if len(a) > 0 and len(b)>0:
            if mean(a) < mean(b) and ((k+a[0]) <=K):
                k+=a[0]
                c+=1
                a.pop(0)
            elif mean(a) > mean(b) and ((k+b[0]) <=K):
                k+=b[0]
                c+=1
                b.pop(0)
            else:
                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:
from sys import stdin
from itertools import accumulate

n, m, k = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]

goukei = min(a[0], b[0])
kaisu = 0
new = []
for i in range(n + m):
  if goukei <= k:
    if len(a) == 0:
      goukei += b[0]
      b.pop(0)
      kaisu += 1
    elif len(b) == 0:
      goukei += a[0]
      a.pop(0)
      kaisu += 1
    else:
      goukei += min(a[0], b[0])
      kaisu+=1
      break;
  else:
    break;
print(kaisu)
"""
new = list(accumulate(new))
for x in range(len(new)):
  if new[x] <= k:
    goukei += 1

print(goukei)
"""

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)
A.sort(reverse=True)
B.sort(reverse=True)
total = 0
count = 0
for i in range(n + m):
    time = min(A[-1], B[-1])
    if A[-1] == time:
        total += A.pop()
    elif B[-1] == time:
        total += B.pop()
    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()))
ans = 0
x = min(a[0],b[0])
while x<=k and k!=0:
    if len(a) and len(b) :
        if a[0] <= b[0]:
            k-=a[0]
            a.pop(0)
        elif a[0] > b[0]:
            k-=b[0]
            b.pop(0)
    elif len(a) and not len(b):
        k-=a[0]
        a.pop(0)
    elif len(b) and not len(a):
        k-=b[0]
        b.pop(0)
    if len(a)==0 and len(b)==0:
        x = 0
    elif len(a) and len(b) :
        x = min(a[0],b[0])
    elif not len(b):
        x = a[0]
    elif not len(a):
        x = b[0]
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
K2 =K
count = 0
numa = 0
numb = 0
count2 = 0
for i in range(N):
    count += A[i]
    A[i] = count
#累積和
B = list(map(int,input().split()))
count = 0
for i in range(M):
    count += B[i]
    B[i] = count
#累積和

for i in range(N):#Aに対してBを探す
    K = K2
    if A[i] <= K:
        K -= A[i]
        bisect.bisect_left(B, K)
        if bisect.bisect_left(B, K) <= M and B[bisect.bisect_left(B, K)-1] <= K:#Aに大して最大化するB
            if count2<A[i] + B[bisect.bisect_left(B, K)-1]:
                count2 = max(count2,A[i] + B[bisect.bisect_left(B, K)-1])   
                numa = i+1
                numb =   bisect.bisect_left(B, K)
    else:
        break
print(numa + numb)

Submission status: Wrong Answer

Solution code:
import sys

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

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



"""i_n = 0
i_m = 0
while True:
    if i_n >= n and i_m >= m:
        break
    elif i_n >= n:
        tmp = b[i_m]
        i_m += 1
    elif i_m >= m:
        tmp = a[i_n]
        i_n += 1
    else:
        if a[i_n] < b[i_m]:
            tmp = a[i_n]
            i_n += 1
        else:
            tmp = b[i_m]
            i_m += 1

    if tmp + time <= k:
        cnt += 1
        time += tmp
    else:
        break
print(cnt)"""