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:
from collections import deque
n, m, k = map(int, input().split())
a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))

ans = 0
while True:
    # aにもbにも本がない場合ブレーク
    if not a and not b:
        break
    # aに本がなく、bに本がある場合はbからpop
    if not a and b:
        x = b.popleft()
    # その逆
    elif not b and a:
        x = a.popleft()
    # どちらにも本がある場合
    elif a and b:
        if a[0] <= b[0]:
            x = a.popleft()
        else:
            x = b.popleft()
    else:
        while True:
            yeah = 10**9
    if x <= k:
        ans += 1
        k -= x
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N,M,K = map(int,input().split())
A = deque(list(map(int,input().split())))
B = deque(list(map(int,input().split())))
count = 0
while True:
    if((len(A) == 0) and (len(B) == 0)):
        break

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

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

    if((A[0] > K) and (B[0] > K)):
        break
    if(A[0] > K):
        count += 1
        K = K - B.popleft()
        continue
    if(B[0] > K):
        count += 1
        K = K - A.popleft()
        continue
    if(A == B):
        count += 1
        K = K - A.popleft()
        continue

    if(A[0] == B[0]):
        it = min([len(A),len(B)])
        flag = True
        for i in range(it):
            if(A[i] > B[i]):
                count += 1
                K = K - B.popleft()
                flag = False
                break
            if(A[i] < B[i]):
                count += 1
                K = K - A.popleft()
                flag = False
                break
        if(flag):
            count += 1
            K = K - A.popleft()
            flag = False
    elif(A[0] < B[0]):
        count += 1
        K = K - A.popleft()
    else:
        count += 1
        K = K - B.popleft()

print(count)

Submission status: Wrong Answer

Solution code:

import sys

grid = []
for i in range(3):
    array = list(map(int, input().strip().split()))
    grid.append(array)

N = grid[0][0]
M = grid[0][1]
K = grid[0][2]
A = grid[1]
B = grid[2]

result = 0
sum = 0

if A < B:
    for i in range(N):
        sum += A[i]
        if sum > K:
            break
    if sum <= K:
        result = N
        i = result - 1
    else:
        sum -= A[i]
        result = i
    i = result -1
    tmp = result
    for j in range(M):
        sum += B[j]
        tmp += 1
        while sum > K and i >= 0:
            sum -= A[i]
            i -= 1
            tmp -= 1
        if result < tmp:
            result = tmp
        if i <= 0:
            break
else:
    for i in range(M):
        sum += B[i]
        if sum > K:
            break
    if sum <= K:
        result = M
        i = result - 1
    else:
        sum -= B[i]
        result = i
    tmp = result
    for j in range(N):
        sum += A[j]
        tmp += 1
        while sum > K and i >= 0:
            sum -= B[i]
            i -= 1
            tmp -= 1
        if result < tmp:
            result = tmp
        if i <= 0:
            break

print(result)

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()
    else:
        cnt += 1
        min += nb
        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()))
 
cnt = 0
 
while K >= 0:        
    if len(a)==0 or len(b)==0:
        if len(a)==0 and len(b)==0:
            cnt += 1
            break
        if len(a) == 0:
            K -= b.pop(0)
        else:
            K -= a.pop(0)
        
    else:
        if K < min(a[0], b[0]):
            cnt += 1
            break
        
        if a[0] <= b[0]:
            K -= a.pop(0)
        elif a[0] > b[0]:
            K -= b.pop(0)
    cnt += 1
print(cnt-1)

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


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
        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
N,M,K = map(int,input().split())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
total = 0
a = 0
b = 0
c = 0

for i in range(10000000000):
    if a + b == len(A_list) + len(B_list):
        print(c)
        sys.exit()
    elif a >= len(A_list):
        total = total + B_list[b]
        if total > K:
            print(c)
            sys.exit()
        else:
            b = b + 1
            c = c + 1
    elif b >= len(B_list):
        total = total + A_list[a]
        if total > K:
            print(c)
            sys.exit()
        else:
            a = a + 1
            c = c + 1
    else:
        if A_list[a] <= B_list[b]:
            total = total + A_list[a]
            if total > K:
                print(c)
                sys.exit()
            else:
                a = a + 1
                c = c + 1
        else:
            total = total + B_list[b]
            if total > K:
                print(c)
                sys.exit()
            else:
                b = b + 1
                c = c + 1

Submission status: Wrong Answer

Solution code:

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

# cumsum
A_cum = [0] * (N+1)
B_cum = [0] * (M+1)
ap = 0
for i, a in enumerate(A_list):
    A_cum[i+1] = ap + a
    ap += a
bp = 0
for i, b in enumerate(B_list):
    B_cum[i+1] = bp + b
    bp += b

for ai,a in enumerate(A_cum):
    if a > K:
        break

max_cnt = ai-1 
bp = 0
for i in range(ai+2):
    a = A_cum[ai]
    if a > K:
        break

    for bi in range(bp, M+1):
        b = B_cum[bi]
        if b+a > K:
            break
    bp = bi-1
    max_cnt = max(max_cnt, i+bi-1)

print(max_cnt)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

a_i = 0
b_i = 0
a_minutes = 0
b_minutes = 0
while True:
    if a_i == len(a) and b_i == len(b):
        break
    elif a_i == len(a):
        if b[b_i] + a_minutes > k:
            break
        b_minutes = b[b_i]
        b_i += 1
    elif b_i == len(b):
        if a[a_i] + b_minutes > k:
            break
        a_minutes = a[a_i]
        a_i += 1
    elif a[a_i] <= b[b_i]:
        if a[a_i] + b_minutes > k:
            break
        a_minutes = a[a_i]
        a_i += 1
    elif a[a_i] > b[b_i]:
        if b[b_i] + a_minutes > k:
            break
        b_minutes = b[b_i]
        b_i += 1

print(a_i + b_i)

Submission status: Wrong Answer

Solution code:
def smaller(a, b):
    if a and b:
        if a[-1] < b[-1]:
            return 1
        elif a[-1] > b[-1]:
            return 2
        else:
            return smaller(a[:-1], b[:-1])
    else:
        if a:
            return 1
        elif b:
            return 2
        else:
            return 0

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

t = 0
res = 0
while a or b:
    val = b.pop() if smaller(a, b) == 2 else a.pop()
    if t + val > k:
        break
    t += val
    res += 1
print(res)

Submission status: Wrong Answer

Solution code:
##C
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
##print(A+B)
C = A+B
A = A+[10**9]
B = B+[10**9]
##print(C)
i = 0
j = 0
goukei = 0
if K >= sum(C):
    print(N+M)
else:
    while goukei <= K: 
        if A[i] <= B[j]:
            goukei += A[i]
            i += 1
        else:
            goukei += B[j]
            j += 1
    print(i+j-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_i= 0
b_i= 0
f = True

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

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

    

print(a_i+b_i)

Submission status: Wrong Answer

Solution code:
N, M, K= map(int, input().split())
li = list(map(int, input().split()))
li2 = list(map(int, input().split()))
a = 0
b = 0
c = 0
count= 0
while True:
    if a < N and b < M:
        if li[a] <= li2[b] and c + li[a] <= K:
            c += li[a]
            a += 1
            count += 1
        elif li[a] >= li2[b] and c + li2[b] <= K:
            c += li2[b]
            b += 1
            count += 1
        else:
            break
    elif a < N:
        if c + li[a] <= K:
            c += li[a]
            a += 1
            count += 1
        else:
            break
    elif b < M:
        if c + li2[b] <= K:
            c += li2[b]
            b += 1
            count += 1
        else:
            break
    else:
        break
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()))
ans=0
for i in range(n):
  if sum(a[:i+1])>k:
    break
  elif sum(a[:i+1])+sum(b)<=k:
      if sum(a[:i+1])>k:
        ans=max(ans,i+m+1)
      else:
        continue
  else:  
    for j in range(m):
      if sum(a[:i+1])+sum(b[:j+1])<=k:
        continue
      else:
        ans=max(ans,i+j+1)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

A_it = list(it.accumulate(A))
B_it = list(it.accumulate(B))

A_index = bisect.bisect_left(A_it, K)
B_index = bisect.bisect_left(B_it, K)

A_it = A_it[:A_index]
B_it = B_it[:B_index]

maxs = 0
count=0
for i in A_it[::-1]:
    if K-i <= 0:
        continue
    now = K-i
    B_index = bisect.bisect_right(B_it, now)
    
    maxs = max(maxs, B_index + A_index - count)
    count+=1

print(maxs)

Submission status: Wrong Answer

Solution code:
from decimal import *
n,m,k=map(Decimal,input().split())
a=list(map(Decimal,input().split()))
b=list(map(Decimal,input().split()))

a.append(10**10)
b.append(10**10)
k/=10**9

i,j,ans=0,0,0
while k>=0:
    if a[i]>b[j]:
        k-=Decimal(b[j]/(10**9))
        j+=1
    else:
        k-=Decimal(a[i]/(10**9))
        i+=1
    ans+=1

print(ans-1)

Submission status: Wrong Answer

Solution code:
time = 0
books = 0
count_N = 0
count_M = 0

line1 = input().split()
N = int(line1[0])
M = int(line1[1])
K = int(line1[2])

Tukue1 = input().split()
Tukue2 = input().split()


while True:
  try:
    if int(Tukue1[count_N]) < int(Tukue2[count_M]):
      #机Aを読む
      time = time + int(Tukue1[count_N])
      count_N = count_N + 1
    else:
      #机Bを読む
      time = time + int(Tukue2[count_M])
      count_M = count_M + 1

    if time > K:
      break
    
    books += 1
      
  except IndexError:
    break
    
while True:
  try:
    if len(Tukue1) == count_N:
      #机Bを読む
      time = time + int(Tukue2[count_M])
      count_M = count_M + 1
    elif len(Tukue2) == count_M:
      #机Aを読む
      time = time + int(Tukue1[count_N])
      count_N = count_N + 1
    else:
      break

    if time > K:
      break

    books += 1
    
  except IndexError:
    break

print(books)

Submission status: Wrong Answer

Solution code:
N, M, K = [int(i) for i in input().split()]

As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]

cnt = 0
time = 0
while time <= K:
    if As and Bs:
        if As[0] > Bs[0]:
            p = Bs.pop(0)
        elif Bs[0] >= As[0]:
            p = As.pop(0)
    else :
        if As:
            p = As.pop(0)
        elif Bs:
            p = Bs.pop(0)
        else :
            break
    time += p
    if time > K:
        break
    cnt += 1
    
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()))
total = 0
ac = 0
bc = 0
alen = len(a)
blen= len(b)
allbook = alen + blen
count = 0
while True:
  if k < total:
    count -= 1
    break
  if bc < blen:
    if ac < alen and a[ac] <= b[bc]:
      total += a[ac]
      ac += 1
      count += 1
      continue
    else:
      total += b[bc]
      bc += 1
      count += 1
      continue
  if ac < alen:
    if bc < blen and a[ac] >= b[bc]:
      total += b[bc]
      bc += 1
      count += 1
      continue
    else:
      total += a[ac]
      ac += 1
      count += 1
      continue
  break
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A_array = np.array(list(map(int, input().split())))

B_array = np.array(list(map(int, input().split())))

time = 0
count = 0

if np.sum(A_array) + np.sum(B_array) <= K:
    print(N + M)
    
elif A_array[0] > K and  B_array[0] > K:
    print(0)
    
else:
    cumA_array = np.cumsum(A_array)
    cumB_array = np.cumsum(B_array)
    result = []
    
    for i in range(len(A_array)):
        if cumA_array[i] > K:
            break
            
        for j in  range(len(B_array)):
            if cumA_array[i] + cumB_array[j] > K:
                break
                
        result.append(i + 1 + j)
    
    print(max(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()))
import numpy as np
a=np.cumsum(A)
b=np.cumsum(B)
ida=np.where(a<=K)
idb=np.where(b<=K)
la=len(a[ida])
lb=len(b[idb])
if la>lb or (la==lb and a[la-1]<b[lb-1]):
    ans=la
    K-=a[la-1]
    for x in b:
        if K>=x:
            ans+=1
        else:
            break
elif la<lb or (la==lb and a[la-1]>b[lb-1]):
    ans=lb
    K-=b[lb-1]
    for y in a:
        if K>=y:
            ans+=1
        else:
            break
elif la==lb and a[la-1]==b[lb-1]:
    ans=la
    K-=a[la-1]
    for i in range(la):
        if a[i]<=K or b[i]<=K:
            ans+=1
        else:
            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()))
t_a=[]
t_b=[]
l=0
for i in range(N):
  l+=A[i]
  t_a.append(l)
l=0
for i in range(M):
  l+=B[i]
  t_b.append(l)

import bisect
  
ans=0
for i in range(N):
  if t_a[i]==K:
    ans=max(i+1,ans)
  elif t_a[i]<K:
    ans=max(bisect.bisect_right(t_b,K-t_a[i])+i+1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
data = input().split()
K = int(data[2])
time = 0
count = 0
A = list(map(int,input().split()))
B = list(map(int,input().split()))
while (time <= K):
    if len(A) > 0 and len(B) > 0:
        if A[0] <= B[0]:
            time += A.pop(0)
        else:
            time += B.pop(0)
    else:
        if len(A) == 0 and len(B) == 0:
            break
        elif len(A) == 0:
            time += B.pop(0)
        elif len(B) == 0:
            time += A.pop(0)
    if time > K:
        break
            
    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()))

l = a + b
l.sort()
t = 0
ans = 0
for i in l:
    t += i
    if k > t:
        ans += 1
    else:
        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()))

state=0
count=0
while(1):
  if len(A) != 0 and len(B) != 0:
    if state + A[0] > K and state + B[0] > K:
      break
  elif len(A) == 0 and len(B) != 0:
    if state + B[0] > K:
      break
  elif len(A) != 0 and len(B) == 0:
    if state + A[0] > K:
      break
  elif len(A) == 0 and len(B) == 0:
    break
  
  if len(A) != 0 and len(B) != 0:
    if A[0] < B[0]:
      state = state + A.pop(0)
      count=count+1
    elif A[0] > B[0]:
      state = state + B.pop(0)
      count=count+1
  elif len(A) == 0 and len(B) != 0:
    state = state + B.pop(0)
    count=count+1
  elif len(A) != 0 and len(B) == 0:
    state = state + A.pop(0)
    count=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()))
mx=n
mn=m
mxl=a
mnl=b
if m>n:
    mx=m
    mn=n
    mxl=b
    mnl=a
if k<a[0] and k<b[0]:
    print(0)
else:
    sm=0
    counts=[]
    i=0
    while sm<=k and i<n:
        sm+=a[i]
        i+=1
    counts.append(i)
    sm=0
    i=0
    while sm<=k and i<m:
        sm+=b[i]
        i+=1
    counts.append(i)
    sm=0
    i=0
    for j in range(mx):
        if sm<=k:
            sm+=mxl[j]
            i+=1
        if sm<=k and j<mn:
            sm+=mnl[j]
            i+=1
    for j in range(mx):
        if sm<=k and j<mn:
            sm+=mnl[j]
            i+=1
        if sm<=k:
            sm+=mxl[j]
            i+=1
          
    counts.append(i)
    print(max(counts))

Submission status: Wrong Answer

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    n,m,k = readInt()
    a = readInt()
    b = readInt()
    c = a + b
    c.sort()
    t = 0
    ans = 0
    for i in range(n+m):
        if t+c[i]<=k:
            ans += 1
            t += c[i]
        else:
            break
    print(ans)
    return

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

time = 0
count = 0
a_i = 0
b_i = 0

if sum(a) + sum(b) <= k:
    print(len(a) + len(b))
    exit()

for _ in range(n+m):
    tmp = 0
    if a_i <= len(a)-1 and b_i <= len(b)-1:
        av = a[a_i]
        bv = b[b_i]
        if av <= bv:
            time += av
            tmp = av
            a_i += 1

        elif av > bv:
            time += bv
            b_i += 1
            tmp = bv
        count += 1
    else:
        if a_i >= len(a):
            bv = b[b_i]
            time += bv
            tmp = bv
            b_i += 1
        elif b_i >= len(b):
            av = a[a_i]
            time += av
            tmp = av
            a_i += 1
        count += 1

    if time > k:
        time -= tmp
        count -= 1
        break
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()))
import bisect

class Cumulative_Sum:
    def __init__(self, a):
        la = len(a)
        self.s = [0] * (la + 1)
        for i in range(la):
            self.s[i+1] = self.s[i] + a[i]
    # s[l]からs[r]までの和
    def sum(self, l, r):
        return self.s[r] - self.s[l]
csa = Cumulative_Sum(a)
csb = Cumulative_Sum(b)
#print(csa.s)
#print(csb.s)
ans = 0
for i in range(n+1):
    t = csa.s[i]
    #if t > k:
    #    continue
    p = k - t
    bi = bisect.bisect_left(csb.s, p)
    if csb.s[m] <= p:
        ans = max(ans, i + m)
    else:
        ans = max(ans, i + 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()))
ans = 0
i, j = 0, 0
while True:
    if i<N:
        a = A[i]
    else:
        a = float('inf')
    if j<M:
        b = B[j]
    else:
        b = float('inf')
    if (a==float("inf") and b==float("inf")):
        i += 1
        break
    if ans>K:
        break
    if a<=b:
        ans += a
        i += 1
    else:
        ans += b
        j += 1
print(i+j-1)

Submission status: Wrong Answer

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

ASUM = [0]
for i in range(len(AN)):
    value = ASUM[-1] + AN[i]
    if value <= K:
        ASUM.append(value)

ABSUM = [ASUM]
for i in range(len(BN)):
    BSUM = []
    for j in range(len(ABSUM[i])):
        tmp = ABSUM[i][j]+BN[i]
        if tmp <= K:
            BSUM.append(tmp)
    if len(BSUM) == 0:
        break
    else:
        ABSUM.append(BSUM)
# print(ABSUM)

maxbooks = 0
for i in range(len(ABSUM)):
    maxbooks= max(maxbooks, (len(ABSUM[i]) + i -1))
print(maxbooks)

Submission status: Wrong Answer

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

    sai = sum(a) + sum(b)
    if sai <= k: return n + m
    if a[0] > k and b[0] > k: return 0
    cnt = 0
    su = 0
    a.reverse()
    b.reverse()
    while su <= sai - k:
        if a and b:
            su += max(a[0], b[0])
            if a[0]>=b[0]:
                a.pop(0)
            else:
                b.pop(0)
            cnt += 1
        elif not a and not b:
            break
        elif not a:
            su += b[0]
            b.pop(0)
            cnt += 1
        elif not b:
            su += a[0]
            a.pop(0)
            cnt += 1

    return (n+m) - (cnt-1)


print(solve())

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = [int(x) for x in input().split()]
A = [float(x) for x in input().split()]
B = [float(x) for x in input().split()]

AB = list()
a = 0
b = 0
for i in range(N+M):
  if ((a < N) and (b < M)):
    if(A[a] == B[b]):
      AB.append(A[a])
      a += 1
      AB.append(B[b])
      b += 1
    elif(A[a] < B[b]):
      AB.append(A[a])
      a += 1
    else:
      AB.append(B[b])
      b += 1
  elif(a >= N):
    for j in range(M-b):
      AB.append(B[b])
      b += 1
    break
  elif(b >= M):
    for j in range(N-a):
      AB.append(A[a])
      a += 1
    break

ans = 0
K = float(K)
while K >= 0:
  K -= AB[ans]
  ans += 1
  if(ans == (N+M)):
    print(N+M)
    sys.exit()
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

WA = [0] * (N + 1)
WB = [0] * (M + 1)
for i in range(N):
    WA[i + 1] = WA[i] + A[i]
for j in range(M):
    WB[j + 1] = WB[j] + B[j]
ma = 0
for i in range(N + 1):
    t = K - WA[i]
    j = bisect.bisect(WB, t)
    ma = max(ma, i + j - 1)

print(ma)

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

read = 0
i, j = 0, 0
flag = True
while(i<len(a) and j<len(b)):
    if a[i] < b[j]:
        flag = True
    elif a[i] == b[j]:
        flag = True if sum(a[i:]) < sum(b[j:]) else False
    else:
        flag = False

    if flag:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k<0:
        break
    read += 1

if k > 0:
    if i==len(a):
        while(j < len(b)):
            k -= b[j]
            j += 1
            if k<0:
                break
            read += 1
    elif j==len(b):
        while(i < len(a)):
            k -= a[i]
            i += 1
            if k<0:
                break
            read += 1

print(read)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

R = lambda: map(int, input().split())
*_, k = R()
a = accumulate(R())
b = list(accumulate(R()))
r = 0
for i, x in enumerate(a, 1):
  j = bisect_right(b, k - x)
  if j == 0:
    break
  r = max(r, i + j) 
print(r)

Submission status: Wrong Answer

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

A.append(1000000001)
B.append(1000000001)

res = -1

for i in range(len(A)+len(B)):
    if  K >= 0:
        if A[0] <= B[0]:
            K -= A.pop(0)
        else:
            K -= B.pop(0)
        res += 1
    else:
        break

print(res)

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=[0]*N
b=[0]*M
a[0]=A[0]
b[0]=B[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i]
for i in range(M-1):
    b[i+1]=b[i]+B[i]
diff=2*10**9
count=0
for i in range(N):
    j=bisect.bisect_left(b,K-a[i])-1
    if 0<=K-(a[i]+b[j])<diff:
        diff=K-(a[i]+b[j])
        count=(i+1)+(j+1)
for j in range(M):
    i=bisect.bisect_left(a,K-b[j])-1
    if 0<=K-(a[i]+b[j])<diff:
        diff=K-(a[i]+b[j])
        count=(i+1)+(j+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()))

S = [0]

Sum = 0


for i in range(N):
  K = K - A[i]
  if K >= 0:
    Sum += 1
  else:
    K = K + A[i]
    break
S.append(Sum)

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if i == 0:
      break
    while(K<0):
      i = i - 1
      K = K + A[i]
      Sum = Sum - 1
    Sum += 1
  S.append(Sum)
print(max(S))

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

t = 0
m = 0
cnt = 0

if (sum(A) + sum(B)) <= K:
    print(N + M)
    sys.exit()
elif A[0] >= K or B[0] >= K:
    print(cnt)
    sys.exit()

while True:
    if t > K:
        print(cnt-1)
        sys.exit()
    elif t == K:
        print(cnt)
        sys.exit()

    if len(A) == 0:
        m = B[0]
    elif len(B) == 0:
        m = A[0]
    else:
        m = min(A[0], B[0])

    t += m
    cnt += 1

    if len(A) != 0 and m == A[0]:
        A.pop(0)
    elif len(B) != 0 and m == B[0]:
        B.pop(0)

Submission status: Wrong Answer

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

A.append(10**9)
B.append(10**9)
cnt=0
for i in range(N+M):
    if A[0]>B[0]:
        K-=B[0]
        B.pop(0)
    else:
        K-=A[0]
        A.pop(0)
    if K>=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()))
total=0
i=0
j=0

while total<K:    
    if i<N and j<M:
        if a[i]>=b[j]:
            if total+b[j]<=K:
                total+=b[j]
                j+=1
            else:
                break
        else:
            if total+a[i]<=K:
                total+=a[i]
                i+=1
            else:
                break
    elif N<i:
        if total+b[j]<=K:
            total+=b[j]
            j+=1
        else:
            break
    elif M<j:
        if total+a[i]<=K:
            total+=a[i]
            i+=1
        else:
            break
print(i+j)