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())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))

sumA = []
for i in range(len(listA)):
    if i == 0:
        sumA.append(listA[i])
    else:
        sumA.append(sumA[i-1]+listA[i])
sumB = []
for i in range(len(listB)):
    if i == 0:
        sumB.append(listB[i])
    else:
        sumB.append(sumB[i-1]+listB[i])

maxB = 0
for iA in range(len(sumA)):
    if sumA[iA] > k:
        break
    for iB in range(len(sumB)):
        if sumA[iA] + sumB[iB] > k:
            break
        else:
            if maxB < iA+1+iB+1:
                maxB = iA+1+iB+1
print(maxB)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate

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

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

print(goukei)
"""

Submission status: Wrong Answer

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

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()))
amax = len(a)
bmax = len(b)
res = 0
tim = 0
for _ in range(amax+bmax):
    if len(a) == 0:
        tim += b[0]
        b.pop(0)
    elif len(b) == 0:
        tim += a[0]
        a.pop(0)
    elif a[0] <= b[0]:
        tim += a[0]
        a.pop(0)
    else:
        tim += b[0]
        b.pop(0)
    res += 1
    if tim > k:
        res -= 1
        break
print(res)

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

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = input().split(" ")
lista = [int(n) for n in a]
b = input().split(" ")
listb = [int(n) for n in b]
count = 0
if sum(lista)+sum(listb)<=k:
  print(m+n)
  exit()
while k>=0:
  if (len(lista)>0 and len(listb)>0 and lista[0]>=listb[0]) or (len(listb)>0 and len(lista)==0):
    k-=listb.pop(0)
    count+=1  
  elif (len(lista)>0 and len(listb)>0 and listb[0]>=lista[0]) or (len(lista)>0 and len(listb)==0):
    k-=lista.pop(0)
    count+=1
  else:
    count+=1
    break
print(count-1)

Submission status: Wrong Answer

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

a_count = 0
b_count = 0
ans = 0
time = 0
flag = True
while flag:
    if a_count < n and b_count < m:
        if a[a_count] < b[b_count]:
            time += a[a_count]
            a_count+=1
            ans += 1

        else:
            time += b[b_count]
            b_count+=1
            ans += 1

    elif a_count < n and b_count > m:
        time += a[a_count]
        a_count+=1
        ans += 1
    elif a_count > n and b_count < m:
        time += b[b_count]
        b_count += 1
        ans += 1
    else:
        flag = False
    if time>k:
        flag = False
        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()))

count = 0
total = 0
idxA = -1
idxB = -1

for i in range(N):
  t = total + A[i]
  if t > K:
    break
  total = t
  count += 1
  idxA = i

for i in range(M):
  t = total + B[i]
  if t > K:
    break
  total = t
  count += 1
  idxB = i

max_total = total
ans = count

# print((total, ans, idxA, idxB))

for i in range(idxA, -1, -1):
  total -= A[i]
  count -= 1
  for j in range(idxB+1, M):
    t = total + B[j]
    if t <= K:
      total = t
      count += 1
      idxB = j
      if max_total < total:
        max_total = total
        ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def f(A, B, K):
    count = 0
    while True:
        if (not A) and (not B):
            return count
        elif not A:
            K -= B[0]
            if K >= 0:
                count += 1
                del B[0]
            else:
                return count
                
        elif not B:
            K -= A[0]
            if K >= 0:
                count += 1
                del A[0]
            else:
                return count
                
        else:
            if A[0] <= B[0]:
                K -= A[0]
                if K >= 0:
                    count += 1
                    del A[0]
                else:
                    return count
            else:
                K -= B[0]
                if K >= 0:
                    count += 1
                    del B[0]
                else:
                    return count
if __name__ == '__main__':

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

Submission status: Wrong Answer

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

i = 0
j = 0
ans = 0

while k > 0:
    if i <= n-1 and j <= m-1:
        k -= min(a_lsit[i], b_list[j])
        if a_lsit[i] < b_list[j]:
            i += 1
        else:
            j += 1
    elif i > n-1:
        k -= b_list[j]
        j += 1
    elif j > m-1:
        k -= a_lsit[i]
        i += 1

    if k < 0:
        break

    ans += 1
    
print(int(ans))

Submission status: Wrong Answer

Solution code:
N,M,K=input().split()
N=int(N)
M=int(M)
K=int(K)
tmp=input().split()
A=[]
Atime=[]
for i in range(len(tmp)):
  A.append(int(tmp[i]))
  if i==0: Atime.append(A[0])
  else: Atime.append(Atime[i-1]+A[i])
tmp=input().split()
B=[]
Btime=[]
for i in range(len(tmp)):
  B.append(int(tmp[i]))
  if i==0: Btime.append(B[0])
  else: Btime.append(Btime[i-1]+B[i])

Blim=len(Btime)
for i in range(len(Btime)):
  if Btime[i]>K:
    Blim=i
    break
result=Blim
#print(Atime)
for i in range(len(Atime)):
  while 1==1:
    if Atime[i]+Btime[Blim-1]<=K:
      if Blim+i+1>result: result=Blim+i+1
      break
    if Blim==0:break
    Blim-=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()))

cnt=0

#Aのみ読んだ場合を考える
for a in A:
  if K >= a:
    K-=a
    cnt+=1
  else:
    break

maxcnt=cnt
A=A[: cnt ]
#print(A,K)
for i,b in enumerate(B):
  #aの要素なくしてbを入れる
  #bがいれれるまでaをなくすよ
  while b>K and len(A)!=0:
    a = A.pop()
    K += a
    cnt -= 1
    #print('-a,',a,K)
    
  if len(A) == 0:
    _B=B.copy()[i:]
   # print(_B)
    _B.pop(0)
    #まだbが入るかもしれない…！
    while(len(_B)>0 and K>=b):
      K-=b
      cnt+=1
      #print('+b(while),',b,K,cnt)
      if len(_B)>0:
        b=_B.pop(0)
      else:
        break
    if maxcnt < cnt:
      maxcnt=cnt
    break

  K -= b
  cnt+=1
  #print('+b,',b,K,cnt)
  
  if maxcnt < cnt:
    maxcnt=cnt



print(maxcnt)

Submission status: Wrong Answer

Solution code:
A_len, B_len, K = map(int, input().split(' '))
#print("Aは{0}冊. Bは{1}冊. 上限{2}分".format(A_len, B_len, K))

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

# A,Bの累積和の配列を出して、A_acc,B_accの要素番地が最大となるような組み合わせを出す

A_acc = []
for idx_A in range(A_len): 
  if(idx_A == 0):
    A_acc.append(A[0])
  else:
    A_acc.append(A_acc[idx_A - 1] + A[idx_A])
A_acc.insert(0, 0)
    
B_acc = []
for idx_B in range(B_len):
  if(idx_B == 0):
    B_acc.append(B[0])
  else:
    B_acc.append(B_acc[idx_B - 1] + B[idx_B])
B_acc.insert(0, 0)

#print(A_acc, B_acc)

max_num = 0
left_time = K
for a_num in range(A_len + 1):
  left_time = K - A_acc[a_num]
  #print("Aから{0}冊読んだ場合はそもそも残り{1}分".format(a_num, left_time))
  
  b_num = 0
  while(True):
    #print("Bから{0}冊読んでる場合,残り時間{1}".format(b_num, left_time - B_acc[b_num]))
    
    if(b_num + 1 > B_len):
      break
    
    if(left_time - B_acc[b_num + 1] < 0):
      break
    
    b_num += 1
    
  #print("結果,A棚から{0}冊、B棚から{1}冊で合計{2}冊で経過時間{3}"
        #.format(a_num, b_num, a_num + b_num, A_acc[a_num] + B_acc[b_num]))
  max_num = max(max_num, (a_num + b_num))
  
print(max_num)

Submission status: Wrong Answer

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

A_cn = 0
B_cn = 0
time = 0

for _ in range(K):
    if A_cn < len(A_list):
        a = A_list[A_cn]
    else:
        a = 10**10
    if B_cn < len(B_list):
        b = B_list[B_cn]
    else:
        b = 10**10

    if (K-time) < min(a,b):
        print(A_cn+B_cn)
        sys.exit()
    elif K-time == 0:
        print(A_cn+B_cn)
        sys.exit()
    else:
        if a <= b:
            time += a
            A_cn += 1
        else:
            time += b
            B_cn += 1

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque

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


count = 0
time = 0
#もし先にどっちかの玉が尽きた時の問題。
for i in range(10**8):
    #本が尽きていない。
    if len(A) != 0 and len(B) != 0:

        if A[0] < B[0]:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()

        elif A[0] > B[0]:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        else:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
    elif len(A) == 0 or len(B)== 0:
        #どっかの本が尽きている。
        if len(A) == 0 and len(B) != 0:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        elif len(A) != 0 and len(B) == 0:
            time = time +A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        elif len(A) == 0 and len(B) == 0:
            print(count)
            sys.exit()
               


print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = input().strip().split()
NMK = [int(N), int(M), int(K)]
A= input().strip().split()
A = [int(s) for s in A]

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

max_val=0
val=0
sum_l=0
for i in range (0,NMK[0],1):
  for j in range (0,NMK[1],1):
    sum_l=sum(A[0:i])+sum(B[0:j])
    if sum_l<=NMK[2]:
      if (i+j)>max_val:
        max_val=i+j

        
print(max_val)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
A_deque = deque(A_list)
B_deque = deque(B_list)
time = 0
book = []

if A_deque[0] > K and B_deque[0] > K:
    pass
else:
    while time < K:
        if len(A_deque) == 0 and len(B_deque) == 0:
            break
        elif len(A_deque) == 0:
            time += B_deque[0]
            book.append(B_deque[0])
            B_deque.popleft()
            # print(B_deque)
        elif len(B_deque) == 0:
            time += A_deque[0]
            book.append(A_deque[0])
            A_deque.popleft()
            # print(A_deque)
        elif (len(A_deque) == 0) and len(B_deque) == 0:
            break
        elif A_deque[0] < B_deque[0]:
            time += A_deque[0]
            book.append(A_deque[0])
            A_deque.popleft()
            # print(A_deque)
        elif A_deque[0] > B_deque[0]:
            time += B_deque[0]
            book.append(B_deque[0])
            B_deque.popleft()
        elif A_deque[0] == B_deque[0]:
            #print(min(len(A_deque), len(B_deque)))
            time += A_deque[0]
            book.append(A_deque[0])
            A_deque.popleft()

if time > K:
    book.pop(-1)
else:
    pass
print(len(book))

Submission status: Wrong Answer

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

p1, p2 = n, m
f = [0]
s = [0]
for i in range(n):
    f.append(f[i]+arr1[i])
for i in range(m):
    s.append(s[i]+arr2[i])
highest = 0
while p1 != 0 or p2 != 0:
    if f[p1] + s[p2] <= k:
        highest = max(highest, p1+p2)
    if f[p1] <= k:
        highest = max(highest, p1)
    if s[p2] <= k:
        highest = max(highest, p2)
    if p1 != 0 and (p2 == 0 or f[p1] >= s[p2]):
        p1 -= 1
    else:
        p2 -= 1
print(highest)

Submission status: Wrong Answer

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

asum = list(accumulate(a))
bsum = list(accumulate(b))

alim = 0
for i, v in enumerate(asum, start=1):
    if v > k:
        alim = i - 1
        break
else:
    alim = n

blim = 0
for i, v in enumerate(bsum, start=1):
    if v > k:
        blim = i - 1
        break
else:
    blim = m

cnt_a = 0
cp_k = k
if k > sum(a[:alim]):
    cp_k -= sum(a[:alim])
    for i in b:
        if cp_k > i:
            cp_k -= i
            cnt_a += 1

cnt_b = 0
cp_k = k
if k > sum(b[:blim]):
    cp_k -= sum(b[:blim])
    for i in a:
        if cp_k > i:
            cp_k -= i
            cnt_b += 1

print(max(alim, blim, alim + cnt_b, blim + cnt_a))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    total = 0
    a_index = 0
    b_index = 0
    is_finish_a = 0
    is_finish_b = 0
    lena = len(A)
    lenb = len(B)
    for i in range(N+M+1):
        # print("is_finish_a")
        # print(is_finish_a)
        # print(is_finish_b)
        # print(a_index)
        # print(b_index)
        # if lena + lenb - 2 == a_index + b_index:
        #     print(a_index+b_index)
        #     sys.exit()
        # print("i")
        # print(i)
        if is_finish_a == 1 and is_finish_b == 1:
            # print("A")
            print(a_index+b_index)
            sys.exit()
        if is_finish_a == 0 and is_finish_b == 0 and total + A[a_index] > K and total + B[b_index] > K:
            # print("B")
            print(a_index+b_index)
            sys.exit()
        if is_finish_a == 1:
            if total + B[b_index] > K:
                # print("C")
                print(a_index+b_index)
                sys.exit()
            else:
                total+=B[b_index]
                b_index+=1
                if b_index == lenb:
                    is_finish_b = 1
            continue
        if is_finish_b == 1:
            if total + A[a_index] > K:
                # print("D")
                print(a_index+b_index)
                sys.exit()
            else:
                total+=A[a_index]
                a_index+=1
                if a_index == lena:
                    is_finish_a = 1
            continue

        if is_finish_a == 1 or is_finish_b == 1:
            continue

        if is_finish_a == 0 and is_finish_b == 0 and A[a_index] > B[b_index]:
            total+=B[b_index]
            b_index+=1
            # print("b_index")
            # print(b_index)
            if b_index == lenb:
                is_finish_b = 1
        elif is_finish_a == 0 and is_finish_b == 0:
            total+=A[a_index] 
            a_index+=1
            if a_index == lena:
                is_finish_a = 1
            # print("a_index")
            # print(a_index)


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()))
count = 0
a.extend(b)
a.sort(reverse=False)
alpha = 0

for i in range(len(a)):
  alpha += a[i]
  if alpha <= k:
    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()))
for i in range(1, len(A)):
    A[i] += A[i - 1]
for i in range(1, len(B)):
    B[i] += B[i - 1]
A.insert(0, 0)
B.insert(0, 0)
r = 0
for i, a in enumerate(A):
    min_idx = 0
    max_idx = len(B) - 1
    while min_idx < max_idx:
        j = (min_idx + max_idx + 1) // 2
        k = K - A[i] - B[j]
        if k < 0:
            max_idx = j - 1
        else:
            min_idx = j
    r = max(r, i + j)
print(r)

Submission status: Wrong Answer

Solution code:
import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    
    n,m,k = map(int, input().split())
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    i,j,count = 0,0,0

    while(k>0):

        
        if count == n+m:
            break

        if i < n and j < m:

            if n_list[i] < m_list[j]:
                k -= n_list[i]
                count += 1
                i += 1
            else:
                k -= m_list[j]
                count += 1
                j += 1
            
            if k < 0:
                count -= 1
                break

        else:
            if i >= n:
                if j >= m:
                    break
                k -= m_list[j]
                count += 1
                j += 1

            elif j >= m:
                if i >= n:
                    break
                k -= n_list[i]
                count += 1
                i += 1

            if k < 0:
                count -= 1
                break

    print(count)



            

if __name__ == "__main__":
    main()

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
for i in range(1,n):
    if a[i]+a[i-1]<=k:
        a[i]+=a[i-1]
        c=i

    else:
        break
    


d=0 

for i in range(1,m):
    if b[i]+b[i-1]<=k:
        b[i]+=b[i-1]
        d=i

    else:
        break

#print(c,d)
if a[0]<=k:
    mx=c+1
else:
    mx=0
j=0
while c>=0 and j<=d:
    if a[c]+b[j]<=k:
        
        j+=1
        mx=max(mx,c+1+j)
        #print(c,j,mx)
    else:
        c-=1
print(mx)

Submission status: Wrong Answer

Solution code:
from collections import deque


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

    ans = 0
    A_d = deque()
    A_d.append(0)
    B_d = deque()
    B_d.append(0)
    for a in A:
        if A_d[-1] + a > K:
            break
        A_d.append(A_d[-1]+a)
    tmp = 0
    for b in B:
        if B_d[-1] + b > K:
            break
        B_d.append(B_d[-1]+b)
    A_d.popleft()
    B_d.popleft()

    tmp = len(A_d)
    for i, b in enumerate(B_d, 1):
        if A_d[-1] + b > K:
            break
        tmp += 1
    ans = tmp
    tmp = len(B_d)
    for i, a in enumerate(A_d, 1):
        if B_d[-1] + a > K:
            break
        tmp += 1
    print(max(ans, tmp))


if __name__ == "__main__":
    main()

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

a_wa = []
max_a_idx = None
for idx, a in enumerate(A):
    if idx == 0:
        a_wa.append(a)
    else:
        a_wa.append(a_wa[idx-1] + a)

    if a_wa[idx] > K:
        break

    max_a_idx = idx

b_wa = []
max_b_idx = None
for idx, b in enumerate(B):
    if idx == 0:
        b_wa.append(b)
    else:
        b_wa.append(b_wa[idx-1] + b)

    if b_wa[idx] > K:
        break

    max_b_idx = idx

if max_a_idx is None and max_b_idx is None:
    print(0)
    exit()
elif max_a_idx is None:
    print(max_b_idx + 1)
    exit()
elif max_b_idx is None:
    print(max_a_idx + 1)
    exit()

temp_a_idx = max_a_idx
temp_b_idx = None
out_num_list = []
for idx in range(max_b_idx+1):
    while True:
        if temp_a_idx < 0:
            print(max_b_idx+1)
            exit()
        temp = a_wa[temp_a_idx] + B[idx]
        if temp <= K:
            temp_b_idx = idx
            break
        else:
            temp_a_idx -= 1

if temp_b_idx is None:
    print(max_a_idx+1)
    exit()
print(temp_a_idx + temp_b_idx + 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()))

a_i= 0
b_i= 0
f = True

# if sum(a)+sum(b) <= k:
#     print(n+m)
#     exit()

for i in range(400000):
    # aaaa
    # print(a_i,b_i,k) 
    if a[a_i] < b[b_i]:
        k -= a[a_i]
        if k == 0:
            print(a_i+b_i+1)
            exit()
        if k < 0:
            print(a_i+b_i)
            exit()
        a_i += 1
        if a_i == n:
            for j in range(200000):
                # aaaaa
                # print(a_i,b_i,k)
                k -= b[b_i]
                if k == 0:
                    print(a_i+b_i+1)
                    exit()
                if k < 0:
                    print(a_i+b_i)
                    exit()
                b_i += 1
                if b_i == m:
                    print(a_i+b_i)
                    exit()
    else:
        k -= b[b_i]
        if k == 0:
            print(a_i+b_i+1)
            exit()
        if k < 0:
            print(a_i+b_i)
            exit()
        b_i += 1
        if b_i == m:
            for j in range(200000):
                # aaaaa
                # print(a_i,b_i,k)
                k -= a[a_i]
                if k == 0:
                    print(a_i+b_i+1)
                    exit()
                if k < 0:
                    print(a_i+b_i)
                    exit()
                a_i += 1
                if a_i == n:
                    print(a_i+b_i)
                    exit()
print(a_i+b_i)

Submission status: Wrong Answer

Solution code:
n, m, k = (int(x) for x in input().split())

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

K = k
ans = 0

i = 0
while i<n and K-a[i]>=0:
    K -= a[i]
    i += 1
    # if i==n:
    #     break
ans = i
    
# K = k
l = 0
if i==0:
    while l<m and K-b[l]>=0:
        K -= b[l]
        l += 1
            # if l==m:
            #     break
        ans = max(ans, l)
else:
    for j in range(i-1, -1, -1):
        while l<m and K-b[l]>=0:
            K -= b[l]
            l += 1
            # if l==m:
            #     break
        ans = max(ans, j+l+1)
        K += a[j]


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()))
result = 0
A.append(10**15)
B.append(10**15)

i,j = 0,0
while K > 0:
    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:
s = [input() for i in range(3)]
list1 = list(map(int, s[0].split()))
n = list1[0]
m = list1[1]
k = list1[2]

list2 = list(map(int, s[1].split()))
list3 = list(map(int, s[2].split()))

counter_l1 = 0
counter_l2 = 0

for i in range(n+m):
    if counter_l1 < n and counter_l2 < m:
        if list2[counter_l1] < list3[counter_l2]:
            k = k - list2[counter_l1]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l1 +=1
            continue
        if list2[counter_l1] >= list3[counter_l2]:
            k = k - list3[counter_l2]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l2 +=1
    else:
        if counter_l1 >= n:
            k = k - list3[counter_l2]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l2 +=1
        if counter_l2 >= m:
            k = k - list2[counter_l1]
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
print(counter_l1+counter_l2)

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect

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

ac = np.cumsum(a)
bc = np.cumsum(b)
ans = 0

# print(ac)
# print(bc)

a_bisect = bisect.bisect_left(ac, k)
b_bisect = bisect.bisect_left(bc, k)
leftTime = 0

if a_bisect < b_bisect:
    leftTime = k - bc[b_bisect - 1]
    # print(leftTime)
    # print(b_bisect)
    # print(bisect.bisect_right(ac, leftTime))
    ans += b_bisect + bisect.bisect_right(ac, leftTime)
elif a_bisect > b_bisect:
    leftTime = k - ac[a_bisect - 1]
    ans += a_bisect + bisect.bisect_right(bc, leftTime)
else:
    if k - bc[b_bisect - 1] <= k - ac[a_bisect - 1]:
        leftTime = k - ac[a_bisect - 1]
        ans += a_bisect + bisect.bisect_right(bc, leftTime)
    else:
        leftTime = k - bc[b_bisect - 1]
        ans += b_bisect + bisect.bisect_right(ac, leftTime)

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_sum = 0
A_max = 0
B_sum = 0
B_max = 0
best_num = 0
A_max = N
flag = True
for i in range(N):
    A_sum += A[i]
    if A_sum > K:
        A_sum -= A[i]
        A_max = i
        flag = False
        break
A = A[0:A_max]
now_num = A_max
mixsum = A_sum
b_num = 0
if flag:
    for i in range(M):
        mixsum += B[i]
        if mixsum > K:
            mixsum -= B[i]
            break
    now_num += i+1
    b_num = i
A.reverse()
best_num = now_num
for i in range(A_max):
    mixsum -= A[i]
    now_num -= i
    for j in range(b_num, M):
        mixsum += B[j]
        now_num += 1
        if mixsum > K:
            now_num -= 1
            break
    if now_num > best_num:
        best_num = now_num
print(best_num)

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

A.extend(B)
AB = sorted(A)

if sum(AB) <= K:
    print(sum(AB))
    sys.exit(0)
    
cnt = []
ans = 0
for ab in AB:
    cnt.append(ab)
    if sum(cnt) <= K:
        ans += 1
    else:
        break
        
print(ans)