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()))
MAX = 10**10

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

la = [0] + list(accumulate(a))
lb = [0] + list(accumulate(b))

ans = 0
i = n
for j in range(m+1):
    while la[i]+lb[j] > k and i>=0:
        i -= 1
    if i==0 and lb[j] > k:
        break
    ans = max(ans, i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

la = [0] + list(accumulate(a))
lb = [0] + list(accumulate(b))

ans = 0
i = n
for j in range(m+1):
    while la[i]+lb[j] > k and i>=0:
        i -= 1
    ans = max(ans, i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
acc = sum(B)
j = M - 1
if acc + sum(A) <= K:
    print(M + N)
    exit()
ans = 0
for i in range(N):
    acc += A[i]
    if K >= acc:
        ans = max(ans, i + j + 2)
        continue
    else:
        while (K < acc) & (j > -1):
            acc -= B[j]
            j -= 1
        if K >= acc:
            ans = max(ans, i + j + 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as numpy 
import bisect as bisect
n,m,k = map(int,input().split())
ali = numpy.cumsum(list(map(int,input().split())))
bli = numpy.cumsum(list(map(int,input().split())))
a = [0]
for i in range(n):
    if ali[i] > k:
        break
    b = bisect.bisect_right(bli,k-ali[i])
    a.append(i+b+1)
print(max(a))

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

if A[0] > K and B[0] > K:
    print(0)
    exit()

tsundoku = [0]*(N+M)
currentIndexA = 0
currentIndexB = 0
for i in range(N+M+1):
    if currentIndexA >= N and currentIndexB < M:
        tsundoku[i] = tsundoku[i-1] + B[currentIndexB]
        currentIndexB += 1
    elif currentIndexB >= M and currentIndexA < N:
        tsundoku[i] = tsundoku[i-1] + A[currentIndexA]
        currentIndexA += 1
    elif currentIndexA >= N and currentIndexB >= M:
        print(i)
        exit()
    elif A[currentIndexA] < B[currentIndexB]:
        if i == 0:
            tsundoku[i] = A[currentIndexA]
        else:
            tsundoku[i] = tsundoku[i-1] + A[currentIndexA]
        currentIndexA += 1
    else:
        if i == 0:
            tsundoku[i] = B[currentIndexB]
        else:
            tsundoku[i] = tsundoku[i-1] + B[currentIndexB]
        currentIndexB += 1

    if tsundoku[i] > K:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

bs = 0
ans = 0

i = 0
while i < n:
    if a[i] <= k:
        k -= a[i]
        bs += 1
        ans = max(ans, bs)
    else:
        break
    i += 1
i = min(i, n - 1)

j = 0
while j < m:
    while i >= 0 and b[j] > k:
        k += a[i]
        bs -= 1
        i -= 1
    if b[j] <= k:
        k -= b[j]
        bs += 1
        ans = max(ans, bs)
    else:
        break
    j += 1

print(ans)

Submission status: Wrong Answer

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

if A[0] > K and B[0] > K:
    print(0)
    exit()

tsundoku = [0]*(N+M)
currentIndexA = 0
currentIndexB = 0
for i in range(N+M+1):
    if currentIndexA >= N and currentIndexB < M:
        tsundoku[i] = tsundoku[i-1] + B[currentIndexB]
        currentIndexB += 1
    elif currentIndexB >= M and currentIndexA < N:
        tsundoku[i] = tsundoku[i-1] + A[currentIndexA]
        currentIndexA += 1
    elif currentIndexA >= N and currentIndexB >= M:
        print(i)
        exit()
    elif A[currentIndexA] < B[currentIndexB]:
        if i == 0:
            tsundoku[i] = A[currentIndexA]
        else:
            tsundoku[i] = tsundoku[i-1] + A[currentIndexA]
        currentIndexA += 1
    else:
        if i == 0:
            tsundoku[i] = B[currentIndexB]
        else:
            tsundoku[i] = tsundoku[i-1] + B[currentIndexB]
        currentIndexB += 1

    print(tsundoku[i])
    if tsundoku[i] > K:
        print(i)
        exit()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
acc = sum(B)
j = M - 1
if acc + sum(A) <= K:
    print(M + N)
    exit()
ans = 0
for i in range(N):
    acc += A[i]
    if acc <= K:
        ans = max(ans, i + j + 2)
        continue
    else:
        while acc > K:
            acc -= B[j]
            j -= 1
            if (j == -1) & (acc > K):
                print(ans)
                exit()
            elif (j == -1) & (acc <= K):
                ans = max(ans , i + j + 2)
                exit()
        ans = max(ans, i + j + 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right, bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0]+a
b = [0]+b+[1e9+10]
ans = 0
for i in range(1, len(a)):
    a[i]+=a[i-1]
for i in range(1, len(b)):
    b[i]+=b[i-1]
for i in range(n+1):
    if a[i]>k: break
    rim = k-a[i]
    sub = bisect_left(b, rim)
    if sub == n+1: sub = n
    elif b[sub] != rim: sub-=1
    cnt = i+sub
    print(cnt)
    if ans<cnt: ans = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
T = 0
p,q = 0,0
ret = 0
while True:
  if T > k:
    ret = p + q - 1
    break
  elif T == k:
    ret = p + q
    break
  elif p > len(A) - 1 and q > len(B) - 1:
    ret = len(A) + len(B)
    break
  else:
      if p > len(A) - 1 and q < len(B):
          T += B[q]
          q += 1
      elif p < len(A) and q > len(B) - 1:
          T += A[p]
          p += 1 
      else:
          if A[p] < B[q]:
              T += A[p]
              p += 1
          else:
              T += B[q]
              q += 1

print(ret)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=[0]
B=[0]
p=0
q=0
ans=0

for i in range (n):
  p+=a[i]
  A.append(p)
for i in range (m):
  q+=b[i]
  B.append(q)

import bisect
for i in range (n+1):
  if A[i]<=k:
    index = bisect.bisect_right(B, k-A[i])
    ans = max(ans, index+i-1)
    print(index,ans,i)
    
  if A[i]>k:
    break
 
print(ans)

Submission status: Wrong Answer

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

ans = 0
minute = 0
i, j = 0, 0

while i < n and j < m and minute <= k:
    if a[i] <= b[j]:
        minute += a[i]
        i += 1
    else:
        minute += b[j]
        j += 1

    if minute > k:
        break
    else:
        ans += 1

while i < n and minute <= k:
    minute += a[i]
    if minute > k:
        break
    else:
        i += 1
        ans += 1

while j < m and minute <= k:
    minute += b[j]
    if minute > k:
        break
    else:
        j += 1
        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()))
T = 0
p,q = 0,0
ret = 0
while True:
  if T > k:
    ret = p + q - 1
    break
  elif p > len(A) - 1 and q > len(B) - 1:
    ret = len(A) + len(B)
    break
  else:
      if p > len(A) - 1 and q < len(B):
          T += B[q]
          q += 1
      elif p < len(A) and q > len(B) - 1:
          T += A[p]
          p += 1 
      else:
          if A[p] < B[q]:
              T += A[p]
              p += 1
          else:
              T += B[q]
              q += 1

print(ret)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_right

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

ac = np.cumsum(a)
bc = np.cumsum(b)
ans = 0

# if k < ac[0]:
#     print(bisect_right(bc, k))
#     exit()

for i in range(n):
    if k < ac[i]:
        break
    time = k - ac[i]
    j = bisect_right(bc, time)
    ans = max(ans, j + i + 1)

print(ans)

Submission status: Wrong Answer

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

ans = 0
minute = 0
i, j = 0, 0

while i < n and j < m and minute <= k:
    if a[i] <= b[j]:
        minute += a[i]
        i += 1
    else:
        minute += b[j]
        j += 1

    if minute > k:
        break
    else:
        ans += 1

while i < n and minute <= k:
    minute += a[i]
    if minute > k:
        break
    else:
        i += 1
        ans += 1

while j < m and minute <= k:
    minute += b[j]
    if minute > k:
        break
    else:
        j += 1
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N, M, K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))

bls = list(itertools.accumulate(bl))
#print(bls)
ans = 0
for i in range(N):
    nokori = K - sum(al[:i+1])
    if nokori >= 1:
        index = bisect.bisect_right(bls,nokori)
        tmp = i + index + 1

        if tmp > ans:
            ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N, M ,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA =[A[0]]
for i in A[1:]:
    SA.append(SA[-1] + i)
SB =[0]
for i in B:
    SB.append(SB[-1] + i)

i = bisect_left(SA, K)
SA = SA[: i+1]
if SA[-1] > K: SA.pop()
i = bisect_left(SB, K)
SB = SB[: i+1]
if SB[-1] > K: SB.pop()

i, ii = 0, 0
j = len(SB) - 1
ans = [j]
while j >= 0:
    diff = K - SB[j]
    jdg = False
    for ii in range(i, len(SA)):
        if SA[ii] > diff:
            jdg = True
            break
    i = ii
    if jdg or i==0: ans.append(i + j)
    else: ans.append(i + 1 + j) 
    j -= 1
print(max(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_right

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

ac = np.cumsum(a)
bc = np.cumsum(b)
ans = 0

if k < ac[0]:
    print(bisect_right(bc, k))
    exit()

for i in range(n):
    if k <= ac[i]:
        break
    time = k - ac[i]
    j = bisect_right(bc, time)
    ans = max(ans, j + i + 1)

print(ans)

Submission status: Wrong Answer

Solution code:
m,n,k = map(int,input().split())
arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
ans = arr1 + arr2
ans.sort()
pos = 0
while k > ans[pos] :
  k = k - ans[pos]
  pos = pos + 1 
print(pos+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, k = rli()
	A = deque(rli())
	B = deque(rli())
	L = deque()
	p, q = 0, 0
	currsum = 0
	for i, a in enumerate(A):
		if currsum + a <= k:
			currsum += a
			p += 1
		else:
			break
	cnt = p 
	for np in range(p, 0, -1):
		for i in range(q, len(B)):
			add = B[i]
			if add + currsum <= k:
				currsum += add
				q += 1
			else:
				break
		# print(f"At p, q = {np, q}, currsum = {currsum}")
		currsum -= A[np-1] if np > 0 else 0
		cnt = max(cnt, np + q)
	print(cnt)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
x,y,z= map(int,input().split())
left = list(map(int,input().split()))
right = list(map(int,input().split()))
array = left+right
array.sort()
#print(array)
x=[0]*len(array)

for i in range(len(array)):
  x[i]=array.pop(0)
  #print(sum(x))
  if (sum(x) > z):
    x.pop(-1)
    break
#print(left+right)
#print(z)
#print(sum(x))
#print(x)
print(len(x))

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, k = rli()
	A = deque(rli())
	B = deque(rli())
	L = deque()
	p, q = 0, 0
	currsum = 0
	for i, a in enumerate(A):
		if currsum + a <= k:
			currsum += a
			p += 1
		else:
			break
	cnt = p 
	for np in range(p, 0, -1):
		for i in range(q, len(B)):
			add = B[i]
			if add + currsum <= k:
				currsum += add
				q += 1
			else:
				break
		# print(f"At p, q = {np, q}, currsum = {currsum}")
		currsum -= A[np-1]
		cnt = max(cnt, np + q)
	print(cnt)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_array = [int(x) for x in input().split()]
b_array = [int(x) for x in input().split()]
res = 0
aggregate = [0]
a_index = 0
b_index = 0
while not (a_index == n and b_index == m):
    next_val = 0
    if b_index == m:
        next_val = a_array[a_index]
        a_index += 1
    elif a_index == n:
        next_val = b_array[b_index]
        b_index += 1
    elif a_array[a_index] < b_array[b_index]:
        next_val = a_array[a_index]
        a_index += 1
    else:
        next_val = b_array[b_index]
        b_index += 1
    aggregate.append(aggregate[-1] + next_val)
    if k < aggregate[-1]:
        print(len(aggregate)-2)
        break
else:
    print(len(aggregate)-1)

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

def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    A = [0] + list(accumulate(A))
    B = [0] + list(accumulate(B))

    def is_ok(arg, a):
        # b <= K - a
        # print(arg, B[arg], a, K, B[arg] <= K - a)
        return B[arg] <= K - a

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

    # print(A)
    # print(B)
    ans = 0
    for i, a in enumerate(A):
        idx = meguru_bisect(M+1, -1, a)
        if 0 <= idx <= M:
            ans = i + idx
    print(ans)

        



if __name__ == '__main__':
    solve()

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()))
sum_list = []
for i in range(N):
  if K < sum(A[:i+1]):
    break
  for j in range(M):
    sum_ = sum(A[:i+1]) + sum(B[:j+1])
    if sum_ <= K:
      sum_list.append(len(A[:i+1]) + len(B[:j+1]))
    elif K < sum_:
      break
if 1 <= len(sum_list):
  print(max(sum_list))
elif 0 == len(sum_list):
  print(0)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N, M ,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA =[A[0]]
for i in A[1:]:
    SA.append(SA[-1] + i)
SB =[0]
for i in B:
    SB.append(SB[-1] + i)

i = bisect_left(SA, K)
SA = SA[: i+1]
if SA[-1] > K: SA.pop()
i = bisect_left(SB, K)
SB = SB[: i+1]
if SB[-1] > K: SB.pop()

i = 0
j = len(SB) - 1
ans = [j]
while j > 0:
    diff = K - SB[j]
    jdg = False
    for ii in range(i, len(SA)):
        if SA[ii] > diff:
            jdg = True
            break
    i = ii
    if jdg: ans.append(i + j)
    else: ans.append(i + 1 + j) 
    j -= 1
print(max(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()))
total = 0
books = 0
i = 0

while(i<len(a)):
    total += a[i]
    #print(total)
    if total > k:
        total -= a[i]
        #print("here"+str(i))
        break
    books += 1
    i += 1
    #print("a"+str(i))
 
i -= 1
#print(i) 
max_books = books 

for j in range(books):
    l = 0
    while(l<len(b)):
        total += b[l]
        #print(total)
        
        if total > k:
            #print("break")
            total -= b[l]
            break 
        books += 1
        if books > max_books:
            max_books = books 
        l += 1
    if i >= 0:
        total -= a[i]
        books -= 1
        i -= 1
    #print(total)

print(max_books)

Submission status: Wrong Answer

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

timer = 0
counter = 0

if int(A[0])>K & int(B[0])>K:
  pass
else: 
  while(timer <= K ):
    if (len(A) == 0) & (len(B) == 0):
      break
    elif (int(A[0]) > timer) & (int(B[0]) > timer):
      break
    elif (len(A) > 0) & (len(B) > 0):
      timer += min(int(A[0]),int(B[0]))
      if timer <= K:
        counter += 1
      elif timer > K:
        break
      if min(int(A[0]),int(B[0])) == int(A[0]):
        A.remove(A[0])
      elif min(int(A[0]),int(B[0])) == int(B[0]):
        B.remove(B[0])
    elif len(A) == 0:
      timer += int(B[0])
      B.remove(B[0])
      if timer <= K:
        counter += 1
      else:
        break
    elif len(B) == 0:
      timer += int(A[0])
      A.remove == 0
      if timer <= K:
        counter += 1
      else:
        break
    
print(counter)

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

sum = 0
cnt = 0

for i in range(N+M):
    
    if 0 < len(A) and 0< len(B):
        if A[0] < B[0]:
            sum += A[0]
            del A[0]
            cnt +=1
        else:
            sum += B[0]
            del B[0]
            cnt +=1
    elif    1 > len(A):
        if len(B) > 0:
            sum += B[0]
            del B[0]
            cnt +=1
    elif  1 > len(B):
        if len(A) > 0:
            sum += A[0]
            del A[0]
            cnt +=1
            
            
    if sum > K:
        cnt = cnt -1
        break
    
    if len(A)==0 and len(B)==0:
        break
        
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, k = rli()
	A = deque(rli())
	B = deque(rli())
	L = deque()
	mins, cnt = 0, 0
	while A or B:
		if not B:
			L.append(A.popleft())
		elif not A:
			L.append(B.popleft())
		else:
			if A[0] <= B[0]:
				L.append(A.popleft())
			else:
				L.append(B.popleft())
	while L and mins <= k:
		add = L.popleft()
		mins += add
		if mins <= k:
			cnt += 1
	print(cnt)
	stdout.close()

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

timer = 0
counter = 0

if int(A[0])>K & int(B[0])>K:
  pass
else: 
  while(timer <= K ):
    if (len(A) == 0) & (len(B) == 0):
      break
    elif (len(A) > 0) & (len(B) > 0):
      timer += min(int(A[0]),int(B[0]))
      if timer <= K:
        counter += 1
        continue
      elif timer > K:
        break
      if min(int(A[0]),int(B[0])) == int(A[0]):
        A.remove(A[0])
        continue
      elif min(int(A[0]),int(B[0])) == int(B[0]):
        B.remove(B[0])
        continue
    elif len(A) == 0:
      timer += int(B[0])
      B.remove(B[0])
      if timer <= K:
        counter += 1
        continue
      else:
        break
    elif len(B) == 0:
      timer += int(A[0])
      A.remove == 0
      if timer <= K:
        counter += 1
        continue
      else:
        break
    
print(counter)

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

timer = 0
counter = 0

if int(A[0])>K & int(B[0])>K:
  pass
else: 
  while(timer <= K ):
    if (len(A) == 0) & (len(B) == 0):
      break
    elif (len(A) > 0) & (len(B) > 0):
      timer += min(int(A[0]),int(B[0]))
      if timer <= K:
        counter += 1
      elif timer > K:
        break
      if min(int(A[0]),int(B[0])) == int(A[0]):
        A.remove(A[0])
      elif min(int(A[0]),int(B[0])) == int(B[0]):
        B.remove(B[0])
    elif len(A) == 0:
      timer += int(B[0])
      B.remove(B[0])
      if timer <= K:
        counter += 1
      else:
        break
    elif len(B) == 0:
      timer += int(A[0])
      A.remove == 0
      if timer <= K:
        counter += 1
      else:
        break
    
print(counter)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m, k = rli()
	A = deque(rli())
	B = deque(rli())
	mins = 0
	cnt = 0
	while (A or B) and mins <= k:
		if not A:
			add = B.popleft()
		elif not B:
			add = A.popleft()
		else:
			if A[0] <= B[0]:
				add = A.popleft()
			else:
				add = B.popleft()
		if mins + add <= k:
			mins += add
			cnt += 1
		else:
			break
	print(cnt)
	stdout.close()

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

count=0
time=0

while time <= K:
    if A == [] and B==[]:
        break
    elif A == [] and B != []:
        count+=1
        time += B[0]
        del B[0]
    elif A != [] and B ==[]:
        count += 1
        time += A[0]
        del A[0]
    else:
        if A[0] > B[0]:
            count += 1
            time += A[0]
            del A[0]
        else:
            count += 1
            time += B[0]
            del B[0]


print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sum_list = []
for i in range(N):
  for j in range(M):
    sum_ = sum(A[:i+1]) + sum(B[:j+1])
    if sum_ <= K:
      sum_list.append(len(A[:i+1]) + len(B[:j+1]))
    elif K < sum_:
      break
if 1 <= len(sum_list):
  print(max(sum_list))
elif 0 == len(sum_list):
  print(0)

Submission status: Wrong Answer

Solution code:
n, m, k = tuple(map(int, input().split()))
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

readed = 0
t = 0

xi = 0
yi = 0

while True:
    if xi <= n -1 and (xs[xi] + t <= k):
        t += xs[xi]
        readed += 1
        xi += 1
    elif yi <= m -1 and (ys[yi] + t <= k):
        t += ys[yi]
        readed += 1
        yi += 1
    else:
        break

print(readed)

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()))
time = 0
count = 0
while True:
    aa = a[0] if len(a)>0 else float("inf")
    bb = b[0] if len(b)>0 else float("inf")
    if(aa < bb):
        time+=aa
        a.pop(0)
    else:
        time+=bb
        b.pop(0)
    if(time > k):
        break
    count += 1
    if(len(a) == 0 and len(b) ==0):
        break
    
    
print(count)

Submission status: Wrong Answer

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

for n in range(1, N+1):
  time = sum(A[:n])
  if K < time:
    break
  for m in range(1, M+1):
    if K < time + B[m-1]:
      m -= 1
      break
    else:
      time += B[m-1]
  ans = max(ans, m+n)
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, 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])

print(A)
print(B)
    
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:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)
j=1
while j<=m and b[j]+b[j-1]<=k:
  b[j]+=b[j-1]
  j+=1
  

j-=1
books=j
i=1
while i<n+1:
  while j>0 and a[i]+b[j]>k:
    j-=1
  if(j>=0) and a[i]+b[j]<=k:
    books=max(books,j+i)
    a[i]+=a[i-1]
    i+=1
  else:
    break
print(books)

Submission status: Wrong Answer

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

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, 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:
# abc172_c.py
N, M ,K= map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
cnt = 0
a_idx = 0
b_idx = 0

for i in range(N + M + 1):
    if a_idx > N-1:
        ans += B[b_idx]
        b_idx += 1
    elif b_idx > M-1:
        ans += A[a_idx]
        a_idx += 1
    else:
        if A[a_idx] < B[b_idx]:
            ans += A[a_idx]
            a_idx += 1
        else:
            ans += B[b_idx]
            b_idx += 1
    # print(a_idx,b_idx,cnt)
    if ans > K:
        break
    if ans == K:
        cnt+=1
        break
    cnt+=1
print(cnt)