Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cum_a = []
total = 0
for i in range(n):
  total += a[i]
  if total > k:
    break
  cum_a.append(total)
  
cum_b = []
total = 0
for j in range(m):
  total += b[j]
  if total > k:
    break
  cum_b.append(total)
lim_a = len(cum_a)
lim_b = len(cum_b)
idx = 0
ans = lim_a
for l in range(1, lim_a + 1):
  while idx < lim_b:
    if k >= cum_a[-l] + cum_b[idx]:
      ans = lim_a - l + idx + 2
    else:
      idx += 1
    idx += 1
print(ans)

Submission status: Wrong Answer

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

A = deque([int(i) for i in input().split()])
B = deque([int(i) for i in input().split()])
ans = 0
while True:
    a = A[0] if len(A) else float('inf')
    b = B[0] if len(B) else float('inf')
    if a > b:
        if len(B): B.popleft()
        K -= b
    else:
        if len(A): A.popleft()
        K -= a
    if K < 0:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Asum = [0] * N
Bsum = [0] * M
res = [0]

for i in range(N-1):
    Asum[0] = A[0]
    Asum[i+1] = Asum[i] + A[i+1]
for j in range(M-1):
    Bsum[0] = B[0]
    Bsum[j+1] = Bsum[j] + B[j+1]

for k in range(N):
    if Asum[k] > K:
        break
    for l in range(M):
        if (Asum[k] + Bsum[l]) > K:
            res.append(k+1+l-1+1)
            break
        elif (Asum[k] + Bsum[l]) == K:
            res.append(k+1+l+1)
            break

print(max(res))

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(K)
# print(a)
# print(b)
# N,M=3,4
# K=730
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0

_accum_a=[0]
for i in a:
    _accum_a.append(_accum_a[-1]+i)
_accum_a.append(K)
_accum_a1=sorted(_accum_a)

accum_a=_accum_a1[:_accum_a.index(K)]

accum_b=[0]
for i in b:
    accum_b.append(accum_b[-1]+i)

ans=0

for j in range (len(accum_a)):
    Kb=K-accum_a[j]
    _accum_b=accum_b
    _accum_b.append(Kb)
    _accum_b1=sorted(_accum_b)
    bookb=_accum_b1.index(Kb)-1
    if _accum_b.count(Kb)==2:
        bookb+=1
    if j+bookb>ans:
        ans=j+bookb
    else:
        continue
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


for i in range(n):
    cnt = sum(a[:i + 1])
    if cnt > k:
        ans = max(ans, i)
        break
    for j in range(m):
        cnt += b[j]
        if cnt > k:
            ans = max(ans, i + 1 + j)
            break
    else:
        ans = max(ans, i + j + 2)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

    #print(M, K, A, B)
    # print(A.pop(0))
    ans = 0
    tmp = 0
    AB = []

    for _ in range(N + M):
        if len(A) == 0:
            AB.extend(B)
            break
        elif len(B) == 0:
            AB.extend(A)
            break
        elif A[0] < B[0]:
            AB.append(A.pop(0))
        else:
            AB.append(B.pop(0))

    for ab in AB:
        tmp += ab
        if tmp <= K:
            ans += 1
        else:
            break
    print(ans)
        


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

n,m,k=read()
A=read()
B=read()
a,b=[0],[0]
for i in range(n):
	a.append(a[i]+A[i])
for i in range(m):
	b.append(b[i]+B[i])
ans=0
for i in range(1,n+1):
	curr=a[i]
	j=m
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

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

n,m,k=read()
A=read()
B=read()
a,b=[0],[0]
for i in range(n):
	a.append(a[i]+A[i])
for i in range(m):
	b.append(b[i]+B[i])
ans=0
for i in range(1,n+1):
	curr=a[i]
	j=bisect(b,k-curr,0,m+1)
	if j>m or b[j]>k-curr:
		j-=1
	if j==-1:
		ans=max(0,ans)
	else:
		ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
INF = float('inf')
n, m, k = list(map(int, input().split()))

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_limit = len(a)
b_limit = len(b)
a += [INF] * 1
b += [INF] * 1

i,j = 0,0
ans, total = 0, 0
for step in range(a_limit + b_limit):
    #print(total, ans, i, j)
    #if i > a_limit and j > b_limit:
        #break

    if a[i] > b[j]:
        if total + b[j] > k:
            break
        total += b[j]
        j += 1
        ans += 1
    else:
        if total + a[i] > k:
            break
        total += a[i]
        i += 1
        ans += 1
#print(total, 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()))
Asum = [0] * N
Bsum = [0] * M
res = [0]

for i in range(N-1):
    Asum[0] = A[0]
    Asum[i+1] = Asum[i] + A[i+1]
for j in range(M-1):
    Bsum[0] = B[0]
    Bsum[j+1] = Bsum[j] + B[j+1]

for k in range(N):
    for l in range(M):
        if (Asum[k] + Bsum[l]) > K:
            res.append(k+1+l-1+1)
            break
        elif (Asum[k] + Bsum[l]) == K:
            res.append(k+1+l+1)
            break

print(max(res))

Submission status: Wrong Answer

Solution code:
INF = float('inf')
n, m, k = list(map(int, input().split()))

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_limit = len(a)
b_limit = len(b)
a += [INF] * 1
b += [INF] * 1

i,j = 0,0
ans, total = 0, 0
while True:
    #print(total, ans, i, j)
    if i > a_limit and j > b_limit:
        break

    if a[i] > b[j]:
        if total + b[j] > k:
            break
        total += b[j]
        j += 1
        ans += 1
    else:
        if total + a[i] > k:
            break
        total += a[i]
        i += 1
        ans += 1

#print(total, ans)
print(ans)

Submission status: Wrong Answer

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

n,m,k=read()
a=read()
b=read()
a.reverse()
b.reverse()
ans=0
while(k>0):
	if a==[] and b==[]:
		break 
	if a and b:
		if a[-1]<b[-1]:
			k-=a[-1]
			a.pop()
		else:
			k-=b[-1]
			b.pop()
	elif a:
		k-=a[-1]
		a.pop()
	elif b:
		k-=b[-1]
		b.pop()
	else:
		break 
	ans+=1
if k<0:
	ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

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

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

C = list(accumulate(A))

D = list(accumulate(B))

res = 0
for i,v1 in enumerate(C,1):
  for j,v2 in enumerate(D,1):
    if v1+v2 <= K:
      res = max(res,i+j)
    else:
      break

print(res)

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

sum_AB = 0
cnt = 0
idx_A = -1
idx_B = -1
for i,a in enumerate(A):
  if sum_AB + a > K:
    break
  else:
    sum_AB += a
    cnt += 1
    idx_A = i
for i,b in enumerate(B):
  if sum_AB + b > K:
    break
  else:
    sum_AB += b
    cnt += 1
    idx_B = i
ans = cnt
A = A[0:idx_A+1][::-1]
B = B[idx_B:]
for a in A:
  sum_AB -= a
  cnt -= 1
  for b in B:
    if sum_AB + b > K:
      break
    else:
      sum_AB += b
      cnt += 1
  ans = max(cnt,ans)
print(ans)

Submission status: Wrong Answer

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

time_A = [0]*(N+1)
time_B = [0]*(M+1)

for i in range(N):
    time_A[i+1] = time_A[i] + A[i]
print(time_A)
for j in range(M):
    time_B[j+1] = time_B[j] + B[j]

ans = 0
l = M

for k in range(N+1):
    if time_A[k] > K:
        break
    while time_A[k] + time_B[l] > K:
        l -= 1
    ans = max(ans,k+l)

print(ans)

Submission status: Wrong Answer

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

def is_ok(arg):
    return sum(a[:arg]) <= remaining_time

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


total = []
for i in range(len(b)):
    if i == 0:
        b_time = b[0]
    else:
        b_time = b_time + b[i]

    if b_time <= k:
        b_number = i + 1
    else:
        b_number = i
        total.append(b_number)
        break
    remaining_time = k - b_time
    a_number = meguru_bisect(len(a) + 1, 0)
    total.append(a_number + b_number)

print(max(total))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [0]+[x for x in accumulate([int(n) for n in input().split()])]
B = [0]+[x for x in accumulate([int(n) for n in input().split()])]
ans = 0
a = bisect_left(A, K)
for i in range(a):
  b = bisect_left(B, K-A[i])
  ans = max(ans, i+b)
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]*(N+1)
b = [0]*(M+1)
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
        ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

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

def is_ok(arg):
    return sum(a[:arg]) <= remaining_time

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


total = []
for i in range(1,len(b) + 1):
    b_time = sum(b[:i])
    if b_time <= k:
        b_number = i
    else:
        b_number = i - 1
        total.append(b_number)
        break
    remaining_time = k - b_time
    a_number = meguru_bisect(len(a) + 1, 0)
    total.append(a_number + b_number)

print(max(total))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [x for x in accumulate([int(n) for n in input().split()])]
B = [x for x in accumulate([int(n) for n in input().split()])]
ans = 0
a = bisect(A, K)
for i in range(a-1, -1, -1):
  b = bisect(B, K-A[i])
  ans = max(ans, i+b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
ans = 0
i = j = 0
while i+j<=n+m:
    a = b = float('inf')
    if i<n:
        a = A[i]
    if j<m:
        b = B[j]
    if min(a, b)>k:
        break
    if a<b:
        k -= a
        i += 1
    else:
        k -= b
        j += 1
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

read_time = 0
read_num = 0

while True:
    if len(A)==0 and len(B)==0:
        break
    if read_time>K:
        break
    if len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
            continue
        else:
            break
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
            continue
        else:
            break
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        else:
            break
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        else:
            break
print(read_num)

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

read_time = 0
read_num = 0

while True:
    if len(A)==0 and len(B)==0:
        break
    if read_time>K:
        break
    if len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
print(read_num)

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

read_time = 0
read_num = 0

while True:
    if len(A)==0 and len(B)==0:
        break
    if read_time>K:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
print(read_num)

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

read_time = 0
read_num = 0

while read_time<=K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
print(read_num)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [x for x in accumulate([int(n) for n in input().split()])]
B = [x for x in accumulate([int(n) for n in input().split()])]
a = bisect(A, K)
b = bisect(B, K-A[a-1])
print(a+b)

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

read_time = 0
read_num = 0

while read_time<K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
print(read_num)

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

read_time = 0
read_num = 0

while read_time<=K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>read_time+r:
            read_num += 1
            read_time += r
print(read_num)

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

read_time = 0
read_num = 0

while read_time<=K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
print(read_num)

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

read_time = 0
read_num = 0

while read_time<K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
            read_time += r
print(read_num)

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

read_time = 0
read_num = 0

while read_time<K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
    read_time += r
print(read_num)

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

read_time = 0
read_num = 0

while not(len(A)==0 and len(B)==0) and read_time<=K:
    if len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
        continue
    elif len(B)==0:
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
        continue
    if(A[0]<B[0]):
        r = A.popleft()
        if K>=read_time+r:
            read_num += 1
    else:
        r = B.popleft()
        if K>=read_time+r:
            read_num += 1
    read_time += r
print(read_num)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
Ai = list(map(int, input().split()))
Bi = list(map(int, input().split()))
 
n = 0
sum_a = 0
for i in range(len(Ai)):
  sum_a += Ai[i]
  if sum_a > K:
    break
  K_b = K - sum_a
  n = max(n, i+1)
  sum_b = 0
  for j in range(len(Bi)):
    sum_b += Bi[j]
    if sum_b > K_b:
      break
    n = max(n, i+j+2)
 
print(n)

Submission status: Wrong Answer

Solution code:
INF = float('inf')
n, m, k = list(map(int, input().split()))

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_limit = len(a)
b_limit = len(b)
a += [INF] * 1
b += [INF] * 1

i,j = 0,0
ans, total = 0, 0
while True:
    #print(total, ans, i, j)
    if i >= a_limit and j >= b_limit:
        break

    if a[i] > b[j]:
        if total + b[j] > k:
            break
        total += b[j]
        j += 1
        ans += 1
    else:
        if total + a[i] > k:
            break
        total += a[i]
        i += 1
        ans += 1

#print(total, 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()))
a = [0]*(N+1)
b = [0]*(M+1)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
for n in range(1, N+1):
    if a[n] <= K:
        X = n
for m in range(1, M+1):
    if b[m] <= K:
        Y = m 
if a[X] < b[Y]:
    K = K - a[X]
    cnt += X
    for y in range(1, Y+1):
        if b[y] <= K:
            cnt += 1
else:
    K = K - b[Y]
    cnt += Y
    for x in range(1, X+1):
        if a[x] <= K:
            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()))
a = [0]*(N+1)
b = [0]*(M+1)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
for n in range(1, N+1):
    if a[n] <= K:
        X = n
for m in range(1, M+1):
    if b[m] <= K:
        Y = m 
if a[X] < b[Y]:
    K = K - a[X]
    cnt += X
    if K - b[Y] == 0:
        cnt += Y
    else:
        for y in range(1, Y+1):
            if b[y] < K:
                cnt += 1
else:
    K = K - b[Y]
    cnt += Y
    if K - a[X] == 0:
        cnt += X
    else:
        for x in range(1, X+1):
            if a[x] < K:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
Ai = list(map(int, input().split()))
Bi = list(map(int, input().split()))
 
def p(x, k):
  y = []
  n = 0
  for v in x:
    n += v
    if n > k:
      break
    y.append(n)
  return y

As = p(Ai, K)
Bs = p(Bi, K)

n = 0
for i in range(len(As)):
  k = K - As[i]
  n = max(n, i+1)
  for j in range(len(Bs)):
    if Bs[j] > k:
      break
    n = max(n, i+j+2)
 
print(n)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(1, N):
    a[i] = a[i-1] + a[i]
for i in range(1, M):
    b[i] = b[i-1] + b[i]

cnt = 0
b_idx = M
for i in range(N+1):
    if a[i] > K:
        break
    for j in range(b_idx, -1, -1):
        if a[i] + b[j] <= K:
            cnt = max(cnt, i+j)
            b_idx = j
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	sumA = []
	for i,val in enumerate(A):
		if i == 0:
			sumA.append(val)
		else:
			sumA.append(val + sumA[i-1])

	sumB = []
	for i,val in enumerate(B):
		if i == 0:
			sumB.append(val)
		else:
			sumB.append(val + sumB[i-1])

	ans = 0
	for i,val in enumerate(sumA):
		if val > K:
			break
		amari = K - val
		indexs = bisect_left(sumB, amari)
		tmp = (i+1) + indexs
		#print(tmp)
		if ans < tmp:
			ans = tmp

	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	sumA = []
	for i,val in enumerate(A):
		if i == 0:
			sumA.append(val)
		else:
			sumA.append(val + sumA[i-1])

	sumB = []
	for i,val in enumerate(B):
		if i == 0:
			sumB.append(val)
		else:
			sumB.append(val + sumB[i-1])

	ans = 0
	for i,val in enumerate(sumA):
		if val > K:
			break
		amari = K - val
		indexs = bisect_right(sumB, amari)
		tmp = (i+1) + indexs
		#print(tmp)
		if ans < tmp:
			ans = tmp

	print(ans)

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

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

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

ptr = 0
ans = 0

for i in range(n):
    if a[i] > k:
        break
    while ptr < m:
        if a[i] + b[ptr] >= k:
            break
        ptr += 1
    ans = max(ans, i + min(ptr, m) + 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()))

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

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

ptr = 0
ans = 0

for i in range(n):
    if a[i] > k:
        break
    while ptr < m:
        if a[i] + b[ptr] >= k:
            break
        ptr += 1
    print(i, ptr)
    ans = max(ans, i + min(ptr, m) + 1)

print(ans)

Submission status: Wrong Answer

Solution code:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    #output
    import heapq as hp
    answer = 0
    l = a + b
    acc_sum = 0
    hp.heapify(l)

    while acc_sum < k:
        temp = hp.heappop(l)
        acc_sum += temp
        if acc_sum > k:
            break
        else:
            answer += 1

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_i = list(map(int, input().split()))
b_i = list(map(int, input().split()))
time = 0
a_cnt = 0
b_cnt = 0
for a in a_i:
    tmp = time + a
    if tmp <= k:
       time += a
       a_cnt += 1
    else: break
for b in b_i:
    tmp = time + b
    if tmp <= k:
        time += b
        b_cnt += 1
    else:
        tmp -= a_i[a_cnt - 1]
        if a_cnt > 0 and tmp <= k:
            time += b - a_i[a_cnt - 1]
            b_cnt += 1
            a_cnt -= 1
        else: break
print(a_cnt + b_cnt)

Submission status: Wrong Answer

Solution code:
import bisect
 
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
 
a_sum = [0]*(n+1)
b_sum = [0]*(m+1)
 
for i in range(n):
  a_sum[i+1] =  a_sum[i] + a[i+1]
for j in range(m):
  b_sum[j+1] =  b_sum[j] + b[j+1]
 
ans = 0
for i in range(n+1):
  j = bisect.bisect_left(b_sum, k - a_sum[i])
  tmp = i + j
  ans = max(ans, tmp)
 
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_cs, b_cs = [0], [0]
for i in range(n):
  a_cs.append(a_cs[i] + a[i])
for i in range(m):
  b_cs.append(b_cs[i] + b[i])

ans, j = 0, m
for i in range(n+1):
  if a_cs[i] > k:
    break
  while b_cs[j] > k - a_cs[i]:
    j -= 1
  ans = min(ans, i + j)
print(ans)

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
    left_to_read -= 1

print(total)