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())
costA=list(map(int,input().split()))
costB=list(map(int,input().split()))
costA=[0]+costA
costB=[0]+costB

for i in range(N):
    costA[i+1]+=costA[i]
    
for i in range(M):
    costB[i+1]+=costB[i]

"""print(costA)
print(costB)"""



def upper_bound(list1,K):
    low=0
    high=len(list1) #index
    while high-low!=1:
        mid=(high+low)//2
        if list1[mid]>K:
            high=mid
        else:
            low=mid
    return low  #条件を満たす左側の要素数

number=[]
for i in range(N+1): #A側の机の本を固定 残りの時間でBを二分探索
    time=K-costA[i]
    if upper_bound(costB,time)!=1:
        number.append(i+upper_bound(costB,time)-1)
    else:
        number.append(0)
"""print(i)
    print(upper_bound(costB,time))
    print(number)"""
    
print(max(number))



"""
print(cumcost)
#以下二分探索 必要なのはソート済みリストと検索したい値
#upper bound 基準値よりも大きい最初の値を返す
#lower bound 基準値以上の最初の値を返す
#欲しい値はl基準値以下の最大値=upper bound値−１の位置の値
    #冊数は+1なので、求める値はupper_bound
# 検索したい値＝K分を超えない最大の値
low=0
high=len(cumcost)-1
while high-low!=1: #差が１になったら終了
    print(high)
    print(low)
    mid=(high+low)//2 #pythonの//は切り捨て徐算
    if cumcost[mid]>K:  #推測した値が大きすぎた ### 値のダブり注意
        high=mid
    else: # 推測した値小さすぎた#cumcost<=K
        low=mid 
#条件を満たす値の個数 (upper_bound)
    #条件を満たすのが左・・・high
    #条件を満たすのが右・・・len(cumcost)--1-low
upper_bound=high #最終的な値はupper_bound
print(upper_bound)
"""
"""境界線が端っこにあると上手に探索できない
→例外処理で乗り切るか　探索のやり方自体を変更するか　どちらが良いか？"""

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
costA=list(map(int,input().split()))
costB=list(map(int,input().split()))
costA=[0]+costA
costB=[0]+costB

for i in range(N):
    costA[i+1]+=costA[i]
    
for i in range(M):
    costB[i+1]+=costB[i]

"""print(costA)
print(costB)"""

costB.append(float("inf"))

def upper_bound(list1,K):
    low=0
    high=len(list1)-1 #index
    while high-low!=1:
        mid=(high+low)//2
        if list1[mid]>K:
            high=mid
        else:
            low=mid
    return high  #条件を満たす左側の要素数

number=[]
for i in range(N+1): #A側の机の本を固定 残りの時間でBを二分探索
    time=K-costA[i]
    if upper_bound(costB,time)!=1:
        number.append(i+upper_bound(costB,time)-1)
    else:
        number.append(0)
"""print(i)
    print(upper_bound(costB,time))
    print(number)"""
    
print(max(number))



"""
print(cumcost)
#以下二分探索 必要なのはソート済みリストと検索したい値
#upper bound 基準値よりも大きい最初の値を返す
#lower bound 基準値以上の最初の値を返す
#欲しい値はl基準値以下の最大値=upper bound値−１の位置の値
    #冊数は+1なので、求める値はupper_bound
# 検索したい値＝K分を超えない最大の値
low=0
high=len(cumcost)-1
while high-low!=1: #差が１になったら終了
    print(high)
    print(low)
    mid=(high+low)//2 #pythonの//は切り捨て徐算
    if cumcost[mid]>K:  #推測した値が大きすぎた ### 値のダブり注意
        high=mid
    else: # 推測した値小さすぎた#cumcost<=K
        low=mid 
#条件を満たす値の個数 (upper_bound)
    #条件を満たすのが左・・・high
    #条件を満たすのが右・・・len(cumcost)--1-low
upper_bound=high #最終的な値はupper_bound
print(upper_bound)
"""
"""境界線が端っこにあると上手に探索できない
→例外処理で乗り切るか　探索のやり方自体を変更するか　どちらが良いか？"""

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input("入力してください").split())
costA=list(map(int,input().split()))
costB=list(map(int,input().split()))
costA=[0]+costA
costB=[0]+costB

for i in range(N):
    costA[i+1]+=costA[i]
    
for i in range(M):
    costB[i+1]+=costB[i]

"""print(costA)
print(costB)"""

costB.append(float("inf"))

def upper_bound(list1,K):
    low=0
    high=len(list1)-1 #index
    while high-low!=1:
        mid=(high+low)//2
        if list1[mid]>K:
            high=mid
        else:
            low=mid
    return high  #条件を満たす左側の要素数

number=[]
for i in range(N+1): #A側の机の本を固定 残りの時間でBを二分探索
    time=K-costA[i]
    if upper_bound(costB,time)!=1:
        number.append(i+upper_bound(costB,time)-1)
    else:
        number.append(0)
"""print(i)
    print(upper_bound(costB,time))
    print(number)"""
    
print(max(number))



"""
print(cumcost)
#以下二分探索 必要なのはソート済みリストと検索したい値
#upper bound 基準値よりも大きい最初の値を返す
#lower bound 基準値以上の最初の値を返す
#欲しい値はl基準値以下の最大値=upper bound値−１の位置の値
    #冊数は+1なので、求める値はupper_bound
# 検索したい値＝K分を超えない最大の値
low=0
high=len(cumcost)-1
while high-low!=1: #差が１になったら終了
    print(high)
    print(low)
    mid=(high+low)//2 #pythonの//は切り捨て徐算
    if cumcost[mid]>K:  #推測した値が大きすぎた ### 値のダブり注意
        high=mid
    else: # 推測した値小さすぎた#cumcost<=K
        low=mid 
#条件を満たす値の個数 (upper_bound)
    #条件を満たすのが左・・・high
    #条件を満たすのが右・・・len(cumcost)--1-low
upper_bound=high #最終的な値はupper_bound
print(upper_bound)
"""
"""境界線が端っこにあると上手に探索できない
→例外処理で乗り切るか　探索のやり方自体を変更するか　どちらが良いか？"""

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

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

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

for i in range(N+1):
  T = a[i]
  if T<= K:
    ans = i
  else:
    pass

T = 0

for i in range(ans, N+1, 1):
  for j in range(M+1):
    T = a[i] + b[j]
    if T <= K:
      ans = max(ans, (i + j))
    else:
      pass


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
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()))
  sa = np.cumsum([0]+a)
  sb = np.cumsum([0]+b)
  print (sa,sb)
  exit()
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

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

calc_A = [0]
calc_B = [0]

for i in range(N):
    calc_A.append(calc_A[i] + A[i])

for j in range(M):
    calc_B.append(calc_B[j] + B[j])

ans = 0
j = M

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

print(ans)

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

waa=[0 for i in range(n)]
waa[0]=a[0]
wab=[0 for i in range(m)]
wab[0]=b[0]
for i in range(1,n):
  waa[i]=waa[i-1]+a[i]
for i in range(1,m):
  wab[i]=wab[i-1]+b[i]

ans=0
for i in range(n):
  idx=0
  if waa[i]>k:
    break
  idx=bisect.bisect_right(wab,k-waa[i])
  ans=max(ans,i+idx+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect
from itertools import accumulate


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    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))
    # print(a)
    # print(b)
    answer = 0
    for i in range(N):
        k_b = K - a[i]
        if k_b >= 0:
            b_read = bisect(b, k_b)
            # print(b_read)
            answer = max(i + b_read + 1, answer)
        else:
            continue

    print(answer)


if __name__ == "__main__":
    main()

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

waa=[0 for i in range(n)]
waa[0]=a[0]
wab=[0 for i in range(m)]
wab[0]=b[0]
for i in range(1,n):
  waa[i]=waa[i-1]+a[i]
for i in range(1,m):
  wab[i]=wab[i-1]+b[i]

ans=0
for i in range(n):
  idx=0
  if waa[i]>k:
    break
  idx=bisect.bisect_left(wab,k-waa[i])
  if idx<m and wab[idx]==k-waa[i]:
    idx+=1
  ans=max(ans,i+idx+1)
print(ans)

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

waa=[0 for i in range(n)]
waa[0]=a[0]
wab=[0 for i in range(m)]
wab[0]=b[0]
for i in range(1,n):
  waa[i]=waa[i-1]+a[i]
for i in range(1,m):
  wab[i]=wab[i-1]+b[i]

ans=0
for i in range(n):
  if waa[i]>k:
    break
  idx=bisect.bisect_left(wab,k-waa[i])
  if idx<m and wab[idx]==k-waa[i]:
    idx+=1
  ans=max(ans,i+idx+1)
print(ans)

Submission status: Wrong Answer

Solution code:
t1 = []
t2 = []
s1 = input().split(' ')
size1, size2, minutes = int(s1[0]),  int(s1[1]), int(s1[2])
s2 = input().split(' ')
for i in range(len(s2)):
  tmp = int(s2[i])
  if tmp > minutes:
    break
  else:
  	t1.append(tmp)

s3 = input().split(' ')
for i in range(len(s3)):
  tmp = int(s3[i])
  if tmp > minutes:
    break
  else:
  	t2.append(tmp)
   
ans = 0
time1 = 0
time2 = 0
f1 = False
f2 = False
while True:
  consume = 10**9
  if time1 == 0 and t1:
    time1 = t1[0]
  if time2 ==0 and t2:
    time2 = t2[0]
  if consume > time1 and time1 != 0:
    consume = time1
    f1 = True
  if consume > time2 and time2 != 0:
    consume = time2
    f1 = False
    f2 = True
  if minutes < consume:
    break
  if (f1 == True):
    t1.pop()
    minutes -= consume
    time1=0
    f1 =False
  elif (f2 == True):
    t2.pop()
    minutes -= consume
    time2 = 0
    f2 = False
  else:
    break
  ans +=1
  
print(ans)

Submission status: Wrong Answer

Solution code:
t1 = []
t2 = []
s1 = input().split(' ')
size1, size2, minutes = int(s1[0]),  int(s1[1]), int(s1[2])
s2 = input().split(' ')
for i in range(len(s2)):
  t1.append(int(s2[i]))

s3 = input().split(' ')
for i in range(len(s3)):
  t2.append(int(s3[i]))

ans = 0
time1 = 0
time2 = 0
f1 = False
f2 = False
while True:
  consume = 10**9
  if time1 == 0 and t1:
    time1 = t1[0]
  if time2 ==0 and t2:
    time2 = t2[0]
  if consume > time1 and time1 != 0:
    consume = time1
    f1 = True
  if consume > time2 and time2 != 0:
    consume = time2
    f1 = False
    f2 = True
  if minutes < consume:
    break
  if (f1 == True):
    t1.pop()
    minutes -= consume
    time1=0
    f1 =False
  elif (f2 == True):
    t2.pop()
    minutes -= consume
    time2 = 0
    f2 = False
  else:
    break
  ans +=1
  
print(ans)

Submission status: Wrong Answer

Solution code:
t1 = []
t2 = []
s1 = input().split(' ')
size1, size2, minutes = int(s1[0]),  int(s1[1]), int(s1[2])
s2 = input().split(' ')
for i in range(len(s2)):
  t1.append(int(s2[i]))

s3 = input().split(' ')
for i in range(len(s3)):
  t2.append(int(s3[i]))

ans = 0
time1 = 0
time2 = 0
while True:
  if time1 == 0 and t1:
    time1 = t1[0]
  if time2 ==0 and t2:
    time2 = t2[0]
  if time1 == 0 and time2 == 0:
    break
  
  
  if minutes < min(time1,time2) or minutes < max(time1,time2):
    break
  if (time1 == 0):
    if(time2 == 0):
      break
    else:
      t2.pop()
      minutes -= time2
      time2 = 0
  else:
    if(time2 == 0 or time2> time1):
      t1.pop()
      minutes -= time1
      time1=0
    else:
      t2.pop()
      minutes -= time2
      time2=0
  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()))
sa = [0] * (n+1)
sb = [0] * (m+1)
for i in range(n):
  sa[i+1] = sa[i] + a[i]
for i in range(m):
  sb[i+1] = sb[i] + b[i]
rx = 0
rb = m
for ra in range(0,n+1): 
  while (sb[rb] + sa[ra]) > k and rb>0 :
    rb-=1
  if rb==0: break
  rx = max(rx,ra+rb)
print(rx)

Submission status: Wrong Answer

Solution code:
class queue:
  data = []
  def __init__(self):
    self.data = []
  def push(self,data):
    self.data.append(data)
  def pop(self):
    return self.data.pop(0)
  def peek(self):
    return self.data[0]

t1 = queue()
t2 = queue()
s1 = input().split(' ')
size1, size2, minutes = int(s1[0]),  int(s1[1]), int(s1[2])
s2 = input().split(' ')
for i in range(len(s2)):
  t1.push(int(s2[i]))

s3 = input().split(' ')
for i in range(len(s3)):
  t2.push(int(s3[i]))

ans = 0
while True:
  time1 = 0
  time2 = 0
  if t1.data:
    time1 = t1.peek()
  if t2.data:
    time2 = t2.peek()
  if time1 == 0 and time2 == 0:
    break
  if minutes < min(time1,time2):
    break
  if time1 > time2:
    t1.pop()
    minutes -=time1
  elif time2> time1:
    t2.pop()
    minutes -=time2
  ans +=1
  
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import itertools
import bisect

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

sum_ = 0
count = 0
for i in range(len(a)):
    if (sum_+a[i]) >= k:
        break
    else:
        count += 1
        sum_ += a[i]
a_max = count

sum_ = 0
count = 0
for i in range(len(b)):
    if (sum_+b[i]) >= k:
        i = i-1
        break
    else:
        count += 1
        sum_ += b[i]
b_max = count


list_ = list(reversed(a[:a_max])) + b[:b_max]
list_acc = list(itertools.accumulate(list_))


index = bisect.bisect_right(list_acc, k)
ans = index

now_left = 0
now_right = index


# print(list_)
while(now_right != len(list_)):
    k += list_[now_left]
    now_left += 1

    while(now_right != len(list_)):
        if list_acc[now_right] <= k:
            now_right += 1
        else:
            break
    # print(ans)
    ans = max(ans, now_right-now_left)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import itertools
import bisect

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

sum_ = 0
count = 0
for i in range(len(a)):
    if (sum_+a[i]) >= k:
        break
    else:
        count += 1
        sum_ += a[i]
a_max = count

sum_ = 0
count = 0
for i in range(len(b)):
    if (sum_+b[i]) >= k:
        i = i-1
        break
    else:
        count += 1
        sum_ += b[i]
b_max = count


list_ = list(reversed(a[:a_max])) + b[:b_max]
list_ = list(itertools.accumulate(list_))


index = bisect.bisect_right(list_, k)
ans = index

now_left = 0
now_right = index
num = index

# print(list_)
while(now_right != len(list_)):
    k += a[now_left]
    now_left += 1
    num -= 1

    while(now_right != len(list_)):
        if list_[now_right] <= k:
            num += 1
            now_right += 1
        else:
            break

    ans = max(ans, now_right-now_left)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import itertools
import bisect

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

sum_ = 0
count = 0
for i in range(len(a)):
    if (sum_+a[i]) >= k:
        break
    else:
        count += 1
        sum_ += a[i]
a_max = count

sum_ = 0
count = 0
for i in range(len(b)):
    if (sum_+b[i]) >= k:
        i = i-1
        break
    else:
        count += 1
        sum_ += b[i]
b_max = count


list_ = list(reversed(a[:a_max])) + b[:b_max]
list_ = list(itertools.accumulate(list_))


index = bisect.bisect_right(list_, k)
ans = index

now_left = 0
now_right = index
num = index

# print(list_)
while(now_right != len(list_)):
    k += a[now_left]
    now_left += 1
    num -= 1

    while(now_right != len(list_)):
        if list_[now_right] <= k:
            num += 1
            now_right += 1
        else:
            break

    ans = max(ans, now_right-now_left+1)

print(ans)

Submission status: Wrong Answer

Solution code:
# abc172_c.py
'''
尺取り法、二分探索、両方良問なので両方で解けるようにする。
'''
N, M ,K= map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
cnt = []
b_idx = M-1
# A を１冊ずつ増やす→B の読める場所を後ろにずらしていくイメージで実装する
# 両方累積和で管理して、計算を減らす(Bは特に後ろにずらすと再計算が必要) 
b_cum = []
cum = 0
for b in B:
    cum += b
    b_cum.append(cum)
a_sum = 0
for i,a in enumerate(A):
    a_sum += a
    if a_sum > K:
        break
    while b_idx >= 0 and a_sum + b_cum[b_idx] > K:
        b_idx -= 1
    ans = max(ans,i + b_idx + 2)
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()))
b = sum(B)
ka = k
i = m
c = 0
re = 0
for a in A:
  while ka < b and i > 0:
    i -= 1
    b -= B[i]
  ka -= a
  if ka < 0:
    break
  c += 1
  re = max(re, c+i) 

  
print(max(re, c+i))

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()))
b = sum(B)
ka = k
i = m
c = 0
re = 0
for a in A:
  ka -= a
  while ka < b and i > 0:
    i -= 1
    b -= B[i]
  if ka < 0:
    break
  c += 1
  if re < c+i:
  	re = c+i

  
print(re)

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.extend(b)
ab = sorted(a)

book = 0
time = 0
for i in ab:
    time += i
    if time > k:
        print(book)
        exit()
    elif time == k:
        book += 1
        print(book)
        exit()
    else:
        book += 1

Submission status: Wrong Answer

Solution code:
[n,m,k]=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

li=[]
li+=a
li+=b
li.sort()

sum=0
for i in li:
    if k>li[0]:
        temp=li.pop(0)
        sum+=1
        k-=temp
    #print(li)


print(sum)

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

print(c-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()))
ta=[0]*n
tb=[0]*m
for i in range(n):
        ta[i]=ta[i-1]+a[i]
for j in range(m):
    tb[j]=tb[j-1]+b[j]
ans=0
for i in range(n):
    if ta[i]>k:
        break
    for j in range(m-1,-1,-1):
        if ta[i]+tb[j]<=k:
            ans=max(ans,i+j+2)
            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, 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:
def main():
    n, m, k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = []
    for x in range(n):
        sumA = int(sum(A[0:x]))
        for y in range(m):
            sumB = int(sum(B[0:y]))
            if sumA + sumB < k:
                C.append(x+y)
    print(max(C))
main()

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_cum = [0]
B_cum = [0]

for i in range(n):
  A_cum.append(A_cum[i]+A[i])
  
for i in range(m):
  B_cum.append(B_cum[i]+B[i])

ans = 0  
for i in range(n+1):
  rest = k-A_cum[i]
  if rest<=0:
    continue
  
  ans = max(ans, bisect.bisect_right(B_cum, rest)-1+i)
  
print(ans)

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()))
    C = []
    for x in range(n):
        sumA = int(sum(A[0:x]))
        for y in range(m):
            sumB = int(sum(B[0:y]))
            if sumA + sumB < k:
                C.append(x+y+2)
    print(max(C))
main()

Submission status: Wrong Answer

Solution code:
import bisect
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n+1):
  a[i] += a[i-1]
for j in range(1,m):
  b[j] += b[j-1]
ans = 0
for i in range(n+1):
  x = k-a[i]
  ptr = bisect.bisect_right(b,x)
  ans = max(ans,ptr+i)
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()))
cn = 0
cm = 0
ans = 0
while cm < m or cn < n:
  if cm < m and (cn == n or a[cn] > b[cm]):
    if b[cm] > k:
      break
    k -= b[cm]
    cm += 1
  elif cn < n:
    if a[cn] > k:
      break
    k -= a[cn]
    cn += 1
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
## necessary imports
import sys
input = sys.stdin.readline
#from math import ceil, floor, factorial;

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

## gcd function
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k 
    res = 1
    for i in range(k): 
        res = res * (n - i) 
        res = res / (i + 1) 
    return int(res) 

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
    hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e7 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve() 
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

n, m, k = int_array();
# a = int_array()[::-1];
# b = int_array()[::-1]; 
a = sorted(int_array(), reverse = 1);
b = sorted(int_array(), reverse = 1);
ans = 0; time = 0;
while(time < k):
    if a and b:
        if a[-1] <= b[-1]:
            if(a[-1] + time <= k):
                ans += 1; time += a.pop();
            else:
                break;
        else:
            if(b[-1] + time <= k):
                ans += 1; time += b.pop();
            else:
                break;
    else:
        if a:
            if(a[-1] + time <= k):
                ans += 1; time += a.pop();
            else:
                break;
        elif b:
            if(b[-1] + time <= k):
                ans += 1; time += b.pop();
            else:
                break;
        else:
            break;

print(ans);

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()))
    C = []
    for x in range(n+1):
        sumA = int(sum(A[0:x]))
        for y in range(m+1):
            sumB = int(sum(B[0:y]))
            if sumA + sumB < k:
                C.append(x+y)
    print(max(C))
main()

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()))
    C = []
    for x in range(n+1):
        sumA = int(sum(A[0:x]))
        print(sumA)
        for y in range(m+1):
            sumB = int(sum(B[0:y]))
            print("仕切り")
            print(sumB)
            if sumA + sumB < k:
                C.append(x+y)
    print(C)
    print(max(C))
main()