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:
import numpy as np

N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
  A[i] = int(A[i])
for i in range(len(B)):
  B[i] = int(B[i])
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
for i in range(M):
  if B_cumsum[i] <= K and max_count <= B_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] > K:
    break
  for j in range(M):
    if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
      max_count = i + j + 2
    else:
      break
print(max_count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
A = input().split()
B = input().split()
c = 0
for i in range(len(B)):
    if i < len(A):
        if k >= int(A[i]):
            k = k - int(A[i])
            c += 1
    if k >= int(B[i]):
        k = k - int(B[i])
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
i = 0
j = M-1

B_SUM = [0] * M
B_SUM[0] = B[0]

max_book = 0

for i in range(1, M):
    B_SUM[i] = B[i] + B_SUM[i - 1]
    if B_SUM[i] <= K:
        max_book = i + 1

A_SUM = 0

b_index = M - 1

for i in range(N):
    A_SUM += A[i]
    while (b_index >= 0):
        B_SUM[b_index]
        if A_SUM + B_SUM[b_index] <= K:
            max_book = max(max_book, b_index + 1 + i + 1)
            break
        b_index -= 1
print(max_book)

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

if(n<m):
    for i in range(m-n):
        a.append(10**10)
if(n>m):
    for i in range(n-m):
        b.append(10**10)

print(a)
print(b)
time=0
i=0
j=0
count=0

while(True):
    
    if(i>len(a)-1):
        time+=b[j]
        count+=1
        j+=1
        
    if(j>len(b)-1):
        time+=a[i]
        count+=1
        i+=1
    
    
    if(time>k):
        break
    
    if(a[i]<b[j]):
        time+=a[i]
        count+=1
        i+=1
    elif(a[i]>b[j]):
        time+=b[j]
        count+=1
        j+=1
    else:
        ii=i
        jj=j
        while(True):
            if(a[ii]<b[ii]):
                time+=a[i]
                count+=1
                i+=1
                break
            elif(a[ii]>b[jj]):
                time+=b[j]
                count+=1
                j+=1
                break
            else:
                ii+=1
                jj+=1
                if(ii>len(a)-1):
                    time+=b[j]
                    count+=1
                    j+=1
                    break
                if(jj>len(b)-1):
                    time+=a[i]
                    count+=1
                    i+=1
                    break

        

print(count-1)

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

Ax = []
Bx = []
aadd, badd = 0, 0
for a in A:
    aadd += a
    Ax.append(aadd)

for b in B:
    badd += b
    Bx.append(badd)

len_a, len_b = len(A), len(B)

def getNext(pos_a,pos_b):
    if pos_a == -1:
        a = 0
    elif pos_a >= len_a:
        a = 10**9
    else:
        a = Ax[pos_a]

    if pos_b == -1:
        b = 0
    elif pos_b >= len_b:
        b = 10**9
    else:
        b = Bx[pos_b]

    return (a + b)

# search
res, r, res_c = 0, 0, 0
pos_a, pos_b = -1, -1

while True:
    # diff
    ra = rb = 0
    ra = getNext(pos_a+1,pos_b)
    rb = getNext(pos_a,pos_b+1)

    if (ra > K and rb > K) or (ra == 0 and rb == 0):
        break

    if ra < rb:
        pos_a += 1
        res = ra
    else:
        pos_b += 1
        res = rb

print(pos_a+pos_b+2)

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

#1

import numpy as np
import bisect
acum=np.cumsum(a).tolist()
bcum=np.cumsum(b).tolist()

ans=0

for i,c in enumerate(acum):
    d=k-c
    if d<0:break
    j=bisect.bisect_right(bcum,d)-1
 
    ans=max(ans,(i+1)+(j+1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

    yomuA = a[0]
    yomuB = b[0]
    ans = []
    
    countA = 0
    countB = 0

    for i in range(400000):
        if (yomuA < yomuB):
            if (countA < n-1):
                ans.append(yomuA)
                countA += 1
                yomuA = a[countA]
            elif (countA == n-1):
                ans.append(yomuA)
                for j in range(countB, m):
                    ans.append(b[j])
                break
        else:
            if (countB < m-1):
                ans.append(yomuB)
                countB += 1
                yomuB = b[countB]
            elif(countB == m-1):
                ans.append(yomuB)
                for t in range(countA, n):
                    ans.append(a[t])
                break

    sum_ = 0
    for s in range(len(ans)):
        sum_ += ans[s]
        if (sum_ > k):
            print(s)
            break
        elif(s == len(ans)-1):
            print(s+1)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = 0
ans = 0
ca = 0
for i in range(n):
  if k >= s + a[i]:
    s += a[i]
    ans += 1
    ca += 1
  else:
    break
cb = 0
for i in range(m):
  if k >= s + b[i]:
    s += b[i]
    ans += 1
    cb = 1
  else:
    break
if ans == n + m or ans == 0:
  print(ans)
else:
  l = [ans]
  while ca >= 0:
    s + a[ca - 1]
    ca -= 1
    ans -= 1
    if k >= s + b[cb - 1]:
      s += b[cb - 1]
      cb += 1
      ans += 1
      l.append(s)
  print(max(l))

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()))
c = 0
i = 0
j = 0
ans = 0
if k >= sum(a) + sum(b):
    ans = n + m
    print(ans)
    sys.exit()
list_ab = []
while c <= (n+m-1):
    if i >= n :
        list_ab.append(b[j])
        j += 1
        c += 1
    elif j >= m :
        list_ab.append(a[i])
        i += 1
        c += 1
    elif a[i] <= b[j]:
        list_ab.append(a[i])
        i += 1
        c += 1
    elif a[i] > b[j]:
        list_ab.append(b[j])
        j += 1
        c += 1
book = 0
for i in range(n+m):
    if k >= list_ab[i]:
        k -= list_ab[i]
        book += 1
    else:
        break
print(book)

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()))
# n, m, k = (3, 4, 240)
# a = [60, 90, 120]
# b = [80, 150, 80, 150]

ans = 0
num_a = n-1
num_b = 0
flg = True

total_time = sum(a)

for i in range(n):
    if total_time > k:
        total_time -= a[num_a]
        num_a -= 1
    else:
        for j in range(num_b, n):
            if total_time + b[num_b] > k:
                flg = False
                break
            else:
                total_time += b[num_b]
                num_b += 1
                flg = True


ans = num_a+1 + num_b+1
if flg is False:
    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()))

L = sorted(A + B)

time = 0
ans = 0
for x in L:
  if time + x <= K:
    ans += 1
    time += x
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=input().split()
A=input().split()
B=input().split()
A.append(10**9)
B.append(10**9)
#print(N,M,K,A,B)
num=0
Nnum=0
Mnum=0
now_time=0

max_loop=int(M)+int(N)


for i in range(max_loop):
  #print(int(A[Nnum]),int(B[Mnum]))
  if(int(A[Nnum])<int(B[Mnum])):
    now_time=now_time+int(A[Nnum])
    Nnum=Nnum+1
    num=num+1
  else:
    now_time=now_time+int(B[Mnum])
    Mnum=Mnum+1
    num=num+1
  
  if(now_time>int(K)):
    num=num-1
    break
  
  
print(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()) ) 
C = []
while sum(C) <= K:
    try:
        if A[0] < B[0]:
            C.append(A[0])
            del A[0]
        else:
            C.append(B[0])
            del B[0]
    except IndexError:
        if len(A) != 0:
            C.append(A[0])
        elif len(B) != 0:
            C.append(B[0])
        else:
            break
if sum(C) > K:
    print(len(C)-1)
else:
    print(len(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(10**10)
b.append(10**10)

waA = [a[0]]
for i in range(1, n + 1):
    waA.append(waA[-1] + a[i])

waB = [b[0]]
for j in range(1, m + 1):
    waB.append(waB[-1] + b[j])

j = 0
mx = 0
for i in reversed(range(n)):
    while waA[i] + waB[j] <= k or j == m - 1:
        if mx < (i + 1) + (j + 1):
            mx = (i + 1) + (j + 1)
        j += 1

print(mx)

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=0
while t<=k:
  if a<=n-1 and b<=m-1:
    if A[a]<B[b]:
      t+=A[a]
      a+=1
    elif A[a]>B[b]:
      t+=B[b]
      b+=1
    else:
      for d in range(1,10**9):
        if a+d<=n-1 and b+d<=m-1:
          if A[a+d]==B[b+d]:
            continue
          elif A[a+d]>B[b+d]:
            for _ in range(d):
              if t<=k:
                t+=B[b]
                b+=1
              else:
                break
            break
          elif A[a+d]<B[b+d]:
            for _ in range(d):
              if t<=k:
                t+=A[a]
                a+=1
              else:
                break
            break    
        elif a+d==n:
          for _ in range(d):
            if t<=k:
              t+=B[b]
              b+=1
              break
        elif b+d==m:
          for _ in range(d):
            if t<=k:
              t+=A[a]
              a+=1
              break
  elif a>=n and b<=m-1:
    t+=B[b]
    b+=1
  elif b>=m and a<=n-1:
    t+=A[a]
    a+=1
  else:
    print(n+m)
    exit()
print(a+b-1)

Submission status: Wrong Answer

Solution code:
NMK = list(map(int, input().split()))

Asum = []
Bsum = []

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

sum = 0
for i in range(NMK[0]):
    sum += A[i]
    Asum.append(sum)

sum = 0
for i in range(NMK[1]):
    sum += B[i]
    Bsum.append(sum)

cutA = 0
max = NMK[2]
indexA = 0
while(True):
    cutA = Asum[indexA]
    if (max < cutA):
        break
    indexA += 1
    if (indexA == NMK[0]):
        break
if (indexA == 0):
    maxA = 0
else:
    maxA = Asum[indexA - 1]

cutB = 0
indexB = 0
while(True):
    cutB = Bsum[indexB]
    if (max < cutB):
        break
    indexB += 1
    if (indexB == NMK[1]):
        break
if (indexB == 0):
    maxB = 0
else:
    maxB = Bsum[indexB - 1]


def returnAnswer(max, min, Marray, marray):
    answer = 0
    remain = 0
    maxAnswer = 0
    max = max if max < 100 else 100
    for i in range(max):
        answer = max - i
        index = 0
        remain = NMK[2] - Marray[max - i - 1]
        while (True):
            if (remain >= marray[index]):
                answer += 1
                index += 1
                if (index == min):
                    break
            else:
                break

        if (maxAnswer < answer):
            maxAnswer = answer
    return maxAnswer

if (indexA > indexB):
    if (indexA == 0):
        print(0)
        exit()
    print(returnAnswer(indexA, indexB, Asum, Bsum))
else:
    if (indexB == 0):
        print(0)
        exit()
    print(returnAnswer(indexB, indexA, Bsum, Asum))

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
ia = 0
ib = 0

while time <= k:
    if ia >= len(a) and ib >= len(b):
        break
    elif ia >= len(a):
        if time + b[ib] > k:
            break
        time += b[ib]
        ib += 1
    elif ib >= len(b):
        if time + a[ia] > k:
            break
        time += a[ia]
        ia += 1
    elif a[ia] <= b[ib]:
        time += a[ia]
        ia += 1
    else:
        time += b[ib]
        ib += 1

if time > k:
    print(ia + ib - 1)
else:
    print(ia + ib)

Submission status: Wrong Answer

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

from bisect import bisect_left, bisect_right

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    for i in range(1,N):
        A[i]+=A[i-1]
    for i in range(1,M):
        B[i]+=B[i-1]
    ret = 0
    for i in range(N):
        if A[i]<=K:
            l = bisect_right(B, K-A[i])    # 5が入るべき境目のうち最も右側の境目を返す
            ret = max(ret,i+l+1)
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#create date: 2020-06-27 22:08

import sys
stdin = sys.stdin
from itertools import accumulate
from bisect import bisect_left, bisect_right

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, k = na()
    a = na()
    b = na()
    i1, i2 = 0, 0
    c = list()
    for i in range(n+m):
        if i1 == n:
            c.append(a[i2])
        elif i2 == m:
            c.append(a[i1])

        elif a[i1] <= a[i2]:
            c.append(a[i1])
            i1 += 1
        else:
            c.append(a[i2])
            i2 += 1
    cum = list(accumulate(c))
    #print(cum)

    print(bisect_right(cum, k))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

A.append(10**10)
B.append(10**10)
i,j = 0,0
for k in range(N+M):
    if A[i] <= B[j]:
        K -= A[i]
        i += 1
    else:
        K -= B[j]
        j += 1
    if K < 0:
        break
    result += 1
print(result)

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
t = 0
c = 0
while 1 == 1:
    if i == n and j == m:
        break
    elif j == m:
        t = t + a[i]
        if t > k:
            break
        c = c + 1
        i = i + 1
    elif i == n:
        t = t + b[j]
        if t > k:
            break
        c = c + 1
        j = j + 1
    elif a[i] <= b[j]:
        t = t + a[i]
        if t > k:
            break
        c = c + 1
        i = i + 1
    elif b[j] < a[i]:
        t = t + b[j]
        if t > k:
            break
        c = c + 1
        j = j + 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()))
count = 0
if sum(a) + sum(b) <= k:
  print(n+m)
  exit()

while k >= 0:
  if not a:
    beta = b[0]
    k = k - beta
    count = count + 1
    b.pop(0)
    continue
  elif not b:
    alpha = a[0]
    k = k - alpha
    count = count + 1
    a.pop(0)
    continue
  else:
    alpha = a[0]
    beta = b[0]  
    if alpha >= beta:
      k = k - beta
      count += 1
      b.pop(0)
    elif beta > alpha:
      k = k - alpha
      count += 1
      a.pop(0)

print(count-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]
nn = n
mm = m
for i in range(1,n):
  suma[i] = suma[i - 1] + a[i]
  if suma[i] > 10**9:
    nn = i
    break
for i in range(1,m):
  sumb[i] = sumb[i - 1] + b[i]
  if sumb[i] > 10**9:
    mm = i
    break

c = 0
t = 0
cc = 0
for i in range(nn):
  if suma[i] <= k:
    t = suma[i]
    c = i + 1
  for j in range(mm):
    tt = t + sumb[j]
    if tt <= k:
      cc = max(cc,c + j + 1)

print(cc)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, rest = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))

book_counter = 0
read_time = 0

a_top = a.popleft()
b_top = b.popleft()

max_num = 1e10

while rest > 0:
    if a_top <= b_top:
        if (rest - a_top) >= 0:
            rest -= a_top
            book_counter += 1
            a_top = a.popleft() if a else max_num
        else:
            break
    elif a_top == b_top == max_num:
        break
    elif b_top < a_top:
        if (rest - b_top) >= 0:
            rest -= b_top
            book_counter += 1
            b_top = b.popleft() if b else max_num
        else:
            break
print(book_counter)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = []
b= []
a= list(map(int, input().split()))
b= list(map(int, input().split()))
a.append(10**10)
b.append(10**10)
t = 0
i = 0
while t<=k:
    t = t + min(a[0],b[0])
    if a[0]==min(a[0], b[0]):
        a.remove(min(a[0], b[0]))
    else:
        b.remove(min(a[0],b[0]))
    if t >k:
        break
    i = i +1
print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque


d=deque()
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.reverse()
for i in range(len(A)):d.append(A[i])
for i in range(len(B)):d.append(B[i])

sum_time=0
count=0

while True:
    try:
        rigth=d.pop()
        left=d.popleft()
    except:
        sum_time+=rigth
        if sum_time<=K:count+=1
        else:pass
    
    if sum_time+rigth<sum_time+left:
        sum_time+=rigth
        if sum_time<=K:count+=1
        else:break
        d.append(left)
    else:
        sum_time+=left
        if sum_time<=K:count+=1
        else:break
        d.append(rigth)

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

sumA, sumB = [], []
sa, sb = 0, 0
for a in A:
    sa += a
    sumA.append(sa)
for b in B:
    sb += b
    sumB.append(sb)

ma, mb = 0, 0
k = 0
n = 0
ia = 0
ib = 0
na = N
nb = M
while k <= K and (na or nb):
    if na:
        kA = sumA[ia] - ma
        if k + kA > K:
            na = 0
    if nb:
        kB = sumB[ib] - mb
        if k + kB > K:
            nb = 0

    if na and nb:
        kA = sumA[ia] - ma
        kB = sumB[ib] - mb
        if kA < kB:
            nA = 1
            while ia+1 < N:
                tA = sumA[ia+1] - ma
                if tA <= kB and k + tA <= K:
                    kA = tA
                    ia += 1
                    nA += 1
                else:
                    break
            n += nA
            k += kA
            ma = sumA[ia]
            na -= nA
            ia += 1
        else:
            nB = 1
            while ib+1 < M:
                tB = sumB[ib+1] - mb
                if kA >= tB and k + tB <= K:
                    kB = tB
                    ib += 1
                    nB += 1
                else:
                    break
            n += nB
            k += kB
            mb = sumB[ib]
            nb -= nB
            ib += 1
    elif na:
        while ia < N and k + A[ia] <= K:
            n += 1
            k += A[ia]
            ia += 1
            na -= 1
    elif nb:
        while ib < M and k + B[ib] <= K:
            n += 1
            k += B[ib]
            ib += 1
            nb -= 1
print(n)

Submission status: Wrong Answer

Solution code:
gen_input = list(map(int, input().split()))
time_a = list(map(int, input().split()))
time_b = list(map(int, input().split()))

length_a = gen_input[0]
length_b = gen_input[1]
time_const = gen_input[2]

if sum(time_a) + sum(time_b) == time_const:
    print(length_a + length_b)
elif time_const < min(time_a[0], time_b[0]):
    print(0)
elif time_const == min(time_a[0], time_b[0]):
    print(1)

else:
    num_read_books = 0
    i = 0
    j = 0
    while True:
        print(i, j)
        if (i < length_a) & (j < length_b):
            if time_a[i] >= time_b[j]:
                time_const -= time_b[j]
                j += 1
            else:
                time_const -= time_a[i]
                i += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break
        
        elif (i == length_a) & (j < length_b):
            time_const -= time_b[j]
            j += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break

        elif (i < length_a) & (j == length_b):
            time_const -= time_a[i]
            i += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break
        else:
            break
    print(num_read_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()))
ctr = 0
T = 0
while T <= K:
  try:
    k = min(A[0], B[0])
    if k == A[0]:
      A.remove(A[0])
    else:
      B.remove(B[0])
  except IndexError:
      if A == [] and B != []:
          k = B[0]
          B.remove(B[0])
      elif B == [] and A != []:
          k = A[0]
          A.remove(A[0])
  T += k
  if T <= K:
    ctr += 1
print(ctr)

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
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
tmp_ans = ans
for i in range(A_idx - 1, -1, -1):
    nowK += A[i]
    tmp_ans -= 1
    for j in range(B_idx, M):
        if nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
    if j == M - 1:
        B_idx = M
    else:
        B_idx = j
    ans = max(tmp_ans, ans)
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()))

a = 0
b = 0
t_sum = 0
ans = 0


while True:
    if a < N and b < M:
        if A[a] <= B[b]:
            t_sum += A[a]
            a += 1
        else:
            t_sum += B[b]
            b += 1
    elif a >= N and b >= M:
        break
    elif a >= N:
        t_sum += B[b]
        b += 1
    elif b >= M:
        t_sum += A[a]
        a += 1
    print(a,b)
    print(t_sum)
    if t_sum > K:
        break
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = (int(x) for x in input().split())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
book = [[-1 for _ in range(N+1)] for _ in range(M+1)]
book[0][0] = 0
ans = 0
num = 10**9 + 1
for i in range(len(A)):
    book[0][i+1] = book[0][i] + A[i]
    if K < book[0][i+1]:
        ans = i
        num = i
        break
if num == 10**9 + 1:
    num = len(A)
for i in range(len(B)):
    for j in range(0,num+1):
        book[i+1][j] = book[i][j] + B[i]
        if K >= book[i+1][j]:
            num = j
            if ans < i + j + 1:
                ans = i + j + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ia, ib = 0, 0
t = 0
cnt = 0
INF = 9876543210
 
while True:
    if a[ia] > b[ib]:
        if t + b[ib] > k:
            break
        t += b[ib]
        if ib+1 < m:
            ib += 1
        else:
            b[ib] = INF
 
    elif a[ia] < b[ib]:
        if t + a[ia] > k:
            break
        t += a[ia]
        if ia+1 < n:
            ia += 1
        else:
            a[ia] = INF
    
    elif a[ia] == b[ib]:
        if ib+1 <= m-1 and ia+1 <= n-1:
            if a[ia+1] >= b[ib+1]:
                t += b[ib]
                ib += 1
            else:
                t += a[ia]
                ia += 1
        elif ib+1 <= m-1:
            t += b[ib]
            ib += 1
        elif ia+1 <= n-1:
            t += a[ia]
            ia += 1
        elif ib+1 == m and ia+1 == n:
            t += a[ia]
            a[ia] = INF

    if t > k:
        break

    cnt += 1
 
    if cnt == n+m:
        break
 
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = deque(list(map(int, input().split())))
    B = deque(list(map(int, input().split())))
    
    cost = K
    count = 0
    while True:
        if len(A) ==0 and len(B) == 0:
            break
        elif len(A) == 0:
            b = B[0]
            if cost -b < 0:
                break
            cost -= B.popleft()
        elif len(B) == 0:
            a = A[0]
            if cost -a < 0:
                break
            cost -= A.popleft()

        else:
            a = A[0] 
            b = B[0] 
            if a < b:
                if cost -a < 0:
                    break
                cost -= A.popleft()
            else:
                if cost -b < 0:
                    break
                cost -= B.popleft()

        count += 1
    
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,M,K= map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.insert(0,0)
ans = 0
for n in range(N+1):
    t = K - sum(A[:n+1])
    book = n
    if t < A[n]:
        break
    else:
        for m in range(M):
            if t >= B[m]:
                t -= B[m]
                book += 1
            else:
                if ans < book:
                    ans = book
                break
        if ans < book:
            ans = book
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
d=0
c=0
t=0
while(d<=k):
    if(k==0):
        print(0)
    elif(i<len(a) and j<len(b)):
        if(a[i]<b[j]):
                d=d+a[i]
                i=i+1
                c=c+1
        else:
            d=d+b[j]
            j=j+1
            c=c+1
    else:
        if(i>len(a) and j<len(b)):
            d=d+b[j]
            c=c+1
        elif(i<len(a) and j>len(b)):
            d=d+a[i]
            c=c+1
        else:
            t=t+1
            print(c)
            break
if(t==0):
    print(c-1)

Submission status: Wrong Answer

Solution code:
#C
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
books = 0
timer = 0
#全部読む必要があるなら全部読んで終わる
if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
#入力例３対策
elif min(A) > K and min(B) > K:
    print(0)
else:
    while timer <= K and (len(A)>0 or len(B)> 0):
        if len(A) == 0 and len(B) != 0:
            books += 1
            timer += B[0]
            B = B[1:]
        elif len(A) != 0 and len(B) == 0:
            books += 1
            timer += A[0]
            A = A[1:]
        elif  A[0] > B[0]:
            books += 1
            timer += B[0]
            B = B[1:]
        elif B[0] > A[0]:
            books += 1
            timer += A[0]
            A = A[1:]
        else:
            #A[0]=B[0]
            tmp = A[0]
            books += 1
            timer += A[0]
            books += 1
            timer += B[0]
            A = A[1:]
            B = B[1:]
    print(books-1)

Submission status: Wrong Answer

Solution code:
N ,M ,K = map(int, input().split())
#K = int(K/10)
#print(K)

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

m = 0

for i in range(1, N+1):
    total = A[:i]
    total = sum(total)
    if total > K:
        break
    mi = i
    for j in range(M):
        total += B[j]
        if total > K:
            break
        #print(total)
        mi += 1

    m = max(m, mi)


print(m)