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

aa = []
for i in range(len(a)):
    if i == 0:
        aa.append(a[i])
    else:
        aa.append(a[i] + aa[i-1])
bb = []
for i in range(len(b)):
    if i == 0:
        bb.append(b[i])
    else:
        bb.append(b[i] + bb[i-1])

total_time = 0
total_book = 0
tmp_total_book = 0
tmp_total_time = 0
flg = False
j_tmp = len(bb)
for i in range(len(aa)):
    tmp_total_book = 0
    tmp_total_time = 0
    if flg:
        break
    if aa[i] > k:
        flg = True
    else:
        tmp_total_time = aa[i]
        tmp_total_book = i + 1
    for j in reversed(range(0, j_tmp)):
        if tmp_total_time + bb[j] > k:
            continue
        else:
            tmp_total_book += j+1
            j_tmp = j + 1
            break

    if tmp_total_book > total_book:
        total_book = tmp_total_book

print(total_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(' ')))

aa = []
for i in range(len(a)):
    if i == 0:
        aa.append(a[i])
    else:
        aa.append(a[i] + aa[i-1])
bb = []
for i in range(len(b)):
    if i == 0:
        bb.append(b[i])
    else:
        bb.append(b[i] + bb[i-1])

total_time = 0
total_book = 0
tmp_total_book = 0
tmp_total_time = 0
flg = False
j_tmp = len(bb)
for i in range(len(aa)):
    tmp_total_book = 0
    tmp_total_time = 0
    if flg:
        break
    if aa[i] >= k:
        flg = True
    else:
        tmp_total_time = aa[i]
        tmp_total_book = i + 1
    for j in reversed(range(0, j_tmp)):
        if tmp_total_time + bb[j] >= k:
            continue
        else:
            tmp_total_book += j+1
            j_tmp = j + 1
            break

    if tmp_total_book > total_book:
        total_book = tmp_total_book

print(total_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(' ')))

aa = []
for i in range(len(a)):
    if i == 0:
        aa.append(a[i])
    else:
        aa.append(a[i] + aa[i-1])
bb = []
for i in range(len(b)):
    if i == 0:
        bb.append(b[i])
    else:
        bb.append(b[i] + bb[i-1])

total_time = 0
total_book = 0
tmp_total_book = 0
tmp_total_time = 0
flg = False
j_tmp = len(bb)
for i in range(len(aa)):
    tmp_total_book = 0
    tmp_total_time = 0
    if flg:
        break
    if aa[i] >= k:
        flg = True
    else:
        tmp_total_time = aa[i]
        tmp_total_book = i + 1
    for j in reversed(range(0, j_tmp)):
        if tmp_total_time + bb[j] >= k:
            continue
        else:
            tmp_total_book += j+1
            j_tmp = j
            break

    if tmp_total_book > total_book:
        total_book = tmp_total_book

print(total_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(' ')))

aa = []
for i in range(len(a)):
    if i == 0:
        aa.append(a[i])
    else:
        aa.append(a[i] + aa[i-1])
bb = []
for i in range(len(b)):
    if i == 0:
        bb.append(b[i])
    else:
        bb.append(b[i] + bb[i-1])

total_time = 0
total_book = 0
tmp_total_book = 0
tmp_total_time = 0
flg = False
for i in range(len(aa)):
    tmp_total_book = 0
    tmp_total_time = 0
    if flg:
        break
    if aa[i] >= k:
        flg = True
    else:
        tmp_total_time = aa[i]
        tmp_total_book = i + 1
    for j in reversed(range(len(bb))):
        if tmp_total_time + bb[j] >= k:
            continue
        else:
            tmp_total_book += j+1
            break

    if tmp_total_book > total_book:
        total_book = tmp_total_book

print(total_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(' ')))

aa = []
for i in range(len(a)):
    if i == 0:
        aa.append(a[i])
    else:
        aa.append(a[i] + aa[i-1])
bb = []
for i in range(len(b)):
    if i == 0:
        bb.append(b[i])
    else:
        bb.append(b[i] + bb[i-1])

total_time = 0
total_book = 0
tmp_total_book = 0
tmp_total_time = 0
flg = False
for i in range(len(aa)):
    tmp_total_book = 0
    tmp_total_time = 0
    if flg:
        break
    if aa[i] >= k:
        flg = True
    else:
        tmp_total_time = aa[i]
        tmp_total_book = i + 1

    for j in range(len(bb)):
        if tmp_total_time + bb[j] < k:
            tmp_total_book += 1
        else:
            break
    if tmp_total_book > total_book:
        total_book = tmp_total_book




print(total_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(' ')))

aa = []
for i in range(len(a)):
    if i == 0:
        aa.append(a[i])
    else:
        aa.append(a[i] + aa[i-1])
bb = []
for i in range(len(b)):
    if i == 0:
        bb.append(b[i])
    else:
        bb.append(b[i] + bb[i-1])

total_time = 0
total_book = 0
tmp_total_book = 0
tmp_total_time = 0
flg = False
print(aa)
print(bb)
for i in range(len(aa)):
    tmp_total_book = 0
    tmp_total_time = 0
    if flg:
        break
    if aa[i] >= k:
        flg = True
    else:
        tmp_total_time = aa[i]
        tmp_total_book = i + 1

    for j in range(len(bb)):
        print(i,j,aa[i],bb[j],tmp_total_time,tmp_total_time, tmp_total_book)
        if tmp_total_time + bb[j] < k:
            tmp_total_book += 1
        else:
            break
    if tmp_total_book > total_book:
        total_book = tmp_total_book




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

max_num = 0
j = 0
j_max = M + 1
A_sums=[sum(A[:i]) for i in range(N+1)]
B_sums=[sum(B[:i]) for i in range(M+1)]

for i in range(N + 1):
    j = 0
    while j < j_max:
        print(i, j)
        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_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()))

a, b = [0], [0]

for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
 if a[i] > K:
  break
 while b[j] > K - a[i]:
  j -= 1
ans = max(ans, i + j)

print(ans)

Submission status: Wrong Answer

Solution code:
lst = input().split()

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

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

for i in range(N):
   A[i] = int(A[i])

for i in range(M):
   B[i] = int(B[i])

time = 0
count = 0

for i in range(N + M):
   if time <= K:
      if A != [] and B != []:
         if A[0] <= B[0] and time + A[0] <= K:
            time = time + A[0]
            count = count + 1
            A.pop(0)
         elif time + B[0] <= K:
            time = time + B[0]
            count = count + 1
            B.pop(0)
      elif A != [] and B == []:
         if time + A[0] <= K:
            time = time + A[0]
            count = count + 1
            A.pop(0)
      elif A == [] and B != []:
         if time + B[0] <= K:
            time = time + B[0]
            count = count + 1
            B.pop(0)
      else:
         break
   else:
      break

print(count)

Submission status: Wrong Answer

Solution code:
import sys

input = [int(x) for x in sys.stdin.readline().split()]
n = input[0]
m = input[1]
k = input[2]

a = [int(x) for x in sys.stdin.readline().split()]
b = [int(x) for x in sys.stdin.readline().split()]

bool = True
cnt = 0
#while bool:
for _ in range(len(a) + len(b)):
    if((len(a) > 0) & (len(b) > 0)):
        if(a[0] > b[0]):
            if(k - b[0] >= 0):
                k -= b.pop(0)
                cnt += 1
            else:
                break
        else:
            if(k - a[0] >= 0):
                k -= a.pop(0)
                cnt += 1
            else:
                break
    elif(len(a) > 0):
        if(k - a[0] >= 0):
            k -= a.pop(0)
            cnt += 1
        else:
            break
    elif(len(b) > 0):
        if(k - b[0] >= 0):
            k -= b.pop(0)
            cnt += 1
        else:
            break
    else:
        break

print(cnt)

Submission status: Wrong Answer

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

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

aa = []
for i in range(len(a)):
    if i == 0:
        aa.append(a[i])
    else:
        aa.append(a[i] + aa[i-1])
bb = []
for i in range(len(b)):
    if i == 0:
        bb.append(b[i])
    else:
        bb.append(b[i] + bb[i-1])

total_time = 0
total_book = 0
tmp_total_book = 0
tmp_total_time = 0
flg = False
for i in range(len(aa)):
    if flg:
        break
    tmp_total_time = 0
    tmp_total_book = 0
    if tmp_total_time + aa[i] < k:
        tmp_total_time += aa[i]
        tmp_total_book += 1
    else:
        flg = True

    for j in range(len(bb)):
        if tmp_total_time + bb[j] < k:
            tmp_total_time += bb[j]
            tmp_total_book += 1
        else:
            break
    if tmp_total_book > total_book:
        total_book = tmp_total_book


print(total_book)

Submission status: Wrong Answer

Solution code:
import sys

input = [int(x) for x in sys.stdin.readline().split()]
n = input[0]
m = input[1]
k = input[2]

a = [int(x) for x in sys.stdin.readline().split()]
b = [int(x) for x in sys.stdin.readline().split()]

bool = True
cnt = 0
while bool:
    if((len(a) > 0) & (len(b) > 0)):
        if(a[0] > b[0]):
            if(k - b[0] >= 0):
                k -= b.pop(0)
                cnt += 1
            else:
                bool = False
        else:
            if(k - a[0] >= 0):
                k -= a.pop(0)
                cnt += 1
            else:
                bool = False
    elif(len(a) > 0):
        if(k - a[0] >= 0):
            k -= a.pop(0)
            cnt += 1
        else:
            bool = False
    elif(len(b) > 0):
        if(k - b[0] >= 0):
            k -= b.pop(0)
            cnt += 1
        else:
            bool = False
    else:
        bool = False

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

N , M , K = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
a.insert(0,0)

ans = 0
for i in range(N + 1):
    if a[i] > K:
        break
    ans = max(ans , bisect.bisect_right(b, K - a[i]))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
inp = input()
n, m, k = inp.split(' ')
a_inp = input()
aa = a_inp.split(' ')
b_inp = input()
bb = b_inp.split(' ')
a = []
for n in aa:
    if n.isdecimal():
        a.append(int(n))

b = []
for n in bb:
    if n.isdecimal():
        b.append(int(n))

total_book = 0
total_time = 0
tmp_total = 0

c = b.copy() if len(a) > len(b) else a.copy()

i = 0
while True:
    if a[0] < b[0]:
        total_time += a[0]
        a.pop(0)
    else:
        total_time += b[0]
        b.pop(0)

    if total_time >= int(k):
        break
    else:
        total_book += 1
    if len(a) == 0 or len(b) == 0:
        break
    i += 1


c = b.copy() if len(a) == 0 else a.copy()

if total_time > int(k):
    print(total_book)
    exit()

for i in range(len(c)):
    total_time += c[i]
    if total_time >= int(k):
        break
    else:
        total_book += 1


print(total_book)

Submission status: Wrong Answer

Solution code:
inp = input()
n, m, k = inp.split(' ')
a_inp = input()
a = a_inp.split(' ')
b_inp = input()
b = b_inp.split(' ')

a = [int(n) for n in a]
b = [int(n) for n in b]

total_book = 0
total_time = 0
tmp_total = 0

c = b.copy() if len(a) > len(b) else a.copy()

i = 0
while True:
    if a[0] < b[0]:
        total_time += a[0]
        a.pop(0)
    else:
        total_time += b[0]
        b.pop(0)

    if total_time >= int(k):
        break
    else:
        total_book += 1
    if len(a) == 0 or len(b) == 0:
        break
    i += 1


c = b.copy() if len(a) == 0 else a.copy()

if total_time > int(k):
    print(total_book)
    exit()

for i in range(len(c)):
    total_time += c[i]
    if total_time >= int(k):
        break
    else:
        total_book += 1


print(total_book)

Submission status: Wrong Answer

Solution code:
inp = input()
n, m, k = inp.split(' ')
a_inp = input()
a = a_inp.split(' ')
b_inp = input()
b = b_inp.split(' ')

a.extend(b)
a = [int(n) for n in a]
a.sort()
total = 0
tmp_total = 0
for key, v in enumerate(a):
    vv = int(v)
    if tmp_total+vv < int(k):
        total += 1
        tmp_total = total
    else:
        break

print(total)

Submission status: Wrong Answer

Solution code:
inp = input()
n, m, k = inp.split(' ')
a_inp = input()
a = a_inp.split(' ')
b_inp = input()
b = b_inp.split(' ')

a.extend(b)
a.sort()
total = 0
tmp_total = 0
for key, v in enumerate(a):
    vv = int(v)
    if (tmp_total+vv < int(k)):
        total += 1
        tmp_total = total
    else:
        break

print(total)

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(k + 1)
b.append(k + 1)
ia = 0
ib = 0
count = 0

for i in range(n + m + 1):
    if a[ia] < b[ib]:
        if a[ia] > k:
            print(count)
            break
        else:
            k -= a[ia]
            ia += 1
            count += 1
    else:
        if b[ib] > k:
            print(count)
            break
        else:
            k -= b[ib]
            ib += 1
            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()))
a.append(k+1)
b.append(k+1)
ia = 0
ib = 0
count = 0
 
for i in range(n + m + 1):
    if (a[ia] < b[ib]):
        if(a[ia] > k):
            print(count)
            break
        else:
            k -= a[ia]
            ia += 1
            count += 1
    else:
        if(b[ib] > k):
            print(count)
            break
        else:
            k -= b[ib]
            ib += 1
            count += 1

Submission status: Wrong Answer

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

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

a_accum = [0] * (N+1)
b_accum = [0] * (M+1)

for i in range(len(A)):
    a_accum[i+1] = a_accum[i] + A[i]

for j in range(len(B)):
    b_accum[j+1] = b_accum[j] + B[j]


ans = 0
for j in range(len(a_accum)):
    time_left = K - a_accum[j]
    if time_left < 0:
        continue

    left = -1
    right = len(b_accum) - 1
    mid = 0

    while left < right:
        mid = (left + right) // 2

        if b_accum[mid] == time_left:
            print(max(ans, j+left))
            sys.exit()

        if b_accum[mid] < time_left:
            left = mid + 1
        else:
            right = mid - 1
    ans = max(ans, j+left)

print(ans)

Submission status: Wrong Answer

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

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

a_accum = [0] * (N+1)
b_accum = [0] * (M+1)

for i in range(len(A)):
    a_accum[i+1] = a_accum[i] + A[i]

for j in range(len(B)):
    b_accum[j+1] = b_accum[j] + B[j]


ans = 0
for j in range(len(a_accum)):
    time_left = K - a_accum[j]
    if time_left < 0:
        continue

    left = 0
    right = len(b_accum) - 1
    mid = 0

    while left < right:
        mid = (left + right) // 2

        if b_accum[mid] == time_left:
            break

        if b_accum[mid] < time_left:
            left = mid + 1
        else:
            right = mid - 1
    ans = max(ans, j+left)
    #print(j, left, right)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
INF = 10 ** 9 + 1000

while k > 0:
    if a[0] < b[0]:
        k -= a[0]
        a.pop(0)
    elif a[0] >= b[0]:
        k -= b[0]
        b.pop(0)

    if k >= 0:
        ans += 1

    if len(a) == 0:
        a.append(INF)
    if len(b) == 0:
        b.append(INF)

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
while K > 0:
    if len(A) == 0 and len(B) == 0:
        break

    elif len(A) == 0:
        K -= B[0]
        if K < 0:
            break
        B.pop(0)

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

Submission status: Wrong Answer

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

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

total = 0
c = 0
while total <= k:
    c += 1
    if len(A) > 0 and len(B) > 0:
        if A[0] > B[0]:
            total += B.pop(0)
        else:
            total += A.pop(0)
    elif len(A) == 0 and len(B) > 0:
        total += B.pop(0)
    elif len(B) == 0 and len(A) > 0:
        total += A.pop(0)
    else:
        break

print(c-1)

Submission status: Wrong Answer

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

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

time = 0
a_index, b_index = 0, 0
num = 0
while time <= K:
    if a_index == len(A) and b_index == len(B):
        print(num)
        sys.exit()

    elif a_index == len(A) and b_index < len(B): #Aがもうない場合
        time += B[b_index]
        num += 1
        b_index += 1
    elif a_index < len(A) and b_index == len(B):
        time += A[a_index]
        num += 1
        a_index += 1
    else:
        if A[a_index] <= B[b_index]:
            time += A[a_index]
            num += 1
            a_index += 1
        else:
            time += B[b_index]
            num += 1
            b_index += 1


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

time = 0
a_index, b_index = 0, 0
num = 0
while time <= K:
    now_added = 0
    if A[a_index] <= B[b_index]:
        if time + A[a_index] > K:
            break
        time += A[a_index]
        num += 1
        a_index += 1 if a_index < len(A)-1 else 0

    elif B[b_index] < A[a_index]:
        if time + B[b_index] > K:
            break
        time += B[b_index]
        num += 1
        b_index += 1 if b_index < len(B) - 1 else 0

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

# A.sort()
# B.sort()

ai=bi=0
sum=0
for i in range(n+m+1):
    if ai>n-1 :
        sum+=B[bi]
        bi+=1
    elif bi>m-1 :
        sum+=A[ai]
        ai+=1
    elif A[ai]>B[bi]:
        sum+=B[bi]
        bi+=1
    else:
        sum+=A[ai]
        ai+=1
    # print(ai, bi, sum)
    if sum>k :
        break
    if ai+bi>=n+m:
        ai+=1
        break
 
ans = ai+bi-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.sort()
B.sort()

ai=bi=0
sum=0
for i in range(n+m+1):
    if ai+bi==n+m:
        ai+=1
        break
    if ai>n-1 :
        sum+=B[bi]
        bi+=1
    elif bi>m-1 :
        sum+=A[ai]
        ai+=1
    elif A[ai]>B[bi]:
        sum+=B[bi]
        bi+=1
    else:
        sum+=A[ai]
        ai+=1
    # print(ai, bi, sum)
    if sum>k :
        break 
ans = ai+bi-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.sort()
B.sort()

ai=bi=0
sum=0
for i in range(n+m):
    if ai+bi==n+m:
        break
    if ai>n-1 :
        sum+=B[bi]
        bi+=1
    elif bi>m-1 :
        sum+=A[ai]
        ai+=1
    elif A[ai]>B[bi]:
        sum+=B[bi]
        bi+=1
    else:
        sum+=A[ai]
        ai+=1
    # print(ai, bi, sum)
    if sum>k :
        break 
ans = ai+bi-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()))
cnt=0
while cnt!=n+m:
  if len(B)==0:
    k-=A[0]
    del A[0]
    cnt+=1
  elif len(A)==0:
    k-=B[0]
    del B[0]
    cnt+=1
  elif A[0]<=B[0] and k>A[0]:
    k-=A[0]
    del A[0]
    cnt+=1
  elif B[0]<A[0] and k>B[0]:
    k-=B[0]
    del B[0]
    cnt+=1
  else:
    break
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cnt=0
while len(A)!=0 or len(B)!=0:
  if len(B)==0:
    k-=A[0]
    del A[0]
    cnt+=1
  elif len(A)==0:
    k-=B[0]
    del B[0]
    cnt+=1
  elif A[0]<=B[0] and k>A[0]:
    k-=A[0]
    del A[0]
    cnt+=1
  elif B[0]<A[0] and k>B[0]:
    k-=B[0]
    del B[0]
    cnt+=1
  else:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
book_list = list(map(int,input().split()))
book_list.extend(list(map(int,input().split())))
book_list.sort()
count=0
readTime=0
for i in range(n+m):
    if readTime+book_list[i]<=k:
        count+=1
        readTime+=book_list[i]
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a_table = list(map(int,input().split()))
b_table = list(map(int,input().split()))
a_table.extend(b_table)
a_table.sort()
count=0
readTime=0
for i in range(n+m):
    if readTime+a_table[0]<=k:
        count+=1
        del a_table[0]
    else:
        break
print(count)

Submission status: Wrong Answer

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_sum = []
b_sum = []
sm = cnt = 0
for a in A:
    sm += a
    if sm > K:
        break
    cnt += 1
    a_sum.append(sm)
sm = cnt = 0
for b in B:
    sm += b
    if sm > K:
        break
    cnt += 1
    b_sum.append(sm)
index_max = 0
a_size = len(a_sum)
for i in range(a_size):
    a_size = len(a_sum)
    b_index = bisect.bisect_right(b_sum, K - a_sum.pop())
    index_max = max(index_max, a_size + b_index)
    # print(a_size, b_index)
print(index_max)