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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-06-27 21:25:14 +0900
# LastModified: 2020-06-27 22:32:22 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from itertools import accumulate as ac

def main():
    n, m, k = map(int, input().split())
    a = list(ac(list(map(int, input().split()))))
    b = list(ac(list(map(int, input().split()))))
    a_j = [a_ for a_ in a if a_<=k]
    b_j = [b_ for b_ in b if b_<=k]
    cnt = 0
#    print(a_j)
#    print(b_j)
    for i in range(len(a_j)):
        for j in range(len(b_j)):
            if a_j[i]+b_j[j] <= k and i+1+j+1 > cnt:
                cnt = i+1+j+1
    print(cnt)


    
    

    


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

for x in range(n):
  sum1=0
  ans1=0
 
  sum1=sum(a[0:x])
  if sum1>k:
    break
  else:
  	ans1+=x+1
  for y in range(m):
    
      
    sum1+=b[y]
    if sum1>k:
      break
    else:
      ans1+=1
      if ans1>ans:
         ans=ans1
        
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()))

if a[0]>k:
  ans=0
  for i in range(m):
    ans+=b[i]
    if ans>k:
      print(i)
      break
elif b[0]>k:
  ans=0
  for i in range(n):
    ans+=a[i]
    if ans>k:
      print(i)
      break
else:
  asum=0
  bsum=0
  for i in a:
    asum+=i
    if asum>k:
      break
  for i in b:
    bsum+=i
    if bsum>k:
      break
  ans=0
  bsumc=bsum
  if asum+bsum<k:
    print(n+m)
  else:
    for i in range(n+1):
      bsum=bsumc
      for j in range(m+1):
        if asum+bsum<=k and n+m-(i+j)>ans:
          ans=n+m-i-j
          break
        if j==m:
          break
        bsum-=b[-1-j]
      if i==n or asum+bsumc<k:
        break
      asum-=a[-1-i]
  print(ans)

Submission status: Wrong Answer

Solution code:
i1 = input().split(" ")
n = int(i1[0])
m = int(i1[1])
k = int(i1[2])
i2 = input().split(" ")  # desk A
i3 = input().split(" ")  # desk B

t = 0
at = 0
bt = 0


def isWithinBudget(val, k):
    if k - val < 0:
        return False
    else:
        return True


# def findBestProceeding(param, param1, k ,t ):
#     if len(param) == 0 and len(param1) == 0:
#         return t
#     elif len(param) == 0:
#         val = param1[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param,param1[1:],k-val,t+1)
#         else:
#             return t
#     elif len(param1) == 0:
#         val = param[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param[1:],param1,k-val,t+1)
#         else:
#             return t
#     if param[0] < param1[0]:
#         val = param[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param[1:], param1, k - val, t + 1)
#         else:
#             return t
#     elif param[0] > param1[0]:
#         val = param1[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param, param1[1:], k - val, t + 1)
#         else:
#             return t
#     else: #equal
#         val = param1[0]
#         if isWithinBudget(val, k):
#             findBestProceeding(param[1:], param1[1:], k - val, t + 1)
#         else:
#             return t



for i in range(len(i2) + len(i3)):
    if bt >= len(i3) and at >= len(i2):
        break
    elif bt >= len(i3):
        # pick form desk A
        val = int(i2[at])
        at += 1
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    elif at >= len(i2):
        val = int(i3[bt])
        bt += 1
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    else:
        if int(i3[bt]) > int(i2[at]):
            # pick form desk A
            val = int(i2[at])
            at += 1
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break
        elif int(i3[bt]) == int(i2[at]):
            val = int(i2[at])
            at += 1
            bt += 1
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break
        else:
            val = int(i3[bt])
            bt += 1
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break

    if k == 0:
        break
print(t)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)


# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1


def II(): return int(input())


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


def MI1(): return map(int1, input().split())


def LI(): return list(map(int, input().split()))


def LI1(): return list(map(int1, input().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def MS(): return input().split()


def LS(): return list(input())


def LLS(rows_number): return [LS() for _ in range(rows_number)]


def printlist(lst, k=' '): print(k.join(list(map(str, lst))))


INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations


# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, M, K = MI()
    A = LI()
    B = LI()

    # print(list(accumulate(A)))
    # print(list(accumulate(B)))
    ra = list(accumulate(A))[::-1]
    rb = list(accumulate(B))[::-1]
    na = N
    nb = M

    ia = 0
    ib = 0

    ta = ra[0]
    tb = rb[0]

    while ta + tb > K:
        # print(ia, ib, na, nb, ta, tb)
        if na == 0 and nb == 0: break
        if ta > tb:
            ia = ia + 1
            na = na - 1
            if na == 0:
                ta = 0
            else:
                ta = ra[ia]
        else:
            ib = ib + 1
            nb = nb - 1
            if nb == 0:
                tb = 0
            else:
                tb = rb[ib]

    print(na + nb)


if __name__ == '__main__':
    solve()

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
ans = 0
for i in range(len(A)):
  if sum(A[0:i+1]) < k:
    a += 1
  else:
    break

for i in range(len(B)):
  if sum(B[0:i+1]) < k:
    b += 1
  else:
    break
#print(a)
#print(b)

su = sum(A[0:a]) + sum(B[0:b])
if su <= k:
  print(a+b)
else:
  for i in range(min(a,b)):
    ans += 1
    if A[a-1] >= B[b-1]:
      if su - A[a-1] <= k:
        break
      else:
        a -=1
    if A[a-1] < B[b-1]:
      if su - B[b-1] <= k:
        break
      else:
        b -=1   
  print(a+b-ans)

Submission status: Wrong Answer

Solution code:


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    accumA = [0,A.pop(0)]
    accumB = [0,B.pop(0)]
    for a in A:
        accumA.append(accumA[-1] + a)
    for b in B:
        accumB.append(accumB[-1] + b)
    total = 0
    ans = None
    # for n,a,b in enumerate(zip(accumA,accumB)):
    for p in itertools.product(accumA,accumB):
        if K >= sum(p):
            total = max(sum(p),total)
            ans = p
    if ans == None:
        return 0
    return accumA.index(ans[0]) + accumB.index(ans[1])








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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    S=list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    N=S[0]
    M=S[1]
    K=S[2]
    nokori=K
    i=0
    j=0
    hon=[A[0],B[0]]
    kazu=0
    inLoop=True
    while inLoop:
        if nokori < min(hon):
            inLoop=False
            break
        if hon[0]==10**10 and hon[1]==10**10:
            inLoop=False
            break
        if hon[0]<=hon[1]:
            i+=1
            nokori -= hon[0]
            kazu+=1
            if i!=N:
                hon[0]=A[i]
            else:
                hon[0]=10**10
        else:
            j+=1
            nokori -= hon[1]
            kazu+=1
            if j!=M:
                hon[1]=B[j]
            else:
                hon[1]=10**10
    print(kazu)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = input().split()
x = input().split()
y = input().split()
xx, yy = [0]*20000, [0]*20000
xx = list(map(lambda i: int(i), x))
yy = list(map(lambda i: int(i), y))
t = 0
m = 0
for i in range(len(xx)):
  if t + sorted(xx)[i]< int(a[2]):
    t += sorted(xx)[i]
    m += 1
  elif t + sorted(yy)[i]< int(a[2]):
    t += sorted(yy)[i]
    m += 1  
  else:
    break
print(m)

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))
elif sum(A)<K and sum(A)+sum(B)>K:
  ans=len(A)
  time=sum(A)
  for i in range(len(B)):
    time+=B[i]
    if time>K:
      print(ans)
      exit()
    else:
      ans+=1
elif sum(B)<K and sum(A)+sum(B)>K:
  ans=len(B)
  time=sum(B)
  for i in range(len(A)):
    time+=A[i]
    if time>K:
      print(ans)
      exit()
    else:
      ans+=1
else:
  ans=0
  time=0
  while len(A)!=0 and len(B)!=0 :
    time+=min(A[0],B[0])
    ans+=1
    if A[0]<B[0]:
      del A[0]
    else:
      del B[0]
    if time>K:
      print(ans)
      exit()

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

import decimal

def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    total = decimal.Decimal(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()))
i=j=0
ans=0
s1=sum(a)
s2=sum(b)
while k>=0:
    if i<len(a) and j<len(b):
        if a[i]<=b[j]:
            k=k-a[i]
            i=i+1
        elif a[i]>b[j]:
            k=k-b[j]
            j=j+1
    else:
        if i<len(a):
            k=k-a[i]
            i=i+1
        elif j<len(b):
            k=k-b[j]
            j=j+1
        else:
            break
    if k>=0:
        ans=ans+1
a.reverse()
b.reverse()
for i in a:
    if s1<=k:
        break
    else:
        s1=s1-i
for i in b:
    if s2<=k:
        break
    else:
        s2=s2-i
print(max(max(s1,s2),ans))

Submission status: Wrong Answer

Solution code:
from collections import deque

N,M,K = map(int,input().split())
Ali = list(map(int,input().split()))
Bli = list(map(int,input().split()))

r = 0
s = 0
t = 0

for i in range(N):
  if Ali[i] <= K-t:
    r += 1
    t += Ali[i]
  else:
    break
    
for i in range(M):
  if Bli[i] <= K-t:
    r += 1
    t += Bli[i]
  else:
    break
    
t = 0
for i in range(M):
  if Bli[i] <= K-t:
    s += 1
    t += Bli[i]
  else:
    break
    
for i in range(N):
  if Ali[i] <= K-t:
    s += 1
    t += Ali[i]
  else:
    break
    
print(max(r,s))

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_sum = 0
cnt = 0
flag = True

for _ in range(N+M):
  if A[a] <= B[b]:
    t_sum += A[a]
    cnt += 1
    a += 1
  elif A[a] > B[b]:
    t_sum += B[b]
    cnt += 1
    b += 1
  
  if t_sum > K:
    cnt -= 1
    break
    
  if a == N:
    for _ in range(M+1):
      if b == M:
        flag = False
        break
      t_sum += B[b]
      cnt += 1
      b += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if b == M:
    for _ in range(N+1):
      if a == N:
        flag = False
        break
      t_sum += A[a]
      cnt += 1
      a += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    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()))

X=[float("inf")]*(n+m+6)
X[n+m]=sum(A)+sum(B)
a=-1 ; b=-1
for i in range(1,n+m+1):
    if a==-n:
        X[n+m-i]=X[n+m-i+1]-B[b]
    elif b==-m:
        X[n+m-i]=X[n+m-i+1]-A[a]
    elif A[a]<B[b]:
        X[n+m-i]=X[n+m-i+1]-B[b]
        b-=1
    else:
        X[n+m-i]=X[n+m-i+1]-A[a]
        a-=1
import bisect
#print(A,B)
if bisect.bisect_left(X,k)==1:
  print(0);exit()
#print(X)
print(bisect.bisect_left(X,k))

Submission status: Wrong Answer

Solution code:
import itertools
from bisect import bisect

N, M, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
C = []
t = 0
while True:
    if t >= K:
        break
    if len(A) !=0 and len(B)!=0:
        c = min(A[0], B[0])
        if c == A[0]:
            t += A[0]
            C.append(A.pop(0))
        else:
            t += B[0]
            C.append(B.pop(0))
    else:
        if len(A)==0:
            C+=B
            break
        else:
            C+=A
            break
print(bisect([x for x in itertools.accumulate(C)], K))

Submission status: Wrong Answer

Solution code:
str1 = input().strip().split()
str_a = input().strip().split()
str_b = input().strip().split()

a_kazu = int(str1[0])
b_kazu = int(str1[1])
jikan_ = int(str1[2])

str_a_count = 0
str_b_count = 0
count = 0

for num in range(a_kazu + b_kazu - 1):
    try:
      if int(str_a[str_a_count]) < int(str_b[str_b_count]):
        jikan_ = jikan_ - int(str_a[str_a_count])
        str_a_count = str_a_count + 1
        count = count + 1
        if jikan_ < 0:
          break
      else:
        jikan_ = jikan_ - int(str_b[str_b_count])
        str_b_count = str_b_count + 1
        count = count + 1
        if jikan_ < 0:
          break
    except:
      try:
        jikan_ = jikan_ - int(str_a[str_a_count])
        str_a_count = str_a_count + 1
        count = count + 1
        if jikan_ < 0:
          break
      except:
        jikan_ = jikan_ - int(str_b[str_b_count])
        str_b_count = str_b_count + 1
        count = count + 1
        if jikan_ < 0:
          break
if count == (a_kazu + b_kazu):
  print(count)
else:
  print(count - 1)

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
#     ans = max(ans, l)
# else:
for j in range(i, -1, -1):
    while l<m and K-b[l]>=0:
        K -= b[l]
        l += 1
    ans = max(ans, j+l)
    K += a[j-1]

while l<m and K-b[l]>=0:
    K -= b[l]
    l += 1
    ans = max(ans, l)

print(ans)

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 and max_count <= A_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] > K:
    break
  elif A_cumsum[i] + B_cumsum[M//2] > K:
    for j in range(M//2):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
        max_count = i + j + 2
      else:
        break
  else:
    for j in range(M//2, 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 = list(map(int,input().split()))
B = list(map(int,input().split()))
def sigma(func, frm, to):
    result = 0;
    for i in range(frm, to+1):
        result += func[i-1]
    return result

a=list()
for i in range(N):
    for j in range(M):
            if sigma(A,1,i)+sigma(B,1,j)<=K:
                a.append(i+j)
print(max(a))

Submission status: Wrong Answer

Solution code:
root = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))      
a.append(1000000000)
b.append(1000000000)
minute=0
books=0
ai=0
bi=0

while minute <= root[2]:
    books += 1
    if a[ai] < b[bi]:
        minute += a[ai]
        ai += 1
    elif b[bi] < a[ai]:
        minute += b[bi]
        bi += 1
    else:
        minute += a[ai]
        if b[bi] == a[ai] == 1000000000:
            break
        if len(a) > ai:
            ai += 1
        elif len(b) > bi:
            bi += 1

print(books-1)

Submission status: Wrong Answer

Solution code:
line = input().split()
n, m, k = int(line[0]), int(line[1]), int(line[2])
a = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
 
time = [[0 for j in range(n+1)] for i in range(m+1)]
for i in range(1,n+1):
    time[0][i] = time[0][i-1] + a[i-1]
for j in range(1,m+1):
    time[j][0] = time[j-1][0] + b[j-1]
ans = 0
for i in range(1,n+1):
    for j in range(1,m+1):
        time[j][i] = time[j-1][i-1] + a[i-1] + b[j-1]
        if time[j][i] <= k:
            ans = max(ans, i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, KK = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))
k = 0


max = N + M
  #print(max)
summ = 0

for i in range(max):

  if len(a) > 0 and len(b) > 0:
    #print(a[0], b[0])
    if a[0] < b[0]:
      k += a[0]
      a.popleft()
    else:
      k += b[0]
      b.popleft()
    
    if KK - k >= 0 :
      summ += 1
    else:
      break
      
  elif len(a) > 0 and len(b) == 0:
    k += a[0]
    
    if KK - k >= 0 :
      summ += 1
      a.popleft()
    else:
      break
  
  elif len(a) == 0 and len(b) > 0:
    k += b[0]
    
    if KK - k >= 0 :
      summ += 1
      b.popleft()
    else:
      break
    
  else:
    break
    
  #print(a)
  #print(b)
  #print(KK)
print(summ)

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=[A[0]]
sumB=[B[0]]


for i in range(1,N):
  sumA.append(sumA[-1]+A[i])

for a in range(len(sumA)):
  if sumA[a]>K:
    lessthanA=a-1
    break
if sumA[-1]<=K:
  lessthanA=N-1

 
for i in range(1,M):
  sumB.append(sumB[-1]+B[i])

#print(sumA)
#print(sumB)
  
totalBook=0
time=0

if A[0]>K and B[0]>K:
  totalBook=0
elif sumA[-1]+sumB[-1]<=K:
  totalBook=N+M

elif A[0]<K:
  for a in range(lessthanA,-1,-1):
    for b in range(len(sumB)):
      if sumB[b]>K-sumA[a]:
        break      
    if a+b+1>=totalBook:
      
      totalBook=a+b+1

  if sumB[-1]<K and totalBook<M:
    #print("secondIF")
    totalBook=M
    
  else:
    #print("ELSE")
    for b in range(len(sumB)):
      if sumB[b]>K:
      	if b>totalBook:
          totalBook=b
      	break

       
print(totalBook)

Submission status: Wrong Answer

Solution code:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n,m,k = MAP()

a = LIST()

b = LIST()

prefA = [0]*n
prefA[0] = a[0]

for i in range(1, n):
    prefA[i] = prefA[i-1] + a[i]


pref = [0]*m

pref[0] = b[0]

for i in range(1, m):
    pref[i] = pref[i-1] + b[i]
#
# print(prefA)
# print(pref)

ans = 0

for i in range(n):
    left = k-prefA[i]

    lo = 0
    hi = m-1

    temp = (i+1)

    if(left>=0):
        while(lo<=hi):
            # print(lo, hi, ans)
            mid = (lo+hi)//2

            if(pref[mid]>left):
                hi = mid - 1
            else:
                lo = mid + 1
                ans = max(ans, temp + lo)
        ans = max(ans, temp + lo)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a.append(10 ** 10)
b.append(10 ** 10)
na = a.popleft()
nb = b.popleft()

cnt = 0
min = 0
while min <= k:
    if na == 10 ** 10 and nb == 10 ** 10:
        cnt += 1
        break
    if na < nb:
        cnt += 1
        min += na
        na = a.popleft()
    elif na > nb:
        cnt += 1
        min += nb
        nb = b.popleft()
    else:
        cnt += 2
        min += na
        min += nb
        if min >= k:
            cnt -= 1
            break
        na = a.popleft()
        nb = b.popleft()

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

total = []
i = 0
j = 0
while len(total) != len(a)+len(b):
  if i<len(a) and j<len(b):
    if a[i]>=b[j]:
      total.append(b[j])
      j+=1
    elif b[j]>=a[i]:
      total.append(a[i])
      i+=1
  elif i>=len(a):
    total.append(b[j])
    j+=1
  elif j>=len(b):
    total.append(a[i])
    i+=1

c = 0
while k>=0:
  k = k-total[c]
  c+=1
  if c == len(total):
    #print(c)
    break
if c == len(total) and k>=0:
  print(c)
else:
  print(c-1)

Submission status: Wrong Answer

Solution code:
import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

if sum(list_)<=k:
  print(len(list_))
else:
  left = 0
  right = len(list_)
  while abs(left-right)>1:
    mid = (left+right) // 2
    if sum(list_[:mid])<=k:
      left = mid
    else:
      right = mid

  print(len(list_[:left]))

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 = A[::-1] + B

right = 0
size = 0
ans = 0
for left in range(N+M):
    while right < (N+M) and size+C[right] <= K:
        size += C[right]
        right += 1
    if (N-1) <= right and left < (N+1):
        ans = max(ans, (right-left))
    if left == right:
        right += 1
    else:
        size -= C[left]

print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
from bisect import bisect

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

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

A_time = [0] * N
B_time = [0] * M

rui = 0
flag = True

for i in range(N):
    
    rui += A[i]
    
    if rui > K:
        rui = float("inf")
        
    A_time[i] = rui

rui = 0

for i in range(M):
    
    rui += B[i]
    
    if rui > K:
        rui = float("inf")
        
    B_time[i] = rui

T = 0
po = 0
num = 0

for i in range(N):
    
    T = K - A_time[i]
    
    if T < 0:
        continue
    
    po = bisect(B_time,T)
    
    num = max(num, po + i + 1)

print("{}".format(num))

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    
    AB = A + B
    AB.sort()
    read_time = 0
    ans = 0
    
    for i in range(len(AB)):
        read_time += AB[i]
        if read_time > K:
            break
        else:
            ans += 1
         
    print(f'{ans}')


if __name__ == '__main__':
    main()

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()))
lA = len(A)
lB = len(B)

i = 0
j = 0
h = 0
dp = [-1] * 410000
dp[0] = 0
while dp[h] <= K:
    if i >= lA and j >= lB:
        print(lA + lB)
        sys.exit(0)
    h += 1
    #print(h)
    if i < lA:
        dp[h] = dp[h-1] + A[i]
        #print(dp[h])
    else:
        dp[h] = 10 ** 18
    if j < lB:
        if dp[h] > dp[h-1] + B[j]:
            dp[h] = dp[h-1] + B[j]
            #print(dp[h])
            j += 1
        else:
            i += 1
    else:
        i += 1
    #print(i,j)

print(h-1)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.buffer.readline


def SS(A, K):
    sA = 0
    AA = []
    for a in A:
        sA += a
        if sA > K:
            break
        AA.append(sA)

    return AA


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

    AA = SS(A, K)
    BB = SS(B, K)
    AA = AA[::-1]

    M = max(len(AA), len(BB))

    left = 0
    right = len(BB) - 1

    print(AA, BB)

    while left < len(AA):
        if AA[left] + BB[right] <= K:
            m = len(AA) - left + right + 1
            if m > M:
                M = m
            left += 1
        else:
            right -= 1
            if right < 0:
                break

    print(M)


main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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

sA=[A[0]]
for i in range(1,n):
    sA.append(sA[-1]+A[i])
sB=[B[0]]
for i in range(m):
    sB.append(sB[-1]+B[i])

ans=0
for i in range(n):
    temp=k-sA[i]
    if temp<0:
        break
    add=bisect_right(sB,temp)
    ans=max(ans,i+1+add)

print(ans)