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

num = len(a) + len(b)
count = 0
time = 0
for i in range(num):
    if len(a) > 0 and len(b) > 0:
        if a[0] <= b[0]:
            time += a[0]
            a.remove(a[0])
            if time > k:
                break
            else:
                count += 1
        else:
            time += b[0]
            b.remove(b[0])
            if time > k:
                break
            else:
                count += 1
    elif len(a) > 0 and len(b) == 0:
        time += a[0]
        a.remove(a[0])
        if time > k:
            break
        else:
            count += 1
    elif len(a) == 0 and len(b) > 0:
        time += b[0]
        b.remove(b[0])
        if time > k:
            break
        else:
            count += 1
    elif len(a) == 0 and len(b) == 0:
        break
print(count)

Submission status: Wrong Answer

Solution code:
a = input().split()
x = input().split()
y = input().split()
z = x + y
print(z)
zz = []
zz = list(map(lambda i: int(i), z))
print(zz)
t = 0
for i in range(len(zz)):
  if t > int(a[2]):
    break
  t += sorted(zz)[i]
print(t)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

aa = [0] + list(itertools.accumulate(A))
bb = [0] + list(itertools.accumulate(B))

ans = bisect.bisect_left(aa, K)-1
ans = max(ans, bisect.bisect_left(aa, K)-1)

for i in reversed(range(N+1)):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if i + M <= ans:
        continue

    if ans != 0 and bb[(ans-i+1)] >= tmp_K:
        continue

    if tmp_K >= bb[-1]:
        ans = max(ans, i+M)
        continue

    mn = 0
    mx = M
    while True:
        if mn == mx:
            if tmp_K >= bb[mn]:
                ans = max(ans, i+mn)
            break

        mid = (mn+mx//2)
        if bb[mid] <= tmp_K:
            if mn == mid:
                mn = mid+1
            else:
                mn = mid

        else:
            if mx == mid:
                mx = mid-1
            else:
                mx = mid
            if i+mx <= ans:
                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()))

ac=0
bc=0
h=0
c=0
al=len(a)-1
bl=len(b)-1

while True:
    if ac>al:
        h+=b[bc]
        bc+=1
        if bc>bl:
            if h<=k:
                c+=1
            break
    elif bc>bl:
        h+=a[ac]
        ac+=1
        if ac>al:
            if h<=k:
                c+=1
            break
    elif a[ac]<=b[bc]:
        h+=a[ac]
        ac+=1
    else:
        h+=b[bc]
        bc+=1
    if h>k:
        break
    else:
        c+=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()))

'''
tmp = 0
count = 0
sum = 0
while 1:
    if n  == 0 and m == 0:
        break
    elif n == 0:
        tmp = b.pop(0)
        m -= 1
    elif m == 0:
        tmp = a.pop(0)
        n -= 1
    elif a[0] > b[0]:
        tmp = b.pop(0)
        m -= 1
    elif a[0] <= b[0]:
        tmp = a.pop(0)
        n -= 1

    sum += tmp
    if sum > k:
        break
    count += 1
print(count)
'''
_n = 0
_m = 0
sum = 0
count = 0
while 1:
    if _n >= n and _m >= m:
        break
    elif _n >= n:
        sum += b[_m]
        _m += 1
    elif _m >= m:
        sum += a[_n]
        _n += 1
    elif a[_n] > b[_m]:
        sum += b[_m]
        _m += 1
    elif a[_n] <= b[_m]:
        sum += a[_n]
        _n += 1
    
    if (sum > 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()))
time_of_A = [A[0]]
for i in range(1, N):
  time_of_A.append(time_of_A[i-1]+A[i])
B = list(map(int, input().split()))
time_of_B = [B[0]]
for i in range(1, M):
  time_of_B.append(time_of_B[i-1]+B[i])

book = [0]
for i in range(N):
  if time_of_A[i] <= K:
    book.append(i+1)

start = M-1
for i in range(N):
  j = start
  time = 10 ** 9 + 1
  while time > K and j >= 0:
    time = time_of_A[i] + time_of_B[j]
    j -= 1
  if time <= K:
    book.append(i+j+3)
    j +=1
    start = j
  else:
    break
print(max(book))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
a = stdin.readline().rstrip().split(' ')
b = stdin.readline().rstrip().split(' ')
k = int(l[2])
n = int(l[0])
m = int(l[1])
ia = 0
ib = 0
b_sum = 0
count = 0
a_sum = 0
res = []

for ib in range(m):
    b_sum += int(b[ib])
    if b_sum <= k:
        count += 1
    else:
        break
res.append(count)
count = 0
for ia in range(n):
    a_sum = a_sum + int(a[ia])
    if k < a_sum:
        #print("ok")
        res.append(count)
        continue
    else:
        count = ia + 1
    b_sum = a_sum
    for ib in range(m):
        b_sum += int(b[ib])
        if b_sum <= k:
            count += 1
        else:
            break
    res.append(count)
print(res)

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
i=0
j=0
while count<=k:
  if a[-1]==10**10 and b[-1]==10**10:
    break
  else:
    if a[i]<b[j] and a[i]<=k-count:
      count+=a[i]
      if i+2>len(a):
        a.append(10**10)
        i+=1
      else:
        i+=1
    elif b[j]<=a[i] and b[j]<=k-count:
      count+=b[j]
      if j+2>len(b):
        b.append(10**10)
        j+=1
      else:
        j+=1
    else:
      break
print(i+j)

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()))
ex=0
inda=0
t=0
for i in range(len(a)):
    ex+=a[i]
    if ex<=k:
        inda=i
        t+=a[i]
    else:
        break
if inda!=0:
    ans=inda+1
else:
    ans=0
aq=deque(a[:inda+1])
bq=deque(b)
now=ans
while len(aq)!=0 and len(bq)!=0:
    if t+bq[0]<=k:
        t+=bq.popleft()
        now+=1
        ans=max(ans,now)
    else:
        t+=bq.popleft()
        t-=aq.pop()
if len(bq)==0:
    print(ans)
else:
    while t<=k and len(bq)!=0:
        t+=bq.popleft()
        if t<=k:
            now+=1
            ans=max(ans,now)
    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

for i in range(N):
    for j in range(M):
        if K >= 0:
            if a[i] > b[j]:
                count += 1
                K -= b[j]
                continue
            else:
                count += 1
                K -= a[i]

                continue
        else:
            break
    else:
        continue
    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()))

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

#print(AL)
#print(BL)

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

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

#print(a,b)

m = a
u = 0
for j in reversed(range(a)):
#    print(j,u)
    t = k-AL[j]
    for i in range(u,b):
#        print(i)
        if t-BL[i]>=0:
            if m < j+1 + i +1:
                m = j+1 + i +1
#                print(m)
        else:
            if u >0:
                u = i-1
            break
        
    if j+1+b<=m:
        break
if a == 0 and b > 0:
    m = b
print(m)

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

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i
        break
else:
    ans1=N
ans2=0
ans3=0
for i in range(ans1):
    if ans1==1:
        while i+ans2<=M and A[ans1-i-1]+B[i+ans2]<=K:
            ans2+=1
        ans3=max(ans3,ans1+ans2-2)
    else:
        while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
            ans2+=1
        ans3=max(ans3,ans1+ans2-1)
print(ans3)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0
    a_time = [0]
    b_time = [0]
    for i in range(1, len(a) + 1):
        a_time.append(a_time[i - 1] + a[i - 1])
    for i in range(1, len(b) + 1):
        b_time.append(b_time[i - 1] + b[i - 1])

    a_max = 0
    b_max = 0
    for i in range(len(a_time)):
        if a_time[i] > k:
            break
        else:
            a_max = i
    for i in range(len(b_time)):
        if a_time[a_max] + b_time[i] <= k:
            ans = max(ans, a_max + i)
        if b_time[i] > k:
            break
        else:
            b_max = i

    for i in range(len(a_time)):
        if b_time[b_max] + a_time[i] <= k:
            ans = max(ans, a_max + i)
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt =0
while sum < k and  (len(a) != 0 or len(b) != 0 ):
    if len(a) != 0 and len(b) != 0:
        if a[0]<b[0]:
            sum += a[0]
            del a[0]
        else:
            sum += b[0]
            del b[0]
    elif len(a) == 0:
        sum += b[0]
        del b[0]
    else :
        sum += a[0]
        del a[0]
    if sum<=k :
        cnt+=1

print(cnt)

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

minute = 0
i = 0
j = 0

while i < n and j < m:
  if alist[i] < blist[j]:
    minute += alist[i]
    if minute > k:
      break
    i += 1
  else:
    minute += blist[j]
    if minute > k:
      break
    j += 1

if minute > k:
  print(i+j)
elif i < n:
  while i < n:
    minute += alist[i]
    if minute >= k:
      break
    i += 1
  print(i+j)
else:
  while j < m:
    minute += blist[j]
    if minute > k:
      break
    j += 1  
  print(i+j)

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_a = [0]*(n+1)
s_b = [0]*(m+1)
for i in range(1,n+1):
    s_a[i] = s_a[i-1] + a[i-1]
for i in range(1,m+1):
    s_b[i] = s_b[i-1] + b[i-1]
import bisect
Sa = bisect.bisect_right(s_a,k) -1
Sb = bisect.bisect_right(s_b,k) -1

ans = Sa
for i in range(1,Sa+1):
    x = max(0, k - s_a[Sa-i+1])
    y = bisect.bisect_right(s_b,x)
    ans = max(ans,y+Sa-i)
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = list(map(int, input().split()))
e.extend(d)
e.sort()
n = 0
m = 0
   
while True:
  m += e[0]
  e.pop(0)
  if m >= c:
    if m - c < 0:
      n -=  1
    break
  n += 1
 
print(n)

Submission status: Wrong Answer

Solution code:
N, M, K = (int(s) for s in input().rstrip().split())

A = [int(s) for s in input().rstrip().split()]
B = [int(s) for s in input().rstrip().split()]

i, j = (0, 0)
sum, count = (0, 0)

while sum < K:
  if (i < N) and (j < M):
    if A[i] <= B[j]:
      sum += A[i]
      i += 1
      count += 1
    else:
      sum += B[j]
      j += 1
      count += 1
  elif i < N:
    sum += A[i]
    i += 1
    count += 1
  elif j < M:
    sum += B[j]
    j += 1
    count += 1
  else:
    break

if sum > K:
  count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int, input().split())
a = deque(map(int, list(input().split())))
b = deque(map(int, list(input().split())))
t = 0
c = 0
while k <= 1000000000 and n <= 200000 and m <= 200000:
    if c < n+m:
        if len(b) == 0 and t + a[0] <= k and a[0] <= 1000000000:
            t = t + a[0]
            a.popleft()
            c = c + 1
        elif len(a) == 0 and t + b[0] <= k and b[0] <= 1000000000:
            t = t + b[0]
            b.popleft()
            c = c + 1
        elif len(a) > 0 and len(b) > 0:
            if a[0] <= b[0] and a[0] <= 1000000000 and b[0] <= 1000000000 and t + a[0] <= k:
                t = t + a[0]
                a.popleft()
                c = c + 1
            elif a[0] > b[0] and a[0] <= 1000000000 and b[0] <= 1000000000 and t + b[0] <= k:
                t = t + b[0]
                b.popleft()
                c = c + 1
            else:
                break
        else:
            break
    else:
        break
print(c)

Submission status: Wrong Answer

Solution code:
import copy
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()))
a = 0
b = 0

tmp = 0
ans = 0
# for i in range(200000):
#     if A[a] < B[b]:
#         if tmp <= K:
#             tmp += A[a]
#             ans += 1
#             a += 1
#     elif A[a] > B[b]:
#         if tmp <= K:
#             tmp += B[b]
#             ans += 1
#             b += 1
#     if a > len(A)-1 or b > len(B)-1:
#         break
fa = False
fb = False

while len(A) > 0 or len(B) > 0:
    AA = copy.copy(A)
    BB = copy.copy(B)
    if len(AA) != 0:
        a = AA.pop(0)
        fa = True
    if len(BB) != 0:
        b = BB.pop(0)
        fb = True
    if fa and fb:
        if a<=b:
            tmp += a
            ans += 1
            A = AA
        else:
            tmp += b
            ans += 1
            B = BB
    else:
        if fa:
            tmp += a
            ans += 1
            A = AA
        if fb:
            tmp += b
            ans += 1
            B = BB

    if tmp > K:
        break
    fa = False
    fb = False
    
    #print(tmp,A,B)
    
if len(A)==0 and len(B)==0:
    print(ans)
else:
    print(ans-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()))

suma = [ -1 for i in range(n) ]
sumb = [ -1 for i in range(m) ]
suma[0] = a[0]
sumb[0] = b[0]
for i in range(1,n):
  suma[i] = suma[i - 1] + a[i]
  if suma[i] > 10**9:
    break
for i in range(1,m):
  sumb[i] = sumb[i - 1] + b[i]
  if sumb[i] > 10**9:
    break

c = 0
for i in range(n):
  if suma[i] == -1:
    break
  for j in range(m):
    if sumb[j] == -1:
      break
    t = suma[i] + sumb[j]
    if t <= k:
      c = max(c,i + j + 2)

print(c)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]
B=[int(y) for y in input().split()]
A.append(10**9+1)
B.append(10**9+1)
ans=0
a_nowtime=0
b_index=0
B_time=[0]*M
kari=0#time
for j in range(M):
    kari+=B[j]
    B_time[j]=kari
kari=0#numofbookofa+b

for i in range(N):
    a_nowtime+=A[i]
    if a_nowtime<=K:
        time=K-a_nowtime
        num=bisect.bisect_right(B_time,time)
        kari=i+1+num
        ans=max(ans,kari)

print(ans)

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()))
sum_A=0
count_A=0
sum_B=0
count_B=0
ans=0


for i in range(N):
  temp_A=A[i]
  if sum_A+temp_A<K:
    sum_A += temp_A
  else:
    count_A = i
    break
else:
  count_A = i+1

for i in range(M):
  temp_B=B[i]
  if sum_B+temp_B<K:
    sum_B += temp_B
  else:
    count_B = i
    break
else:
  count_B = i+1
  
def check(K,sum_A,sum_B,count_A,count_B):
  if sum_A+sum_B<=K:
    return count_A+count_B
  else:
    return 0

if max(sum_A,sum_B)>0:
  ans = check(K,sum_A,sum_B,count_A,count_B)

while True:
  if ans>0:
    break
  if count_A==0 and count_B==0:
    break
  elif count_A==0:
    ans = count_B
    break
  elif count_B==0:
    ans = count_A
    break
  if A[count_A-1] > B[count_B-1]:
    sum_A-=A[count_A-1]
    count_A-=1
    ans = check(K,sum_A,sum_B,count_A,count_B)
  else:
    sum_B-=B[count_B-1]
    count_B-=1
    ans = check(K,sum_A,sum_B,count_A,count_B)
  
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=0
j=0
a.append(10000000000)
b.append(10000000000)
while True:
    if i==n and j==m:
        break
    elif a[i]<=b[j]:
        if k-a[i]<0:
            break
        k-=a[i]
        i+=1
    else:
        if k-b[j]<0:
            break
        k-=b[j]
        j+=1
print(i+j)

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_ind = 0
b_ind = 0
while k > 0:
    if n > a_ind and m > b_ind:
        if a[a_ind] < b[b_ind]:
            if k >= a[a_ind]:
                k -= a[a_ind]
                a_ind += 1
                ans += 1
            else:
                break
        else:
            if k >= b[b_ind]:
                k -= b[b_ind]
                b_ind += 1
                ans += 1
            else:
                break
    elif n > a_ind and m == b_ind:
        if k >= a[a_ind]:
            k -= a[a_ind]
            a_ind += 1
            ans += 1
        else:
            break
    elif n == a_ind and m > b_ind:
        if k >= b[b_ind]:
            k -= b[b_ind]
            b_ind += 1
            ans += 1
        else:
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

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()
cnt = 0
time = 0
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
"""while True:
    if a[-1] < b[-1]:
        tmp= a.pop()
    else:
        tmp = b.pop()
    
    if tmp + time <= k:
        cnt += 1
        time += tmp
    else:
        break"""
print(cnt)

Submission status: Wrong Answer

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

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

i=0
la=len(A)


 
B= list(map(int,arr.split(' '))) 
lb=len(B)

for x in range(la):
    if(A[x]<K):
        K=K-A[0]
        i=i+1
    for y in range(lb):
    	if(B[y]<K):
        	K=K-B[0]
        	i=i+1

print(i)

Submission status: Wrong Answer

Solution code:
import collections
def C():
    N, M, K = map(int, input().split())
    A = collections.deque(list(map(int, input().split())))
    B = collections.deque(list(map(int, input().split())))
    ans = 0
    while A and B and K:
        if A[0] <= B[0] and K >= A[0]:
            K -= A.popleft()
            ans += 1
        elif K >= B[0]:
            K -= B.popleft()
            ans += 1
        else:
            print(ans)
            return
    while A and K >= A[0]:
        K -= A.popleft()
        ans += 1
    while B and K >= B[0]:
        K -= B.popleft()
        ans += 1
    print(ans)

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()))
c = 0
ans = 0
ia = 0
ib = 0
while c <= K:
  if ia == N and ib == M:
    break
  elif ia == N:
    c += B[ib]
    ib += 1
     
  elif ib == M:
    c += A[ia]
    ia += 1
    
  elif A[ia] <= B[ib]:
    c += A[ia]
    ia += 1
     
  else:
    c += B[ib]
    ib += 1
  if c <= K:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N,M,K=list(map(int, input().split()))
res=0
ans=0
A=collections.deque(map(int, input().split()))
B=collections.deque(map(int, input().split()))
while (A or B):
    if A and B:
        a = min(A[0], B[0])
        if a == A[0]:
            A.popleft()
        else:
            B.popleft()
    elif A:
        a = A[0]
        A.popleft()
    else:
        a = B[0]
        B.popleft()
    if res+a>K:
        break
    else:
        res+=a
        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()))

T=0
U=0
V=0
Q=0
K1=0
for j in range(N):
    if K1+A[j]<=K:
        K1+=A[j]
    else:
        break
K2=0
for k in range(M):
    if K2+B[k]<=K:
        K2+=B[k]
    else:
        break
for i in range(N+M):
    if U<N and V<M:
        if A[U]>=B[V] and T+B[V]<=K:
            T+=B[V]
            V+=1
            Q+=1
        elif A[U]<=B[V] and T+A[U]<=K:
            T+=A[U]
            U+=1
            Q+=1
    elif U>=N and V<M:
        if T+B[V]<=K:
            T+=B[V]
            V+=1
            Q+=1
    elif U<N and V>=M:
        if T+A[U]<=K:
            T+=A[U]
            U+=1
            Q+=1
    else:
        break

print(max(Q,j,k))

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    t = 0
    ca, cb = 0, 0
    for a in A:
        t += a
        if t > k:
            t -= a
            break

        ca += 1

    while True:
        if t > k:
            cb -= 1
            t -= B[cb]
            break

        if cb == len(B):
            break

        t += B[cb]
        cb += 1

    AA = [ca + cb]
    while True:
        if ca == 0 or cb == len(B):
            break

        ca -= 1
        t -= A[ca]
        while True:
            t += B[cb - 1]
            if t > k or cb == len(B):
                break

            cb += 1

        AA.append(ca + cb)

    print(max(AA))


if __name__ == '__main__':
    main()

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

for i in range(N+M): 
  if A_ind < N and B_ind < M:
    if A_N[A_ind] < B_M[B_ind]:
      if count + A_N[A_ind] <= K:
        count += A_N[A_ind]
        ans += 1
        A_ind += 1
      else:
        break
    elif A_N[A_ind] >= B_M[B_ind]:
      if count + B_M[B_ind] <= K:
        count += B_M[B_ind]
        ans += 1
        B_ind += 1
      else:
        break
  elif A_ind < N:
    if count + A_N[A_ind] <= K:
      count += A_N[A_ind]
      ans += 1
      A_ind += 1
    else:
      break
  elif B_ind < M:
    if count + B_M[B_ind] <= K:
      count += B_M[B_ind]
      ans += 1
      B_ind += 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()))
a.append(10000000000000)
b.append(10000000000000)
a.append(10000000000000)
b.append(10000000000000)
total_time = 0

ans = 0
num_a = 0
num_b = 0

while total_time <= k:
    if a[num_a]+a[num_a+1] < b[num_b]+b[num_b+1]:
        total_time += a[num_a]
        num_a += 1
    else:
        total_time += b[num_b]
        num_b += 1
    ans += 1

if total_time > k:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import itertools
import bisect

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

cA = list(itertools.accumulate(A))
cB = list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(n):
    tmp = cA[-(i+1)]
    if tmp <= k:
        indb = bisect.bisect_right(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    
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()))

answer = 0
spend = 0
a_index = 0
b_index = 0
while (True):
    if a_index < len(A) and b_index < len(B):
        # aとbの短い方
        if A[a_index] < B[b_index]:
            if spend + A[a_index] <= K:
                spend += A[a_index]
                a_index += 1
                answer += 1
            else:
                break
        else:
            if spend + B[b_index] <= K:
                spend += B[b_index]
                b_index += 1
                answer += 1
            else:
                break
    elif a_index == len(A):
        # bのみ
        if b_index == len(B):
            break
        if spend + B[b_index] <= K:
            spend += B[b_index]
            b_index += 1
            answer += 1
        else:
            break
    elif b_index == len(B):
        # aのみ
        if a_index == len(A):
            break
        if spend + A[a_index] <= K:
            spend += A[a_index]
            a_index += 1
            answer += 1
        else:
            break

print(answer)

Submission status: Wrong Answer

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

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

i,j = 0,0

cnt = 0

while((i<n and j<m) and (a[i]<=k or a[j]<=k)):
    if(a[i]<=b[j] and a[i]<=k):
        k-=a[i]
        i+=1
    
    elif(b[j]<=a[i] and b[j]<=k):
        k-=b[j]
        j+=1
    
    cnt+=1
    

while(i<n and a[i]<=k):
    k-=a[i]
    i+=1
    cnt+=1
    
while(j<m and b[j]<=k):
    k-=b[j]
    j+=1
    cnt+=1

print(cnt)

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()]
nansatsu = 0
while(1):
    if(len(A) > 0 and len(B)>0):
        if A[0] <= B[0]:
            if K >= A[0]:
                K-=A.pop(0)
                nansatsu+=1
            else:
                break
        else:
            if K >= B[0]:
                K-=B.pop(0)
                nansatsu+=1
    else:
        if len(A) == 0 and len(B) == 0:
            break
        elif len(A) > len(B):
            if K >= A[0]:
                K-=A.pop(0)
                nansatsu+=1
            else:
                break
        else:
            if K >= B[0]:
                K-=B.pop(0)
                nansatsu+=1
            else:
                break
print(nansatsu)

Submission status: Wrong Answer

Solution code:
nmk=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
k=nmk[2]
time=0
cnt=0
while time<=k:
  if len(b)==0:
    time+=a[0]
    _=a.pop(0)
    cnt+=1
  elif len(a)==0:
    time+=b[0]
    _=b.pop(0)
    cnt+=1
  elif a[0]<=b[0]:
    time+=a[0]
    _=a.pop(0)
    cnt+=1
  elif a[0]>b[0]:
    time+=b[0]
    _=b.pop(0)
    cnt+=1
 # print(a,b,time)
  if time>k:
    cnt-=1
  if len(a)==0 and len(b)==0:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
x = input().split()
N = int(x[0])
M = int(x[1])
K = int(x[2])
C =[]
A = input().split()
B = input().split()
A.append(10000000000)
B.append(10000000000)
for i in range(N + M):
    if int(A[0]) <= int(B[0]):
        C.append(int(A[0]))
        del A[0]
    else:
        C.append(int(B[0]))
        del B[0]

T = 0
book = 0
for i in range(len(C)):
    if T + C[i] > K:
        break
    else:
        T += C[i]
        book += 1

print(book)

Submission status: Wrong Answer

Solution code:
def main():
    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()]

    import itertools
    import bisect
    A = list(itertools.accumulate(A))
    B = list(itertools.accumulate(B))
    ans = bisect.bisect_right(B, K)
    for i in range(len(A)-1, -1, -1):
        target = K - A[i]
        if target > 0:
            j = bisect.bisect_right(B, target)
            ans = max(ans, i+j+1)
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    from bisect import bisect_right
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    A,B=[0],[0]
    x,y=0,0
    for i in range(n):
        x+=a[i]
        A.append(x)
    for j in range(m):
        y+=b[j]
        B.append(y)
    ai=bisect_right(A,k)-1
    ans=0
    for i in range(ai,-1,-1):
        bi=bisect_right(B,k-a[i-1])-1
        ans=max(ans,i+bi)
    print(ans)

if __name__ == '__main__':
    resolve()