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:
import copy

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

max_count = 0

for i in range(n):
	time = sum(a[:i+1])
	count = i+1
	for i in range(m):
		if(time + b[i] > k):
			break
		time += b[i]
		count += 1
	max_count = max(count,max_count)

print(max_count)

Submission status: Wrong Answer

Solution code:
import copy

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

time = 0
count = 0
while(True):

	if(count == len(a) or time + a[count]> k):
		break
	time += a[count]
	count += 1

a = a[:count]
try:
	while(a[-1] >= b[0] or sum(a) <= k):
	
		a.insert(0,b[0])
		b = b[1:]
		if(sum(a) > k):
			a = a[:-1]
except:
	pass
print(len(a))

Submission status: Wrong Answer

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

A = [0]
for i,a in enumerate(input().split()):
    A.append(A[i] + int(a))

B = [0]
for i,a in enumerate(input().split()):
    B.append(B[i] + int(a))

#print(A)
#print(B)
i,bestj,ans = 0,m,0
while A[i] < k:
    for j in range(bestj, -1, -1):
        if A[i] + B[j] <= k: break
    #print(i,j)
    ans = max(i+j, ans)
    bestJ = j
    
    i += 1
    if i == n+1: break

print(ans)

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    # cumsum
from bisect import bisect_left, bisect_right

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

    A = list(accumulate(A))
    B = list(accumulate(B))
    
    # print(A)
    # print(B)
    ans = bisect_right(B, K)
    for i, a in enumerate(A):
        th = K - a
        if th <= 0: break
        ib = bisect_right(B, th)
        ans = max(i+1+ib, ans)
    print(ans)
    

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
seen = []
runSum = 0
for i, val in enumerate(b):
    runSum += val
    seen.append((runSum, i))
seen.sort()
def findLessEqual(target):
    l, r = 0, len(seen) - 1
    result = -1
    while l <= r:
        mid = (l + r) // 2
        if seen[mid][0] == target:
            return seen[mid][1]
        elif seen[mid][0] < target:
            result = seen[mid][1]
            l = mid + 1
        else:
            r = mid - 1
    return result

runSum = 0
result = 0
for i, val in enumerate(a):
    runSum += val
    if runSum <= k:
        complement = k - runSum
        compI = findLessEqual(complement)
        result = max(result, i + compI + 2)
print(result)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
result = 0
seen = []
runSum = 0
for i, val in enumerate(b):
    runSum += val
    seen.append((runSum, i))
seen.sort()
def findLessEqual(target):
    l, r = 0, len(seen) - 1
    result = -1
    while l <= r:
        mid = (l + r) // 2
        if seen[mid][0] == target:
            return seen[mid][1]
        elif seen[mid][0] < target:
            result = seen[mid][1]
            l = mid + 1
        else:
            r = mid - 1
    return result

runSum = 0
result = 0
for i, val in enumerate(a):
    runSum += val
    if runSum > k:
        break
    complement = k - runSum
    compI = findLessEqual(complement)
    result = max(result, i + compI + 2)
print(result)

Submission status: Wrong Answer

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

A.append(float('inf'))
B.append(float('inf'))

sum,min,ans,i,j = 0,0,0,0,0

while True:
    if A[i] < B[j]:
        min = A[i]
        i += 1
    else:
        min = B[j]
        j += 1
    
    if sum + min > k: 
        break
    else:
        sum += min
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
nmin = list(map(int,input().split()))
mmin = list(map(int,input().split()))
sum = 0
i = 0
j = 0
result = 0
while sum <= k:
    result += 1
    if i >= n:
        if j < m:
            sum += mmin[j]
            j += 1
        else:
            break
    elif j >= m:
        if i < n:
            sum += nmin[i]
            i += 1
        else:
            break
    elif nmin[i] <= mmin[j]:
        sum += nmin[i]
        i += 1
    elif nmin[i] > mmin[j]:
        sum += mmin[j]
        j += 1

print(result-1)

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])


num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in (J,-1,-1):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])


num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in (J,0,-1):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)

Submission status: Wrong Answer

Solution code:
import math
N, M, K = map(int, input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

def getstartm(asum, bsumlist):
  fro =0
  to = len(bsumlist)
  tempm=0
  while 1:
    tempm = math.floor((to-fro)/2)+fro
   # print(str(fro) + " "+str(to) + " " +str(tempm))
    if tempm==len(bsumlist)-1:
      break
    elif asum>=bsumlist[tempm] and asum<bsumlist[tempm+1]:
      break
    elif asum<=bsumlist[tempm]:
      to = tempm
    elif asum>bsumlist[tempm]:
      fro = tempm
  return tempm


asumlist = list([0])
asum = 0
for n in range(N):
  asum += alist[n]
  if K >=asum:
    asumlist.append(asum)
  else:
    break

bsumlist = list([0])
bsum = 0
for m in range(M):
  bsum += blist[m]
  if K >=bsum:
    bsumlist.append(bsum)
  else:
    break

max_b=0
for n in range(len(asumlist)):
  b = getstartm(K- asumlist[n], bsumlist)
  if max_b < b+n:
    max_b = b+n
else:
  b = len(asumlist) + len(bsumlist)-2
  if asumlist[-1]+bsumlist[-1] <= K and max_b < b:
    max_b = b
print(max_b)

Submission status: Wrong Answer

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

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

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

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    if(k >= mx):
        print(n+m)
        return
    
    
    caca = bisect.bisect_left(b_sum,k)
    
    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_left(b_sum,rd)
        caca_tmp = i + 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()

Submission status: Wrong Answer

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

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

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

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    
    caca = bisect.bisect_left(b_sum,k)
    
    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_left(b_sum,rd)
        caca_tmp = i + 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()

Submission status: Wrong Answer

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

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

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

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    if(k >= mx):
        print(n+m)
        return
    
    
    caca = bisect.bisect_left(b_sum,k)
    
    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_left(b_sum,rd)
        caca_tmp = i+ 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()

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

minute = 0
num = 0
a = 0
b = 0
for _ in range(N):
    if len(A[a:]) == 0:
        minute += B[b]
        b += 1
    elif len(B[b:]) == 0:
        minute += A[a]
        a += 1
    elif A[a] < B[b]:
        minute += A[a]
        a += 1
    else:
        minute += B[b]
        b += 1
    
    if minute > K:
        break
    num += 1

print(num)

Submission status: Wrong Answer

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

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

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

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    caca = 0
    if(k >= mx):
        print(n+m)
        return
    
    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd <= 0):
            continue

        b_b = bisect.bisect_left(b_sum,rd)
        caca_tmp = i+ 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()

Submission status: Wrong Answer

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

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

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

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    caca = 0
    if(k >= mx):
        print(n+m)
        return
    
    a_mx = bisect.bisect_left(a_sum,k)+1
    b_mx = bisect.bisect_left(b_sum,k)+1

    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_left(b_sum,rd)
        caca_tmp = i+ 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()

Submission status: Wrong Answer

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

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

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

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    caca = 0
    if(k >= mx):
        print(n+m)
        return
    
    a_mx = bisect.bisect_left(a_sum,k)+1
    b_mx = bisect.bisect_left(b_sum,k)+1

    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_left(b_sum,rd)+1
        caca_tmp = i + b_b
        caca = max(caca,caca_tmp)
    
    print(caca)



solve()

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

minute = 0
num = 0
a = 0
b = 0
while(minute<K):
    if len(A[a:]) == 0:
        minute += B[b]
        b += 1 
    elif len(B[b:]) == 0:
        minute += A[a]
        a += 1
    elif A[a] < B[b]:
        minute += A[a]
        a += 1
    else:
        minute += B[b]
        b += 1
    
    if minute <= K:
        num += 1

print(num)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0];b=[0];ans=0;j=m
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
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:
N, M, K = map(int, input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))

asumlist = list([0])
asum = 0
for n in range(N):
  asum += alist[n]
  if K >=asum:
    asumlist.append(asum)
  else:
    break

bsumlist = list([0])
bsum = 0
for m in range(M):
  bsum += blist[m]
  if K >=bsum:
    bsumlist.append(bsum)
  else:
    break

max_b=0
for n in range(len(asumlist)):
  startm = 0
  if K>=asumlist[n] + bsumlist[int(len(bsumlist)/2)]:
    startm=int(len(bsumlist))
  for m in range(startm, len(bsumlist)):
    if K >= asumlist[n]+bsumlist[m]:
      b = n + m
      if max_b < b:
        max_b = b
    else:
      break
  else:
    b = n + len(bsumlist)-1
    if max_b < b:
      max_b = b
else:
  b = len(asumlist) + len(bsumlist)-2
  if asumlist[-1]+bsumlist[-1] <= K and max_b < b:
    max_b = b
print(max_b)

Submission status: Wrong Answer

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

asumlist = list([0])
for n in range(N):
  if K >=sum(alist[0:n+1]):
    asumlist.append(sum(alist[0:n+1]))
  else:
    break

bsumlist = list([0])
for m in range(M):
  if K >=sum(blist[0:m+1]):
    bsumlist.append(sum(blist[0:m+1]))
  else:
    break
print(asumlist)
print(bsumlist)
max_b=0
for n in range(len(asumlist)):
  for m in range(len(bsumlist)):
    if K >= asumlist[n]+bsumlist[m]:
      b = n + m
      if max_b < b:
        max_b = b
    else:
      break
  else:
    b = n + len(bsumlist)-1
    if max_b < b:
      max_b = b
else:
  b = len(asumlist) + len(bsumlist)-2
  if asumlist[-1]+bsumlist[-1] <= K and max_b < b:
    max_b = b
print(max_b)

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

minute = 0
num = 0
while(minute<K):
    if len(A) == 0:
        minute += B[0]
        B.pop(0)
    elif len(B) == 0:
        minute += A[0]
        A.pop(0)
    elif A[0] < B[0]:
        minute += A[0]
        A.pop(0)
    else:
        minute += B[0]
        B.pop(0)
    
    if minute <= K:
        num += 1

print(num)

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;j=0;ans=0
while k>0:
        if i<n and j<m:
            if a[i]<=b[j]:
                k-=a[i]
                ans+=1
                i+=1
                continue
            else:
                k-=b[j]
                ans+=1
                j+=1
                continue
        elif i==n and j<m:
            k-=b[j]
            ans+=1
            j+=1
            continue
        elif i<n and j==m:
            k-=a[i]
            ans+=1
            i+=1
            continue
print(ans-1 if (i==0 and j==1)or(i==1 and j==0)else ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
t=0
max_b=0
for n in range(N):
  if sum(alist[0:n+1])>K:
    b = n
    if b > max_b:
      max_b = b
    break
  else:
    for m in range(M):
      if sum(alist[0:n])+sum(blist[0:m+1]) > K:
        b = n+1 + m
        if b > max_b:
          max_b = b
        break
    else:
      b = n+1 + M
      if b > max_b:
        max_b = b
else:
  b = N+M
  max_b = b
print(max_b)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
result = 0
i1, i2 = 0, 0
while True:
    if k == 0:
        break
    if i1 < n and i2 < m:
        if a[i1] < b[i2]:
            if a[i1] > k:
                break
            result += 1
            k -= a[i1]
            i1 += 1
        elif b[i2] < a[i1]:
            if b[i2] > k:
                break
            result += 1
            k -= b[i2]
            i2 += 1
        else:
            tempi1, tempi2 = i1, i2
            broke = False
            while tempi1 < n and tempi2 < m and a[tempi1] == b[tempi2]:
                if a[tempi1] > k:
                    broke = True
                    break
                result += 1
                k -= a[tempi1]
                tempi1 += 1
                tempi2 += 1
            if broke:
                break
            if tempi1 >= n and tempi2 >= m:
                break
            elif tempi1 < n and tempi2 < m:
                if a[tempi1] < b[tempi2]:
                    i1 = tempi1
                else:
                    i2 = tempi2
            elif tempi1 < n:
                i1 = tempi1
            elif tempi2 < m:
                i2 = tempi2

    elif i1 < n:
        if a[i1] > k:
            break
        result += 1
        k -= a[i1]
        i1 += 1
    elif i2 < m:
        if b[i2] > k:
            break
        result += 1
        k -= b[i2]
        i2 += 1
    else:
        break
print(result)

Submission status: Wrong Answer

Solution code:
n,m,k=input().split()
n,m,k=int(n),int(m),int(k)

a=input().split()
for i in range(len(a)):
  a[i]=int(a[i])
  
b=input().split()
for i in range(len(b)):
  b[i]=int(b[i])
  
#print(n,m,k,a,b)

ans=0
if a[0]>k and b[0]>k:
    ans=0

elif b[0]>k:
    timea=0  
    counta=0
    for i in range(n):
        timea+=a[i]
        if timea<=k:
            counta+=1
        else:
            ans=counta
            break

elif a[0]>k:
    timeb=0  
    countb=0
    for i in range(m):
        timeb+=b[i]
        if timeb<=k:
            countb+=1
        else:
            ans=countb
            break  
else:
    timea=0
    counta=0
    for i in range(n):
        timea+=a[i]
        if timea<=k:
            counta+=1
        else:
            break
        timeb=0
        countb=0
        for j in range(m):
            timeb+=b[j]
            if timea+timeb <= k:
                countb+=1
                ans=max(ans, counta+countb)
            else:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=input().split()
n,m,k=int(n),int(m),int(k)

a=input().split()
for i in range(len(a)):
  a[i]=int(a[i])
  
b=input().split()
for i in range(len(b)):
  b[i]=int(b[i])
  
#print(n,m,k,a,b)

ans=0
if a[0]>k and b[0]>k:
    ans=0

elif b[0]>k:
    timea=0  
    counta=0
    for i in range(n):
        timea+=a[i]
        if timea<=k:
            counta+=1
        else:
          ans=counta
          break

elif a[0]>k:
    timeb=0  
    countb=0
    for i in range(m):
        timeb+=b[i]
        if timeb<=k:
            countb+=1
        else:
          ans=countb
          break  
  
else:
    timea=0
    counta=0
    for i in range(n):
        timea+=a[i]
        if timea<=k:
            counta+=1
        timeb=0
        countb=0
        for j in range(m):
            timeb+=b[j]
            if timea+timeb <= k:
                countb+=1
#                print(counta,countb)
                ans=max(ans, counta+countb)
            else:
                break
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=input().split()
n,m,k=int(n),int(m),int(k)

a=input().split()
for i in range(len(a)):
  a[i]=int(a[i])
  
b=input().split()
for i in range(len(b)):
  b[i]=int(b[i])
  
#print(n,m,k,a,b)

ans=0
if a[0]>k and b[0]>k:
    ans=0

timea=0
counta=0
for i in range(n):
    timea+=a[i]
    if timea<=k:
        counta+=1
    timeb=0
    countb=0
    for j in range(m):
        timeb+=b[j]
        if timea+timeb <= k:
            countb+=1
#            print(counta,countb)
            ans=max(ans, counta+countb)
        else:
            break
        
print(ans)

Submission status: Wrong Answer

Solution code:
nn= input().split()
N = int(nn[0])
M = int(nn[1])
K = int(nn[2])
MM = input().split()
LL = input().split()
total =0
count = -1
while total <= K :
  if len(MM) != 0:
    a =int(MM[0])
  else:
    a = 1000000000
  if len(LL) != 0:
    b =int(LL[0])
  else:
    b = 1000000000
  if a <= b:
    total +=a
    if len(MM) !=0:
        MM.pop(0)
  else:
    total +=b
    if len(LL) !=0:
        LL.pop(0)
  count +=1
print(count)

Submission status: Wrong Answer

Solution code:
m, n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
assert(len(a) == m)
assert(len(b) == n)

def books_from_pile(pile, minutes):
  books = 0
  residue = minutes
  while books < len(pile) and residue >= pile[books]:
    residue -= pile[books]
    books += 1
  return books, residue

# All A
books_a, r = books_from_pile(a, k)
books_b, s = books_from_pile(b, r)
books = books_a + books_b

max_books = books
for i in range(1, books_a):
  s += a[books_a - i]
  f, s = books_from_pile(b[books_b:], s)
  books_b += f
  books -= 1
  books += f
  if books > max_books:
    max_books = books

print(max_books)

Submission status: Wrong Answer

Solution code:
m, n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
assert(len(a) == m)
assert(len(b) == n)

def books_from_pile(pile, minutes):
  books = 0
  residue = minutes
  while books < len(pile) and residue >= pile[books]:
    residue -= pile[books]
    books += 1
  return books, residue

# All A
books_a, r = books_from_pile(a, k)
books_b, s = books_from_pile(b, r)
books = books_a + books_b

max_books = books
for i in range(1, books_a):
  r += a[books_a - i]
  books_b, s = books_from_pile(b, r)
  books = books_a - i + books_b
  if books > max_books:
    max_books = books

print(max_books)

Submission status: Wrong Answer

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

n_ls = list(map(int, input().split(' ')))
m_ls = list(map(int, input().split(' ')))

now_time = 0
result = 0
while now_time < k:
    if (len(n_ls) > 0) & (len(m_ls) > 0):
        if n_ls[0] < m_ls[0]:
            now_time += n_ls.pop(0)
            if now_time <= k:
                result += 1
        else:
            now_time += m_ls.pop(0)
            if now_time <= k:
                result += 1
    elif (len(n_ls) > 0) & (len(m_ls) == 0):
        now_time += n_ls.pop(0)
        if now_time <= k:
            result += 1
    elif (len(n_ls) == 0) & (len(m_ls) > 0):
        now_time += m_ls.pop(0)
        if now_time <= k:
            result += 1
    else:
        break
print(result)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    a_idx = 0
    b_idx = 0
    sum = 0
    while sum <= K:
        if a_idx == N and b_idx == M:
            break
        elif a_idx == N:
            sum += B[b_idx]
            b_idx += 1
        elif b_idx == M:
            sum += A[a_idx]
            a_idx += 1
        elif A[a_idx] < B[b_idx]:
            sum += A[a_idx]
            a_idx += 1
        elif B[b_idx] < A[a_idx]:
            sum += B[b_idx]
            b_idx += 1
        elif A[a_idx] == B[b_idx]:
            i = 0
            while True:
                i += 1
                if a_idx + i == N or b_idx + i == M:
                    sum += A[a_idx]
                    a_idx += 1
                    break
                elif A[a_idx+i] == B[b_idx+i]:
                    continue
                elif A[a_idx+i] < B[b_idx+i]:
                    sum += A[a_idx]
                    a_idx += 1
                    break
                elif A[a_idx+i] > B[b_idx+i]:
                    sum += B[b_idx]
                    b_idx += 1
                    break

    if sum > K:
        print(a_idx + b_idx - 1)
    else:
        print(a_idx + b_idx)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
A = [0]
B = [0]

for i in range(len(a)):
	A.append(A[-1] + a[i])
for i in range(len(b)):
	B.append(B[-1] + b[i])

y = len(B) - 1
ans = 0
for i in range(len(A)):
	while A[i] + B[y] > x:
		y -= 1
		if y == -1:
			break
	if y == -1:
		break
	if x + y > ans:
		ans = i + y

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split(' '))
n = list(map(int, input().split(' ')))
m = list(map(int, input().split(' ')))
i, j = 0, 0

l = []
while i < len(n) and j < len(m):
	if n[i] < m[j]:
		l.append(n[i])
		i += 1
	else:
		l.append(m[j])
		j += 1
l = l + n[i:] + m[j:]

ans = 0
for book in l:
	if book <= x:
		x -= book
		ans += 1
	else:
		break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split(' '))
n = list(map(int, input().split(' ')))
m = list(map(int, input().split(' ')))
i, j = 0, 0

l = []
while i < len(n) and j < len(m):
	if n[i] < m[j]:
		l.append(n[i])
		i += 1
	else:
		l.append(m[j])
		j += 1
if i < len(n):
	l = l + n[i:]
else:
	l = l + m[j:]

ans = 0
for book in l:
	if book <= x:
		x -= book
		ans += 1
	else:
		break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A_sum = [0]
B_sum = [0]
A_sum.extend(A)
B_sum.extend(B)
for i in range(1,N+1):
    A_sum[i]+=A_sum[i-1]
for i in range(1,M+1):
    B_sum[i]+=B_sum[i-1]

for i in range(N,-1,-1):
    for j in range(M,-1,-1):
        if(A_sum[i]+B_sum[j]<=K):
            print(i+j)
            exit()

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    a_idx = 0
    b_idx = 0
    sum = 0
    while sum <= K:
        if a_idx == len(A) and b_idx == len(B):
            break
        elif a_idx == len(A):
            sum += B[b_idx]
            b_idx += 1
        elif b_idx == len(B):
            sum += A[a_idx]
            a_idx += 1
        elif A[a_idx] <= B[b_idx]:
            sum += A[a_idx]
            a_idx += 1
        elif B[b_idx] <= A[a_idx]:
            sum += B[b_idx]
            b_idx += 1
    if sum > K:
        print(a_idx + b_idx - 1)
    else:
        print(a_idx + b_idx)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))+[k+1]
b=list(map(int,input().split()))+[k+1]
ans=0
i=0
j=0
kt=k
while k>=a[i] or k>=b[j]:
    if a[i]<b[j]:
        k-=a[i]
        i+=1
    elif b[j]<a[i]:
        k-=b[j]
        j+=1
    else:
        if a[i+1]<b[j+1]:
            k -= a[i]
            i += 1
        else:
            k -= b[j]
            j += 1
    ans+=1

s=a[i]
i=0
while s<kt and i<n:
    i+=1
    s+=a[i]
if s==kt:i+=1


s=b[0]
j=0
while s<kt and j<n:
    j+=1
    s+=b[j]
if s==kt:j+=1

print(max(ans,i,j))

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))+[k+1]
b=list(map(int,input().split()))+[k+1]
ans=0
i=0
j=0
kt=k
while k>=a[i] or k>=b[j]:
    if a[i]<b[j]:
        k-=a[i]
        i+=1
    elif b[j]<a[i]:
        k-=b[j]
        j+=1
    else:
        if a[i+1]<b[j+1]:
            k -= a[i]
            i += 1
        else:
            k -= b[j]
            j += 1
    ans+=1

s=0
i=0
while s<kt and i<n:
    s+=a[i]
    i+=1
if s==k:i+=1


s=0
j=0
while s<kt and j<n:
    s+=b[j]
    j+=1
if s==k:j+=1

print(max(ans,i,j))

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))+[k+1]
b=list(map(int,input().split()))+[k+1]
ans=0
i=0
j=0
while k>=a[i] or k>=b[j] :
    if a[i]<=b[j]:
        k-=a[i]
        i+=1
    else:
        k-=b[j]
        j+=1
    ans+=1
print(ans)