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

pointer_A = 0
pointer_B = 0

left_to_read = len(A) + len(B)
total = 0

while left_to_read > 0:
    Ai = float('inf')
    Bi = float('inf')
    if pointer_A < len(A):
        Ai = A[pointer_A]
    if pointer_B < len(B):
        Bi = B[pointer_B]
    if min(Ai, Bi) > K:
        break
    elif Ai <= Bi:
        pointer_A += 1
        K -= Ai
    else:
        pointer_B += 1
        K -= Bi
    total += 1

print(total)

Submission status: Wrong Answer

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


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


sys.setrecursionlimit(20000000)

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


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    book = []
    flag_b = 0
    for i in range(N):
        a = A[i]
        while flag_b < M:
            if B[flag_b] <= a:
                book.append(B[flag_b])
                flag_b += 1
            else:
                break
        book.append(a)
    while flag_b < M:
        book.append(B[flag_b])
        flag_b += 1
    # print(book)

    tsundoku = list(accumulate(book))
    # print(tsundoku)
    answer = bisect(tsundoku, K)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
import bisect as bs
n,m,s=map(int, stdin.readline().split())
dn=list(map(int, stdin.readline().split()))
dm=list(map(int, stdin.readline().split()))
pre=[dm[0]];s1=0
for v in dm[1:]:
    pre+=[pre[-1]+v]
m=bs.bisect_right(pre,s)
for i in range(n):
    s1+=dn[i]
    if s-s1>0:m=max(m,i+1+bs.bisect_right(pre,s-s1))
print(m)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
import bisect as bs
n,m,s=map(int, stdin.readline().split())
dn=list(map(int, stdin.readline().split()))
dm=list(map(int, stdin.readline().split()))
pre=[dm[0]];s1=0
for v in dm[1:]:
    pre+=[dm[-1]+v]
m=bs.bisect_right(pre,s)
for i in range(n):
    s1+=dn[i]
    if s-s1>0:m=max(m,i+1+bs.bisect_right(pre,s-s1))
print(m)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
import bisect as bs
n,m,s=map(int, stdin.readline().split())
dn=list(map(int, stdin.readline().split()))
dm=list(map(int, stdin.readline().split()))
pre=[dm[0]];s1=0
for v in dm[1:]:
    pre+=[dm[-1]+v]
m=bs.bisect(pre,s)
for i in range(n):
    s1+=dn[i]
    if s-s1>0:m=max(m,i+1+bs.bisect(pre,s-s1))
print(m)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
import bisect as bs
n,m,s=map(int, stdin.readline().split())
dn=list(map(int, stdin.readline().split()))
dm=list(map(int, stdin.readline().split()))
pre=[dm[0]];s1=0
for v in dm[1:]:
    pre+=[dm[-1]+v]
m=bs.bisect(pre,s)
for i in range(n):
    s1+=dn[i]
    if s-s1>=0:m=max(m,i+1+bs.bisect(pre,s-s1))
print(m)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector
from collections import deque as que
inin = lambda: int(input())
inar = lambda: list(map(int,input().split()))
from heapq import heappush as hpush,heappop as hpop

n,m,k=inar()
a=inar()
b=inar()
def top(x):
	if x==[]:
		return float('inf')
	else:
		return x[-1]
ans=0
while(k>0):
	if top(b)==top(a)==float('inf'):
		break
	if top(a)<top(b):
		ans+=1
		k-=top(a)
		a.pop()
	elif top(b)<=top(a):
		ans+=1
		k-=top(b)
		b.pop()
	else:
		k-=k
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c = map(int,input().split())
lis1=list(map(int,input().split()))
lis2=list(map(int,input().split()))
s=0
d=0
i=0
j=0
while(s<=c and i<len(lis1) and j<len(lis2)):
  if(lis1[i]<=lis2[j]):
    s+=lis1[i]
    i+=1
    d+=1
  else:
    s+=lis2[j]
    j+=1
    d+=1
if(s>c):
  print(d-1)
elif(i==len(lis1)):
  while(s<=c and j<len(lis2)):
    s+=lis2[j]
    d+=1
    j+=1
  print(d if s<=c else d-1)
else:
  while(s<=c and i<len(lis1)):
    s+=lis1[i]
    d+=1
    i+=1
  print(d if s<=c else d-1)

Submission status: Wrong Answer

Solution code:
a,b,c = map(int,input().split())
lis1=list(map(int,input().split()))
lis2=list(map(int,input().split()))
s=0
d=0
i=0
j=0
while(s<=c and i<len(lis1) and j<len(lis2)):
  if(lis1[i]<=lis2[j]):
    s+=lis1[i]
    i+=1
    d+=1
  else:
    s+=lis2[j]
    j+=1
    d+=1
if(s>c):
  print(d-1)
elif(i==len(lis1)):
  while(s<=c and j<len(lis2)):
    s+=lis2[j]
    d+=1
    j+=1
  print(d)
else:
  while(s<=c and i<len(lis1)):
    s+=lis1[i]
    d+=1
    i+=1
  print(d)

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_time = 0
books = 0
pA = -1
pB = -1
for i in range(len(A)):
    total_time += A[i]
    books += 1
    if total_time > k:
        total_time -= A[i]
        books -= 1
        break
    pA = i
    
if i == len(A) - 1:
    for j in range(len(B)):
        total_time += B[j]
        books += 1
        if total_time > k:
            total_time -= B[j]
            books -= 1
            break
        pB = j
else:
    pB = 0

max_books = books
#print(max_books)

for l in B[pB:]:
    total_time += l
    books += 1
    while pA > 0 and total_time > k:
        pA -= 1
        total_time -= A[pA]
        books -= 1
    if total_time <= k:
        max_books = max(max_books, books)

print(max_books)

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_time = 0
books = 0
pA = -1
pB = -1
for i in range(len(A)):
    total_time += A[i]
    books += 1
    if total_time > k:
        total_time -= A[i]
        books -= 1
        break
    pA = i
    
if i == len(A) - 1:
    for j in range(len(B)):
        total_time += B[j]
        books += 1
        if total_time > k:
            total_time -= B[j]
            books -= 1
            break
        pB = j
else:
    pB = 0

max_books = books
#print(max_books)

for l in B[pB:]:
    total_time += l
    books += 1
    while pA > 0 and total_time > k:
        pA -= 1
        total_time -= A[pA]
        books -= 1
    if total_time <= k:
        max_books = max(max_books, books)
    else:
        books -= 1
        break
print(max_books)

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 Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
a.insert(0,0)
b = Cum(B)
b.insert(0,0)


def f(X,x,target):
    return X[x]-target

def nibutan(X):
    num = list(range(len(X)))
    lo = 0
    hi = len(X)
    while hi-lo>=2:
        mid = (lo+hi)//2
        if f(X,mid,Y)<=0:
            lo = mid
        else:
            hi = mid
    return lo

ans = 0
for i in range(N):
    if K-a[i]>=0:
        Y = K-a[i]
        ans = max(nibutan(b)+i,ans)
    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()))


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
b = Cum(B)

def f(X,x,target):
    return X[x]-target

def nibutan(X):
    num = list(range(len(X)))
    lo = 0
    hi = len(X)
    while hi-lo>=2:
        mid = (lo+hi)//2
        if f(X,mid,Y)<=0:
            lo = mid
        else:
            hi = mid
    return lo

ans = 0
for i in range(N):
    if K-a[i]>=0:
        Y = K-a[i]
        ans = max(nibutan(b)+i+1+(Y>=b[0]),ans)
    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()))


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
b = Cum(B)

def f(X,x,target):
    return X[x]-target

def nibutan(X):
    num = list(range(len(X)))
    lo = 0
    hi = len(X)
    while hi-lo>=2:
        mid = (lo+hi)//2
        if f(X,mid,Y)<=0:
            lo = mid
        else:
            hi = mid
    return lo

ans = 0
for i in range(N):
    if K-a[i]>=0:
        Y = K-a[i]
        ans = max(nibutan(b)+i+1+(Y>=b[0]),ans)
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()))


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
b = Cum(B)

def f(X,x,target):
    return X[x]-target

def nibutan(X):
    num = list(range(len(X)))
    lo = 0
    hi = len(X)
    while hi-lo>=2:
        mid = (lo+hi)//2
        if f(X,mid,Y)<=0:
            lo = mid
        else:
            hi = mid
    return lo

ans = 0
for i in range(N):
    if K-a[i]>=0:
        Y = K-a[i]
        ans = max(nibutan(b)+i+1+(Y>b[0]),ans)
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()))


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
b = Cum(B)

def f(X,x,target):
    return X[x]-target

def nibutan(X):
    num = list(range(len(X)))
    lo = 0
    hi = len(X)
    while hi-lo>=2:
        mid = (lo+hi)//2
        if f(X,mid,Y)<=0:
            lo = mid
        else:
            hi = mid
    return lo

ans = 0
for i in range(N):
    if K-a[i]>=0:
        Y = K-a[i]
        ans = max(nibutan(b)+i+2,ans)
print(ans)

Submission status: Wrong Answer

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

T=0
cnt=0
while(T<=K):
    if len(A)*len(B)!=0:
        if A[0]<B[0]:
            T+=A.popleft()
        else:
            T+=B.popleft()
    elif len(A)==0 and len(B)!=0:
        T+=B.popleft()
    elif len(A)!=0 and len(B)==0: 
        T+=A.popleft()
    else:
        cnt+=1
        break
    cnt+=1
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()))

import numpy as np
C=np.array(sorted(A+B)).cumsum()

import bisect
print(bisect.bisect_left(C, K))

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
C=np.array(sorted(A+B)).cumsum()

import bisect
print(bisect.bisect_left(C-0.1, K))

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
SA,SB = [0 for i in range(N+1)],[0 for i in range(M+1)]
ra,rb = 0,0
flag = 0
r = 0

for i in range(N):
    SA[i+1] = SA[i] + A[i]
    
for i in range(M):
    SB[i+1] = SB[i] + B[i]

for i in range(N+1):
    if SA[i]<=K:
        ra = i

K = K - SA[ra]

for i in range(M+1):
    if SB[i]<=K:
        rb = i

K = K - SB[rb]
r = ra + rb
if rb == M:
    flag = 1

for i in range(ra+1):
    if flag == 1:
        break
    ra = ra - 1
    K = K+A[ra]
    sj = 0
    while rb<M:
        sj = sj + B[rb]
        if sj <= K:
            rb = rb+1
        else:
            sj = sj - B[rb]
            break
    K = K - sj
    r = max(r,ra+rb)
    if rb == M:
        flag = 1

print(r)

Submission status: Wrong Answer

Solution code:
N,M,K=(int(x) for x in input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A.append(10**10)
B.append(10**10)
#A.extend(B)
#l=A.sort()

i=0
j=0
k=0

while K>=0:
  if A[i]<=B[j]:
    K=K-A[i]
    i+=1
  else:
    K=K-B[j]
    j+=1
    
  k+=1
  
print(k-1)

Submission status: Wrong Answer

Solution code:
from itertools import chain


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

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

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain and idx_b >= 0:
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b

        i += idx_b
        answer = i if answer < i else answer

    return answer


def main():
    print(solve)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    maxB = len(B)

    Asum = [0] * (200000 + 1)
    Bsum = [0] * (200000 + 1)

    maxA = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    ans = maxA
    prevmax = 0
    Bsum[0] = B[0]
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            if Bsum[j] == 0:
                Bsum[j] = (Bsum[j-1] + B[j])
            if Asum[i] + Bsum[j] <= K:
                if ans < i + (j+1):
                    ans = i + (j+1)
                    prevmax = j

                if j == maxB - 1:
                    print(ans)
                    exit()
            else:
                break


    print(ans)

main_sum()

Submission status: Wrong Answer

Solution code:
from itertools import chain


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

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

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain:
            if idx_b < 0:
                break
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b

        answer = i + idx_b

    return answer


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    maxB = len(B)

    Asum = [0] * (200000 + 1)
    Bsum = [0] * (200000 + 1)

    maxA = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    ans = maxA
    prevmax = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            if Bsum[j+1] == 0:
                Bsum[j+1] = (Bsum[j] + B[j])
            if Asum[i] + Bsum[j] <= K:
                if ans < i + (j + 1):
                    ans = i + (j + 1)
                    prevmax = j

                if j == maxB - 1:
                    print(ans)
                    exit()
            else:
                break


    print(ans)

main_sum()

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    maxB = len(B)

    Asum = [0] * (200000 + 1)

    maxA = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    ans = maxA
    prevmax = 0
    Bsum = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            Bsum += B[j]
            if Asum[i] + Bsum <= K:
                if ans < i + (j + 1):
                    ans = i + (j + 1)
                    prevmax = j

                if j == maxB - 1:
                    print(ans)
                    exit()
            else:
                break


    print(ans)

main_sum()

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    maxB = len(B)

    Asum = [0] * (200000 + 1)

    maxA = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    ans = maxA
    prevmax = 0
    Bsum = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            Bsum += B[j]
            if Asum[i] + Bsum <= K:
                if ans < i + (j + 1):
                    ans = i + (j + 1)
                    prevmax = j
                    if j == maxB - 1:
                        print(ans)
                        exit()
            else:
                if j == maxB - 1:
                    print(ans)
                    exit()
                break


    print(ans)

main_sum()

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    maxB = len(B)

    Asum = [0] * (200000 + 1)

    maxA = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    ans = 0
    prevmax = 0
    Bsum = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            Bsum += B[j]
            if Asum[i] + Bsum <= K:
                if ans < i + (j + 1):
                    ans = i + (j + 1)
                    prevmax = j
                    if j == maxB - 1:
                        print(ans)
                        exit()
            else:
                if j == maxB - 1:
                    print(ans)
                    exit()
                break


    print(ans)

main_sum()

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 = sum(A)
i = N
ans = 0

for j in range(M + 1):
  while i > 0 and t > K:
    i -= 1
    t -= A[i] 
  print(t)
  if t > K:
    break
  ans = max(ans, i + j)
  if j == M:
    break
  t += B[j]
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
n, m, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

list_AS = []
list_BS = []
a = 0
b = 0
for i in list_A:
    a += i
    list_AS.append(a)
list_BS.append(0)
for i in list_B:
    b += i
    list_BS.append(b)
ans = 0
for i in range(n):
    j = bisect(list_BS, k-list_AS[i])
    if list_AS[i] + list_BS[j-1] <= k:
        ans = max(ans, i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n, m, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

list_AS = []
list_BS = []
a = 0
b = 0
for i in list_A:
    a += i
    list_AS.append(a)

for i in list_B:
    b += i
    list_BS.append(b)
ans = 0

for i in range(n):
    j = bisect_left(list_BS, k-list_AS[i])
    if list_AS[i] + list_BS[j-1] <= k:
        ans = max(ans, i+j+1)

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
n, m, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

list_AS = []
list_BS = []
a = 0
b = 0
for i in list_A:
    a += i
    list_AS.append(a)

for i in list_B:
    b += i
    list_BS.append(b)
ans = 0

for i in range(n):
    j = bisect(list_BS, k-list_AS[i])
    if j != 0 and list_AS[i] + list_BS[j-1] <= k:
        ans = max(ans, i+j+1)

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = 0
    maxB = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    add = 0
    for i in range(1,B_len+1):
        add += B[i-1]
        Bsum[i] = add
        if add <= K:
            maxB = i + 1
        else:
            break

    ans = 0
    prevmax = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            if Asum[i] + Bsum[j] <= K:
                if ans < i + j:
                    ans = i + j
                    prevmax = j
            elif j == maxB -1:
                print(ans)
                exit()

    print(ans)

main_sum()

Submission status: Wrong Answer

Solution code:
from bisect import bisect
n, m, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

list_AS = []
list_BS = []
a = 0
b = 0
for i in list_A:
    a += i
    list_AS.append(a)

for i in list_B:
    b += i
    list_BS.append(b)
ans = 0

for i in range(n):
    j = bisect(list_BS, k-list_AS[i])
    ans = max(ans, i + j + 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()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui.append(a[i] + arui[i])
for i in range(M):
    brui.append(b[i] + brui[i])

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

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]

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

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from itertools import accumulate

N, M, K, *AB = map(int, open(0).read().split())
A, B = AB[:N], AB[N:]

A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))

ans = 0
for i, a in enumerate(A):
    if K - a <= 0:
        break
    ans = max(ans, bisect_right(B, K - a) + i - 1)

print(ans)

Submission status: Wrong Answer

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

dpA = [0]*(N+1)
dpB = [0]*(M+1)

for i in range(1,N+1):
    dpA[i] = dpA[i-1] + A[i-1]

for i in range(1,M+1):
    dpB[i] = dpB[i-1] + B[i-1]

ans = 0
for i in range(1,N+1):
    if dpA[i] > K:
        continue
    indexB = bisect.bisect_right(dpB, K - dpA[i])
    ans = max(ans, i + indexB - 1)

print(ans)

Submission status: Wrong Answer

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

ruisekiA = [0]
ruisekiB = [0]
tmpA=0
tmpB=0
for i in range(len(A)):
    tmpA += A[i]
    ruisekiA.append(tmpA)
for i in range(len(B)):
    tmpB += B[i]
    ruisekiB.append(tmpB)
ans = 0
for i in range(len(ruisekiA)):
    #tmp = ruisekiA[i]
    l = -1
    r = len(ruisekiB)
    while r - l > 1:
        mid = (r + l)//2
        tmp = ruisekiA[i]+ruisekiB[mid]
        if tmp <= K:
            l = mid
        else:
            r = mid
    ans = max(ans, i+l)
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 = [0]
B = [0]
for i in range(n):
	A.append(A[i]+a[i])
for j in range(m):
	B.append(B[j]+b[j])

#print(A,B)

maxij = 0
l = m
for i in range(n+1):
	for j in range(m):
#		print(i,l,A[i],B[l],k)
		if(l == 0):
			break
		elif((A[i]+B[l]) <= k):
		 	maxij=max(maxij,i+l)
#		 	print("mm",maxij)
		 	break
		else:
		 	l-=1
print(maxij)

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

dpA = [0]*(N+1)
dpB = [0]*(M+1)
maxIndexA = 0
maxIndexB = 0

for i in range(1,N+1):
    dpA[i] = dpA[i-1] + A[i-1]
    maxIndexA += 1
    if dpA[i] >= K:
        break
for i in range(1,M+1):
    dpB[i] = dpB[i-1] + B[i-1]
    maxIndexB += 1
    if dpB[i] >= K:
        break

ans = 0
for i in range(1,maxIndexA+1):
    if dpA[i] > K:
        break
    for j in range(1,maxIndexB+1):
        if dpB[j] > K - dpA[i]:
            j = j-1
            break
    ans = max(ans, i+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()))
a.append(10**9+1)
b.append(10**9+1)
acnt = 0
bcnt = 0
ans = 0
cnt = 0

while cnt < k:
    if a[acnt] > b[bcnt]:
        if cnt + b[bcnt] > k:
            break
        else:
            cnt += b[bcnt]
            ans += 1
            bcnt += 1
    else:
        if cnt + a[acnt] > k:
            break
        else:
            cnt += a[acnt]
            ans += 1
            acnt += 1        

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * (n + 1)
d = [0] * (m + 1)

for i in range(n):
  c[i+1] = c[i]+a[i]
for i in range(m):
  d[i+1] = d[i]+b[i]
  
cnt = 0
  
for i in range(n+1):
  e = bisect.bisect_right(d, k-c[i])
  if cnt < i + e -1:
    cnt =  i + e -1
print(cnt)

Submission status: Wrong Answer

Solution code:
"""everything has a cost!"""

from math import *
import random, functools, collections, sys

__author__ = 'p7x'


# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
# sys.stderr = open('err.txt', 'w')


if __name__ == '__main__':
    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]

    j = len(b)-1
    while j > -1 and b[j] > k:
        j -= 1
    ans = j+1
    i = len(a)-1
    while i > -1 and a[i] > k:
        i -= 1
    ans = max(i+1,ans)

    for inx in range(i+1):
        while j > -1 and a[inx] + b[j] > k:
            j -= 1
        ans = max(i+j+2,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cmplst = a + b
cmplst.sort()
rui = [0] * (N + M + 1)
for i in range(N + M):
    rui[i + 1] += cmplst[i] + rui[i]

tmp = bisect.bisect_left(rui, K)
if rui[tmp] == K:
    print(tmp)
else:
    print(tmp - 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()))
b_num = sum(b)
b_best = M-1
j = M-1
a_num = 0
maxmize = 0
for i in range(N):
  #print(i)
  X = 0
  a_num += a[i]
  if a_num>K:
    break
  X +=a_num
  handan = True
  j = b_best
  while handan ==True:
    #print('max',maxmize)
    X +=b_num
    #print(X,K)
    if X<=K:
      b_best = j
      maxmize = max(i+j+2,maxmize)
      handan=False
    else:
      X -=b_num
      b_num -=b[j]
      j-=1
    #print('max1',maxmize)
    
print(maxmize)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
MAX = 10**10

ret = 0
acount = 0
bcount = 0
while True:
	aa = MAX
	bb = MAX
	if(acount == n)and(bcount == m):
		break
	if(acount != n):
		aa = a[acount]
	if(bcount != m):
		bb = b[bcount]
	#print(acount,bcount,aa,bb,k,ret)
	if(aa < bb):
		if(aa <= k):
			k -= aa
			ret += 1
			acount += 1
		else:
			break
	else:
		if(bb <= k):
			k -= bb
			ret += 1
			bcount += 1
		else:
			 break
print(ret)

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()))
acc = sum(B)
j = M - 1
if K >= acc + sum(A):
    print(M + N)
    exit()
ans = 0 if K < acc else M
for i in range(N):
    acc += A[i]
    if K >= acc:
        ans = max(ans, i + j + 2)
        continue
    else:
        while (K < acc) & (j > -1):
            acc -= B[j]
            j -= 1
        if K >= acc:
            ans = max(ans, i + j + 2)
print(ans)