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:
def main():
    n, m, k = map(int,input().split())
    from collections import deque
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    if sum(a)+sum(b) <= k:
        print(m+n)
        return 0
    if a[0] > k and b[0] > k:
        print(0)
        return 0
    ad = deque(a)
    bd = deque(b)
    cnt = 0
    inf = 10**18
    p = inf
    q = inf
    while True:
        if p == inf and ad:
            p = ad.popleft()
        if q == inf and bd:
            q = bd.popleft()
        if p < q:
            n -= 1
            k -= p
            p = inf
        else:
            m -= 1
            k -= q
            q = inf
        if k >= 0:
            cnt += 1
        if k <= 0:
            break
    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()))
a = -1
b = -1
total = 0
ans = 0
while a<len(A)-1:
    if total+A[a+1] > K:
        break
    a+=1
    total+=A[a]
    
while b<len(B)-1:
    if total+B[b+1] > K:
        break
    b+=1
    total+=B[b]
    
ans = a+b+2
subs = 0
while a>=0:
    subs+=A[a]
    a-=1
    for i in range(b+1, len(B)):
        if subs < B[i]:
            break
        subs-=B[i]
        b = i
    ans = max(ans,a+b+2)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split()) 
arr = input() 
A= list(map(int,arr.split(' '))) 
i=0
la=len(A)
B= list(map(int,arr.split(' '))) 
lb=len(B)
for x in range(la):
    if(A[x]<K):
        K=K-A[0]
        i=i+1
    for y in range(lb):
    	if(B[y]<K):
        	K=K-B[0]
        	i=i+1
print(i)

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

#print(A)

cut = 0

s = 0
D =[]
F =[]

for i in range(100):
    if A[0] <= B[0]:
        s = s + A[0]
        if s > K:
            break
        elif s < K:
            del A[0]
            cut += 1
            if len(A)== 0:
                D.append(1)
                break
        elif s == K:
            cut += 1
            break
    else:
        s = s + B[0]
        if s > K:
            break
        elif s < K:
            del B[0]
            cut += 1
            if len(B)== 0:
                F.append(1)
                break
        elif s == K:
            cut += 1
            break


if len(D) == 1:
    for j in range(100):
        s = s + B[0]
        if s > K:
            break
        elif s < K:
            del B[0]
            cut += 1
        elif s == K:
            cut += 1
            break

if len(F) == 1:
    for jj in range(100):
        s = s + A[0]
        if s > K:
            break
        elif s < K:
            del A[0]
            cut += 1
        elif s == K:
            cut += 1
            break
              
        
print(cut)

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 Main(N, M, K, A, B):
    i = j = 0
    ans = 0
    read = 0
    while read <= K:
        if i < N and j < M:
            if A[i] <= B[j]:
                read += A[i]
                i += 1
            else:
                read += B[j]
                j += 1
            ans += 1
        elif i < N and j == M:
            read += A[i]
            i += 1
            ans += 1
        elif j < M and i == N:
            read += B[j]
            j += 1
            ans += 1
        else:
            break
    if read > K:
        return ans-1
    else:
        return ans
            
        
                    
out = Main(N, M, K, A, B)
print(out)

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

for i in range(N+M):

    if N != 0 and M != 0:
        if A[Acount] < B[Bcount]:
            if K >= A[Acount]:
                K = K - A[Acount]
                Acount = Acount + 1
                N = N-1
        elif A[Acount] > B[Bcount]:
            if K >= B[Bcount]:
                K = K - B[Bcount]
                Bcount = Bcount +1
                M = M-1
    elif N == 0 and M != 0:
        if K >= B[Bcount]:
                K = K - B[Bcount]
                Bcount = Bcount +1
                M = M-1
    elif N != 0 and M == 0:
        if K >= A[Acount]:
            K = K - A[Acount]
            Acount = Acount +1
            N = N-1
                

print(Acount + Bcount)

Submission status: Wrong Answer

Solution code:
n, m , has_time = [int(x) for x in input().split()]
nb = [int(x) for x in input().split()][::-1]
mb = [int(x) for x in input().split()][::-1]
done = 0
read = 0
while mb or nb:
    if mb and nb:
        if mb[-1] < nb[-1]:
            done += mb.pop()
        else:
            done += nb.pop()
    elif mb:
        done += mb.pop()
    else:
        done += nb.pop()
    if done <= has_time:
        read += 1
    else:
        break
print(read)

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
    for a in ra:
        if a > K:
            na = na - 1
        else:
            break
    nb = M
    for b in rb:
        if b > K:
            nb = nb -1
        else:
            break
    # print(na, nb)
    if na == 0 and nb == 0:
        print(0)
        return
    elif na == 0:
        print(nb)
        return
    elif nb == 0:
        print(na)
        return

    ra = ra[-na:]
    rb = rb[-nb:]
    # print(ra)
    # print(rb)
    ia = 0
    ib = 0

    ta = ra[0]
    tb = rb[0]
    while ta + tb > K:
        # print(ta, tb)
        if ra[ia] > rb[ib]:
            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:
# import io
# import sys

# _INPUT = """\
# 1 4 10
# 100
# 80 150 80 150
# """
# sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

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

if sum(A) + sum(B) <= K:
  ans = len(A) + len(B)
  print(ans)
  exit()


A = A + [K+1]
B = B + [K+1]
a = b = k = ans = 0

p(A)
p(B)
while True:
  if A[a] < B[b]:
    k += A[a]
    a += 1
  else:
    k += B[b]
    b += 1

  if k > K: break
  ans += 1
  p(K, k, a, b, ans)


p(K, k, a, b, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)

def func(arr, b):
	return([i-b for i in arr])

# def f(i, j, t):
# 	if t >=k:
# 		return(i+j)
# 	return(max(f(i+1, j, t+a_[i+1]), f(i, j+1, t+b_[j+1])))



def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	# dic = {}
	# def f(i, j, t):
	# 	# print(i, j, t, "******")
	# 	key = (i, j, t)
	# 	if key in dic:
	# 		return(dic[key])
	# 	if t == k:
	# 		# print(i, j, t, "11111")
	# 		dic[key] = i+j
	# 		return(dic[key])
	# 	if t > k:
	# 		# print(i, j, t, "22222")
	# 		dic[key] = i+j-1
	# 		return(dic[key])
	# 	if i ==a and j ==b:
	# 		# print(i, j, t, "0"*5)
	# 		dic[key] = i+j
	# 		return(dic[key])
	# 	if i == a:
	# 		dic[key] = f(i, j+1, t + b_[j])
	# 		return(dic[key])
	# 	if j == b:
	# 		dic[key] = f(i+1, j, t + a_[i])
	# 		return(dic[key])
		

	# 	x = f(i+1, j, t+a_[i]) if i < a else 0#f(i+1, j, t)
	# 	y = f(i, j+1, t+b_[j]) if j < b else 0#f(i, j+1, t)
	# 	dic[key] = max(x, y)
	# 	return(dic[key])

	for i in range(1, a): a_[i] += a_[i-1]
	for i in range(1, b): b_[i] += b_[i-1]
	ans = 0
	while k > 0:
		inda = bisect(a_, k); indb = bisect(b_, k)
		# print(k, inda, indb,a_, b_)
		if inda == 0 and indb == 0:
			break
		if inda == 0:
			k -= b_[indb-1];
			ans += indb
			b_ = func(b_[indb:], b_[indb-1])
		elif indb == 0:
			k -= a_[inda-1];
			ans += inda
			a_ = func(a_[inda:], a_[inda-1])
		elif inda > indb:
			k -= a_[inda-1];
			ans += inda
			a_ = func(a_[inda:], a_[inda-1])
		elif inda == indb:
			if a_[inda-1] < b_[indb-1]:
				k -= a_[inda-1];
				ans += inda
				a_ = func(a_[inda:], a_[inda-1])
			else:
				k -= b_[indb-1];
				ans += indb
				b_ = func(b_[indb:], b_[indb-1])
		else:
			k -= b_[indb-1];
			ans += indb
			b_ = func(b_[indb:], b_[indb-1])
		# print(k, inda, indb,a_, b_, "*********")

	# ans = f(0, 0, 0)
	# print(dic)
	print(ans)





		

if __name__ == "__main__":
	solve()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a= [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_i=0
b_i=0
a_c=0
b_c=0
for i in a:
    a_c+=i
    if a_c>k:
        a_c-=i
        break
    a_i+=1
for i in b:
    b_c+=i
    if b_c>k:
      b_c-=i
      break
    b_i+=1
if a_c+b_c<=k:
    print(a_i+b_i)
else:
    for j in a:
      b_c+=j
      if b_c>k:
        break
      b_i+=1
    for j in b:
      a_c+=j
      if a_c>k:
        break
      a_i+=1
    if a_i>b_i:
      print(a_i)
    else:
      print(b_i)

Submission status: Wrong Answer

Solution code:
import math
import bisect
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
pa=[0]*n
pb=[0]*m
pa[0]=a[0]
pb[0]=b[0]
for i in range(1,n):
	pa[i]=pa[i-1]+a[i]
for i in range(1,m):
	pb[i]=pb[i-1]+b[i]

ans=0
for i in range(n):
	if pa[i]<=k:
		p=bisect.bisect_right(pb,k-pa[i])
		ans=max(ans,i+1+p)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = input().split(' ')
n = int(N)
m = int(M)
k = int(K)

a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
total = 0
x = 0
y = 0

while k > 0:
    if n>x and m >y:
        k -= min(a[x],b[y])
        total +=1
        if min(a[x],b[y])==a[x]:
            x += 1
        else:
            y += 1
    elif n<=x and m > y:
        k -= b[y]
        total += 1
        y += 1
    elif m <= y and n > x:
        k -= a[x]
        total += 1
        x += 1
        
print(total - 1)

Submission status: Wrong Answer

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

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

b.append(k+100)
cnt = 0
ans1, ans2 = 0, 0
for i in range(n-1):
    a[i+1] += a[i]
    if a[i] <= k:
        ans1 = i+1
for j in range(m-1):
    b[j+1] += b[j]
    if b[j] <= k:
        ans2 = j+1
# print(a, b)
ans = max(ans1, ans2)
for i in range(n):
    nokori = k-a[i]
    r, l = 0, m
    if nokori < 0:
        break
    if b[0] > nokori:
        ans = max(i+1, ans)
        continue

    while(l-r > 1):
        if b[(r+l)//2] <= nokori:
            r = (r+l)//2
        else:
            l = (r+l)//2
        # print(l, r)
    ans = max(i+l+1, ans)
    # print(i, r, l, nokori)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
A.append(1000000000)
B = list(map(int, input().split()))
B.append(1000000000)
time = 0
numA = 0
numB = 0

while time < K:
    if A[numA] < B[numB]:
        time += A[numA]
        if time <= K:
            numA += 1
        else:
            break
    elif A[numA] > B[numB]:
        time += B[numB]
        if time <= K:
            numB += 1
        else:
            break
    elif A[numA] == B[numB]:
        if A[numA+1] > B[numB+1]:
            time += B[numB]
            if time <= K:
                numB += 1
            else:
                break
        else:
          if A[numA+1] <= B[numB+1]:
            time += A[numA]
            if time <= K:
                numA += 1
            else:
                break  
        

print(numA + numB)

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

a_i = 0
b_i = 0
time = 0
counter = 0

while time < k:
    if a_i >= len(a_list) and b_i < len(b_list):
        time += b_list[b_i]
        if time > k:
            break
        counter += 1
        b_i += 1
    elif b_i >= len(b_list) and a_i < len(a_list):
        time += a_list[a_i]
        if time > k:
            break
        counter += 1
        a_i += 1
    elif a_i >= len(a_list) and b_i >= len(b_list):
        break
    else:
        if a_list[a_i] == b_list[b_i]:
            if a_i+1 < len(a_list) and b_i+1 < len(b_list):
                if a_list[a_i+1] <= b_list[b_i+1]:
                    time += a_list[a_i]
                    if time > k:
                        break
                    counter += 1
                    a_i += 1
                else:
                    time += b_list[b_i]
                    if time > k:
                        break
                    counter += 1
                    b_i += 1
            elif a_i+1 >= len(a_list) and b_i+1 < len(b_list):
                time += b_list[b_i]
                if time > k:
                    break
                counter += 1
                b_i += 1
            elif a_i+1 < len(a_list) and b_i+1 >= len(b_list):
                time += a_list[a_i]
                if time > k:
                    break
                counter += 1
                a_i += 1
            else:
                time += a_list[a_i]
                if time > k:
                    break
                counter += 1
                a_i += 1
        elif a_list[a_i] < b_list[b_i]:
            time += a_list[a_i]
            if time > k:
                break
            counter += 1
            a_i += 1
        else:
            time += b_list[b_i]
            if time > k:
                break
            counter += 1
            b_i += 1

print(counter)

Submission status: Wrong Answer

Solution code:
def main():
    import bisect
    n,m,k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    A_ac = [0]
    B_ac = [0]
    a_ac = 0
    b_ac = 0
    for a in A:
        a_ac+=a
        A_ac.append(a_ac)
    for b in B:
        b_ac+=b
        B_ac.append(b_ac)
    
    i_mx = bisect.bisect_right(A_ac,k)
    i = i_mx-1
    ct = [0]

    while i > 0:
        k_left = k-A_ac[i]
        j = bisect.bisect_right(B_ac,k_left)-1
        ct.append(i+j)
        i-=1
    

    print(max(ct))
main()

Submission status: Wrong Answer

Solution code:
from collections import deque
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))
else:
    A = deque(A)
    B = deque(B)
    time = 0
    ans = 0
    while time < K:
        if len(A) == 0:
            time += B[0]
            ans += 1
            B.popleft()
        elif len(B) == 0:
            time += A[0]
            ans += 1
            A.popleft()
        else:
            if A[0] <= B[0]:
                time += A[0]
                ans += 1
                A.popleft()
            else:
                time += B[0]
                ans += 1
                B.popleft()
    print(ans-1)

Submission status: Wrong Answer

Solution code:
a,b,k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
i = 0
j = 0
c = 0
if k < min(arr1[0], arr2[0]):
	print(0)
	exit()
while i < a or j < b:
	if i == a:
		while j < b:
			if k >= arr2[j]:
				k -= arr2[j]
				c += 1
				j += 1
			else:
				print(c)
				exit()
	elif j == b:
		while j < b:
			if k >= arr2[j]:
				k -= arr2[j]
				c += 1
				j += 1
			else:
				print(c)
				exit()
	elif arr1[i] < arr2[j] and k >= arr1[i]:
		k -= arr1[i]
		i += 1
	elif arr2[j] <= arr1[i] and k >= arr2[j]:
		k -= arr2[j]
		j += 1
	else:
		break
	c += 1
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
n = 0
m = 0
s = 0
for _ in range(len(A) + len(B)+ 1):
    if n <= len(A)-1 and m <= len(B)-1:
        if A[n] < B[m]:
            s += A[n]
            ans += 1
            n += 1
        else:
            s += B[m]
            ans += 1
            m += 1
    elif n <= len(A) - 1 and m == len(B):
        s += A[n]
        ans += 1
        n += 1    
    elif n == len(A) and m <= len(B)-1:
        s += B[m]
        ans += 1
        m += 1
    if s > K:
        print(ans-1)
        exit()
    elif s == K:
        print(ans)
        exit()
    elif n == len(A) and m == len(B):
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
from statistics import mean
N,M,K=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
k=0
c=0
while k <= K:
    if len(a) > 0 and len(b)>0:
        if mean(a) < mean(b) and ((k+a[0]) <=K):
            k+=a[0]
            c+=1
            a.pop(0)
        elif mean(a) > mean(b) and ((k+b[0]) <=K):
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            if (a[0] < b[0]) and ((k+a[0]) <=K):
                k+=a[0]
                c+=1
                a.pop(0)

            elif (a[0] > b[0]) and ((k+b[0]) <=K):
                k+=b[0]
                c+=1
                b.pop(0)
            else:
                break
    elif (len(a) > 0) and (len(b) ==0):
        if ((k+a[0]) <=K):
            k+=a[0]
            c+=1
            a.pop(0)
        else:
            break
    elif (len(b) > 0) and (len(a) ==0):
        if ((k+b[0]) <=K):
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            break
    else:
        break
print(c)

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()))
ans1=0
ans2=0
k2=k
a2=a
b2=b
for _ in range(4*10**5):
  if a[0] < b[0]:
    if k-a[0] >= 0:
      ans1+=1
      k-=a[0]
      a=a[1:]
      if len(a)==0:
        a.append(10**10)
    else:
      break
  elif a[0] > b[0]:
    if k-b[0] >= 0:
      ans1+=1
      k-=b[0]
      b=b[1:]
      if len(b)==0:
        b.append(10**10)
    else:
      break
  else:
    if k-a[0] >= 0:
      ans1+=1
      k-=a[0]
      a=a[1:]
      if len(a)==0:
        a.append(10**10)
    else:
      break
print(ans1)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A= list(map(int,input().split()))
B= list(map(int,input().split()))
count_A=0
count_B=0
kouho1=0
amount_min=0
temp_min=0
A_max_count=0
A_max_min=0
B_max_min=0
for i in range(0,N):
    temp_min+=A[i]
    if temp_min >= K:
        A_max_min=temp_min-A[i]
        A_max_count=count_A
        break
    else:
        count_A+=1

    if i==N-1:
        A_max_count=count_A
print(A_max_count)
temp_min=0
count=0
for i in range(0,M):
    temp_min+=B[i]
    if temp_min >= K:
        B_max_min=temp_min-B[i]
        B_max_count=count_B
        break
    else:
        count_B+=1
    if i==M-1:
        B_max_count=count_B
        
temp_A_min=A_max_min
katei1=A_max_min
katei1_count=A_max_count
ans=A_max_count
for i in range(-1,A_max_count):
    Anocount=0
    if i==-1:
        Anocount=A_max_count
        rev_i=A_max_count-2
        _temp=temp_A_min
    else:
        rev_i = A_max_count-i-1
        _temp=temp_A_min - A[rev_i]
        Anocount=A_max_count-i-1
    for j in range(0,M):
        _temp+=B[j]
        if _temp>=K:
            if Anocount+j > katei1_count:
                katei1_count=Anocount+j

            break
        if j==M-1:
            if Anocount+j+1 > katei1_count:
                katei1_count=Anocount+j+1
            
print(katei1_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
x=0
c=[sum(a)-sum(a[:i+1]) for i in range(len(a))]
d=[sum(b)-sum(b[:i+1]) for i in range(len(b))]
# 60 150 270
# 80 230 310 470
# 3 4 240
# 60 90 120
# 80 150 80 150
e=[sum(a[:i+1]) for i in range(len(a))]
f=[sum(b[:i+1]) for i in range(len(b))]
#print(c,d)
#print(e,f)
ans=0
x=0
for i in range(m+n):
    if a and b:
        if e[0]<=f[0]:
            z=a[0]
            ans+=z
            del a[0]
            del e[0]
        else:
            z=b[0]
            ans+=z
            del b[0]
            del f[0]
    else:
        if a:
            ans+=a[0]
            del a[0]
            del e[0]
        elif b:
            ans+=b[0]
            del b[0]
            del f[0]
        else:
            break
    if ans>k:
        break
    x+=1
    #print(ans)
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)
B = np.array(list(map(int, input().split())), dtype=np.int64)
SA = np.cumsum(A)
SB = np.cumsum(B)
D = tuple(*np.where(SA <= k))
if not D:
    d = 0
else:
    d = max(D)
res = d + 1

for i, sb in enumerate(SB):
    SC = SA + sb
    E = tuple(*np.where(SC <= k))
    if not E:
        e = 0
    else:
        e = max(E)
    res = max(res, e + i + 2)
print(res)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A = deque(A)
B = deque(B)

ans = 0
left_time = K
while True:
    # 本が両方の机からなくなったら終了
    if len(A) == 0 and len(B) == 0:
        break

    # Aだけ本が残っている場合
    if len(A) != 0 and len(B) == 0:
        val = A.popleft()
    # Bだけ本が残っている場合
    elif len(A) == 0 and len(B) != 0:
        val = B.popleft()
    # Aの先頭の本の方がすぐに読める場合
    elif A[0] < B[0]:
        val = A.popleft()
    # Bの先頭の本の方がすぐに読める場合
    elif A[0] > B[0]:
        val = B.popleft()
    # Aの先頭とBの先頭が同じ場合
    else:
        if len(A) == 1:
            val = A.popleft()
        elif len(B) == 1:
            val = B.popleft()
        elif A[1] <= B[1]:
            val = A.popleft()
        else:
            val = B.popleft()
    left_time -= val
    if left_time < 0:
        break
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = deque(list(map(int, input().split())))
    B = deque(list(map(int, input().split())))
    CNT = 0
    while K >= 0:
        if CNT == N+M:
            break
        if len(A) > 0 and len(B) > 0:
            a = A[0]
            b = B[0]
            if a >= b:
                if K >= b:
                    K -= b
                    B.popleft()
                    CNT += 1
                else:
                    break
            else:
                if K >= a:
                    K -= a
                    A.popleft()
                    CNT += 1
                else:
                    break

        elif len(A) == 0:
            b = B[0]
            if K >= b:
                K -= b
                B.popleft()
                CNT += 1
            else:
                break
        else:
            if K >= a:
                K -= a
                A.popleft()
                CNT += 1
            else:
                break
    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()))
c = 0

if K >= sum(A+B):
    print(N+M)
else:
    while K >=0:
        c +=1
        if not A:
            K -= B.pop(0)
        elif not B:
            K -= A.pop(0)
        elif A[0] >=B[0]:
            K -= B.pop(0)
        else:
            K -= A.pop(0)
    if K == 0:
        print(c)
    else:
        print(c-1)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
i = 0
n = 0
while i <= K:
    if a == [] and b == []:
        n += 1
        break
    elif a==[] and b !=[]:
        i += b[0]
        del b[0]
    elif a!=[] and b ==[]:
        i +=a[0]
        del a[0]        
    else:
        i += min(a[0],b[0])
        if a[0] <= b[0]:
            del a[0]
        else:
            del b[0]
    n += 1

print(n-1)
exit(0)

Submission status: Wrong Answer

Solution code:
n=list(map(int,input().split()))
m=list(map(int,input().split()))
t=list(map(int,input().split()))

li=m+t
i=0
count=0

while i< len(li):
  if li[i] + count <= n[2]:
    count +=1
  i+=1



print(count)

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_sum = []
for i in range(len(a)):
  a_sum.append(sum(a[:i+1]))
b_sum = []
for j in range(len(b)):
  b_sum.append(sum(b[:j+1]))

iMax = bisect.bisect(a_sum, k)
jMax = bisect.bisect(b_sum, k)

if iMax == 0 and jMax == 0:
  print(0)
  exit()

ans = 0
for i in range(iMax):
  for j in range(jMax):
    if a_sum[i] + b_sum[j] <= k:
      ans = max(ans, i + j + 2)

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_i= 0
b_i= 0
f = True

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

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

Submission status: Wrong Answer

Solution code:
alen,blen,k = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
max = 0

for acount in range(0,alen):
    bcount = 0
    asum = sum(alist[:acount])
    while asum + sum(blist[:bcount+1]) < k and bcount <= blen:
        bcount += 1
    if acount + bcount > max and asum + sum(blist[:bcount])<=k:
        max = acount + bcount

print(max)

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()))
prog=0
a_idx=0
b_idx=0

while a_idx<n:
    if a[a_idx]+prog>k:
        break
    prog+=a[a_idx]
    a_idx+=1

if a_idx==n:
    while b_idx<m:
        if b[b_idx]+prog>k:
            break
        prog+=b[b_idx]
        b_idx+=1

mx=a_idx+b_idx

if mx==n+m:
    print(mx)
    sys.exit()

for i in range(a_idx):
    while b[b_idx]+prog<=k:
        prog+=b[b_idx]
        b_idx+=1
    if a_idx+b_idx>mx:
        mx=a_idx+b_idx
    a_idx-=1

print(mx)

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
cnt = 0
idx_A = 0
idx_B = 0
while total <= K:
    if idx_A < N and idx_B < M:
        if A[idx_A] < B[idx_B]:
            total += A[idx_A]
            cnt += 1
            idx_A += 1
        else:
            total += B[idx_B]
            cnt += 1
            idx_B += 1
    elif idx_B < M:
        total += B[idx_B]
        cnt += 1
        idx_B += 1
    elif idx_A < N:
        total += A.pop(0)
        cnt += 1
        idx_A += 1
    else:
        break

if total > K:
    cnt -= 1
print(cnt)