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 itertools
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

i, j = n//2, m//2
suma, sumb = sum(a[0:n//2]), sum(a[0:m//2])
flaga, flagb = True, True

while True:

    if i < len(a) and i >= 0:
        if k > suma:
            if k - suma >= a[i]:
                suma += a[i]
                i += 1
            else:
                flaga = False
        elif k < suma:
            if suma - k >= a[i]:
                suma -= a[i]
                i -= 1
            else:
                flaga = False
        else:
            flaga = False

    else:
        flaga = False

    if j < len(b) and j >= 0:
        if k > sumb:
            if k - sumb >= b[j]:
                sumb += b[j]
                j += 1
            else:
                flagb = False
        elif k < sumb:
            if sumb - k >= b[j]:
                sumb -= b[j]
                j -= 1
            else:
                flagb = False
        else:
            flagb = False
    else:
        flagb = False

    if not flaga:
        if not flagb:
            break


br = False
maxbooks = 0

if i >= j:
    for x in range(i-1, -1, -1):
        for y in range(j-1, -1, -1):
            if sum(a[0:x+1]) + sum(b[0:y+1]) <= k:
                books = x + y + 2
                maxbooks = max(maxbooks, books)
                br = True
                break
        if br:
            break

else:
    for y in range(j-1, -1, -1):
        for x in range(i-1, -1, -1):
            if sum(a[0:x+1]) + sum(b[0:y+1]) <= k:
                books = x + y + 2
                maxbooks = max(maxbooks, books)
                br = True
                break
        if br:
            break
print(maxbooks)

Submission status: Wrong Answer

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

A.append(10**10)
B.append(10**10)

lst = []
i = 0
j = 0
while(i < N or j < M):
    if A[i] > B[j]:
        lst.append(B[j])
        j += 1
    elif A[i] < B[j]:
        lst.append(A[i])
        i += 1
    else:
        tmpi = i
        tmpj = j
        while(tmpi <= N or tmpj <= M):
            if A[tmpi] == 10**10 and B[tmpj] == 10**10:
                lst.append(A[i])
                i +=  1
                break
            elif A[tmpi] < B[tmpj]:
                lst.append(A[i])
                i +=  1
                break
            elif A[tmpi] > B[tmpj]:
                lst.append(B[j])
                j +=  1
                break
            else:
                tmpi += 1
                tmpj += 1
            
ans = 0
for elem in lst:
    K -= elem
    ans += 1
    if K < 0:
        ans -= 1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
aes = list(map(int, input().split()))
bs = list(map(int, input().split()))
r_aes = [0]*n
for i in range(1,n):
    aes[i] += aes[i-1]
for i in range(1,m):
    bs[i] += bs[i-1]
cnt_a = 0
for i in range(n):
    if aes[i] > k:
        break
    cnt_a += 1
cnt_b = 0
res = cnt_a
#cnt = 5
while True:
    #print("cnt_a: "+str(cnt_a))
    #print("cnt_b: " + str(cnt_b))
    if cnt_b >= m or bs[cnt_b] > k:
        break
    if cnt_a >= 1 and k-aes[cnt_a-1]>=bs[cnt_b]:
        cnt_b += 1
        res = max(res,cnt_a+cnt_b)
        continue
    if cnt_a < 1 and k>=bs[cnt_b]:
        cnt_b += 1
        res = max(res,cnt_a+cnt_b)
        continue
    cnt_a -= 1
    if cnt_a < 1:
        break
    #if cnt<= 0:
        #break
print(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()))
a.append(10**9+1)
b.append(10**9+1)
# k分以内
ans=0
i=0
while True:
    if a[0]>b[0]:
        ans+=b.pop(0)
    else:
        ans+=a.pop(0)
        
    if ans>k:
        print(i)
        quit()
    i+=1

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
ans = -1
ia = 0
ib = 0
while c <= K:
  if ia == N and ib == M:
    c = K+1
   
  elif ia == N:
    c += B[ib]
    ib += 1
     
  elif ib == M:
    c += A[ia]
    ia += 1
    
  elif A[ia] <= B[ib]:
    c += A[ia]
    ia += 1
     
  elif A[ia] > B[ib]:
    c += B[ib]
    ib += 1
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N_M_K_str = input().split()
A_str = input().split()
B_str = input().split()

N_M_K = [int(s) for s in N_M_K_str]
A = [int(s) for s in A_str]
B = [int(s) for s in B_str]

limit = N_M_K[2]
time = 0
count = 0


for i in range(N_M_K[0] + N_M_K[1]):
    if A != [] and B != []:
        if A[0] + time > limit and B[0] + time > limit:
            break
        elif A[0] > B[0]:
            time += B[0]
            count += 1
            B.pop(0)
        elif A[0] < B[0]:
            time += A[0]
            A.pop(0)
            count += 1
    elif A == []:
        if B[0] + time <= limit:
            time += B[0]
            count += 1
            B.pop(0)
        elif B[0] + time > limit:
            break
    elif B == []:
        if A[0] + time <= limit:
            time += A[0]
            count += 1
            A.pop(0)
        elif A[0] + time > limit:
            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()))

cnt=0

#Aのみ読んだ場合を考える
for a in A:
  if K >= a:
    K-=a
    cnt+=1
  else:
    break

maxcnt=cnt
A=A[: cnt ]
#print(A,K)
for i,b in enumerate(B):
  #aの要素なくしてbを入れる
  #bがいれれるまでaをなくすよ
  while b>K and len(A)!=0:
    a = A.pop()
    K += a
    cnt -= 1
    #print('-a,',a,K)
    
  if len(A) == 0:
    _B=B.copy()[i:]
   # print(_B)
    _B.pop(0)
    #まだbが入るかもしれない…！
    while(len(_B)>0 and K>=b):
      K-=b
      cnt+=1
      #print('+b(while),',b,K,cnt)
      b=_B.pop(0)
    if maxcnt < cnt:
      maxcnt=cnt
    break

  K -= b
  cnt+=1
  #print('+b,',b,K,cnt)
  
  if maxcnt < cnt:
    maxcnt=cnt



print(maxcnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = deque(A)
b = deque(B)
ans = 0
while a and b:
    if K - a[0] >= 0 or K - b[0] >= 0:
        if a[0] > b[0]:
            x = b.popleft()
            K = K - x
            ans += 1
        elif a[0] < b[0]:
            x = a.popleft()
            K = K - x
            ans += 1
        else:
            chk_a = 0
            chk_b = 0
            for i in range(min(len(a), len(b))):
                chk_a += a[i]
                chk_b += b[i]
                print('aa')
                if chk_a < chk_b:
                    x = a.popleft()
                    K = K - x
                    ans += 1
                    break
                elif chk_a > chk_b:
                    x = b.popleft()
                    K = K - x
                    ans += 1
                    break
                else:
                    continue
    else:
        break
C = list(a) + list(b)
c = deque(C)
while c:
    if K - c[0] >= 0:
        x = c.popleft()
        K = K - x
        ans += 1
    else:
        break
print(ans)

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

    T = 0
    TA = 0
    C = []

    if A[0] > B[0]:
        A, B = B, A

    for i, a in enumerate(A):
        TA += a
        C.append(i + 1)

        if TA > K:
            C[i] -= 1
            break

        T = TA
        for b in B:
            T += b
            C[i] += 1
            if T > K:
                C[i] -= 1
                break

    print(max(C))


if __name__ == '__main__':
    main()

exit()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    n, m, k = map(int,input().split(' '))
    A = list(map(int,input().split(' ')))
    B = list(map(int,input().split(' ')))
    A.insert(0, 0)
    a = deque([A[i-1]+A[i] for i in range(n)])
    B.insert(0, 0)
    b = deque([B[i-1]+B[i] for i in range(m)])

    time = 0
    cnt = 0
    while True:
        if len(a) == 0:
            time += b.popleft()
        elif len(b) == 0:
            time += a.popleft()
        else:
            if a[0]<b[0]:
                time += a.popleft()
            else:
                time += b.popleft()
        if time > k:
            break
        cnt += 1
        if len(a)==0 and len(b) == 0:
            break
    
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    n = 0
    k = 0
    i = 0
    j = 0
    while k <= K:
        if i == N and j == M:
            break
        if i < N and j < M:
            if A[i] < B[j]:
                if k + A[i] <= K:
                    n += 1
                    k += A[i]
                    i += 1
                else:
                    break
            else:
                if k + B[j] <= K:
                    n += 1
                    k += B[j]
                    j += 1
                else:
                    break
        elif i == N:
            n += 1
            k += B[j]
            j += 1
        elif j == M:
            n += 1
            k += A[i]
            i += 1

    print(n)

resolve()

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()]
s = 0
ans = 0
ca = 0
for i in range(n):
  if k >= s + a[i]:
    s += a[i]
    ans += 1
    ca += 1
  else:
    break
cb = 0
for i in range(m):
  if k >= s + b[i]:
    s += b[i]
    ans += 1
    cb += 1
  else:
    break
if ans == n + m or ans == 0:
  print(ans)
else:
  l = [ans]
  while ca >= 0:
    s + a[ca - 1]
    ca -= 1
    ans -= 1
    if k >= s + b[cb - 1]:
      s += b[cb - 1]
      cb += 1
      ans += 1
      l.append(s)
  print(max(l))

Submission status: Wrong Answer

Solution code:
NMK = list(map(int, input().split()))

Asum = []
Bsum = []

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

sum = 0
for i in range(NMK[0]):
    sum += A[i]
    Asum.append(sum)

sum = 0
for i in range(NMK[1]):
    sum += B[i]
    Bsum.append(sum)

cutA = 0
max = NMK[2]
indexA = 0
while(True):
    cutA = Asum[indexA]
    if (max < cutA):
        break
    indexA += 1
    if (indexA == NMK[0]):
        break
if (indexA == 0):
    maxA = 0
else:
    maxA = Asum[indexA - 1]

cutB = 0
indexB = 0
while(True):
    cutB = Bsum[indexB]
    if (max < cutB):
        break
    indexB += 1
    if (indexB == NMK[1]):
        break
if (indexB == 0):
    maxB = 0
else:
    maxB = Bsum[indexB - 1]

answer = 0
remain = 0
index = 0
if (indexA > indexB):
    answer = indexA
    remain = NMK[2] - maxA
    while(index < NMK[1] and remain >= Bsum[index]):
        answer += 1
        index += 1
elif (indexB > indexA):
    answer = indexB
    remain = NMK[2] - maxB
    while(index < NMK[0] and remain >= Asum[index]):
        answer += 1
        index += 1
else:
    if (maxA < maxB):
        answer = indexA
        remain = NMK[2] - maxA
        while (index < NMK[1] and remain >= Bsum[index]):
            answer += 1
            index += 1
    elif (maxA > maxB):
        answer = indexB
        remain = NMK[2] - maxB
        while (index < NMK[0] and remain >= Asum[index]):
            answer += 1
            index += 1
    else:
        if (maxA != 0):
            answer = indexA
            remain = NMK[2] - maxA
            while (index < NMK[1] and remain >= Bsum[index]):
                answer += 1
                index += 1

            tmp = 0
            index = 0
            tmp = indexB
            remain = NMK[2] - maxB
            while (index < NMK[0] and remain >= Asum[index]):
                tmp += 1
                index += 1

            answer = answer if answer > tmp else tmp

print(answer)

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
MIN = 0
satsu = 0

for i in range(N+M):
    if TIME + MIN >= K:
        break
    else:
        if A[0] < B[0]:
            MIN = A[0]
        else:
            MIN = B[0]
        TIME += MIN
        satsu += 1

print(satsu)

Submission status: Wrong Answer

Solution code:

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

time = 0
books = 0
for i in range(N+M):
    if not A:
        if not B:
            break
        if (time + B[0]) > K:
            break
        else:
            Time = B.pop(0)
            time += Time
            books += 1

    elif not B:
        if (time + A[0]) > K:
            break
        else:
            Time = A.pop(0)
            time += Time
            books += 1
    elif (time + min(A[0], B[0]))> K:
        break
    else:
        if A[0] < B[0]:
            Time = A.pop(0)
            time += Time
            books += 1
        else:
            Time = B.pop(0)
            time += Time
            books += 1

print(books)

Submission status: Wrong Answer

Solution code:
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

a = [int(s) for s in data[1].split()]
b = [int(s) for s in data[2].split()]

c = [0]
time = 0
for i in reversed(range(1,n+m+1)):
    for j in range(0,i+1):
        if j <= n and 0 <= i-j <= m:
            if sum(a[0:j])+sum(b[0:i-j]) <= k:
                print(i)
                break
    else:
        continue
    break

Submission status: Wrong Answer

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



Kc=K
bookc=0

Ai=0
Bi=0

while Kc>0:
    if Ai<N:
        if Bi<M:
            if A[Ai]<=B[Bi] and A[Ai]<=Kc:
                bookc+=1
                Kc-=A[Ai]
                Ai+=1

            elif B[Bi]<=Kc:
                bookc+=1
                Kc-=B[Bi]
                Bi+=1
            else:
                break
        elif A[Ai]<=Kc:
            bookc+=1
            Kc-=A[Ai]
            Ai+=1
        else:
            break
    elif Bi<M:
        if B[Bi]<=Kc:
            bookc+=1
            Kc-=B[Bi]
            Bi+=1
        else:
            break

print(bookc)

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()))
books = 0
i,j = 0,0
bsum = 0
while i<n and j<m:
    if a[i]<b[j]:
        if bsum+a[i]<=k:
            books += 1
            bsum += a[i]
            i += 1
        else:
            break
    else:
        if bsum+b[j]<=k:
            books += 1
            bsum += b[j]
            j += 1
        else:
            break
while i<n:
    if bsum + a[i] <= k:
        books += 1
        bsum += a[i]
        i += 1
    else:
        break
while j<m:
    if bsum + b[j] <= k:
        books += 1
        bsum += b[j]
        j += 1
    else:
        break
print(books)

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque

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


count = 0
time = 0
#もし先にどっちかの玉が尽きた時の問題。
for i in range(10**8):
    #本が尽きていない。
    if len(A) != 0 and len(B) != 0:

        if A[0] < B[0]:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()

        elif A[0] > B[0]:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        else:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
    else:
        #どっかの本が尽きている。
        if len(A) == 0 and len(B) != 0:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        elif len(A) != 0 and len(B) == 0:
            time = time +A[0]
            if time <= K:
                count = count + 1
                A.popleft()
            elif time == K or time > K:
                print(count)
                sys.exit()
        elif len(A) == 0 and len(B) == 0:
            print(count)
            sys.exit()
               


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
aa = 0
bb = 0
p = k

for i in range(n):
    if p - a[i] <0:
        break
    else:
        p -= a[i]
        aa += 1
ans = aa
#print(ans)

for i in range(m):
    if p - b[i] >= 0:
        p -= b[i]
        bb += 1
        if ans < aa + bb:
            ans = aa + bb
    else:
        while aa > 0:
            aa -= 1
            #print(aa)
            #print(aa)
            p += a[aa]
            if p - b[i] >= 0:
                p -= b[i]
                bb += 1
                break

        if ans < aa + bb:
            ans = aa + bb
        #if aa <= 0:
        #    break
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(a,b,n,m,k):
	i=0
	j=0
	ans=0
	while(i<n and j<m):
		if(a[i]<=b[j]):
			if(k-a[i]<0):
				print(ans)
				return
			k-=a[i]
			i+=1
			ans+=1
		else:
			if(k-b[j]<0):
				print(ans)
				return
			k-=b[j]
			j+=1
			ans+=1
	while(i<n):
		if(k-a[i]<0):
			print(ans)
			return
		k-=a[i]
		ans+=1
		i+=1
	while(j<m):
		if(k-b[j]<0):
			print(ans)
			return
		k-=b[j]
		ans+=1
		j+=1
	print(ans)



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

Submission status: Wrong Answer

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

S = [0]

Sum = 0


for i in range(N):
  K = K - A[i]
  if K >= 0:
    Sum += 1
  else:
    K = K + A[i]
    break
S.append(Sum)

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if i == 0:
      break
    for k in range(i):
      K = K + A[i-k-1]
      Sum = Sum - 1
      if K >= 0:
        i = i-k-1
        break
    if K >= 0:
      Sum += 1
    else:
      break
  S.append(Sum)
print(max(S))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
read_list = []
cnt = 0

diffvalue = max(n, m) - min(n, m)

# for i in range(diffvalue):
#     if n > m:
#         b_lst.append(999999999)
#     else:
#         a_lst.append(999999999)

# print(a_lst, b_lst)


while sum(read_list) <= k:

    if len(a_lst) == 0 and len(b_lst) == 0:
        cnt += 1
        break

    elif len(a_lst) == 0:
        read_list.append(b_lst[0])
        del b_lst[0]
    elif len(b_lst) == 0:
        read_list.append(a_lst[0])
        del a_lst[0]
    else:
        x = min(a_lst[0], b_lst[0])
        # print(x)
        read_list.append(x)

        if a_lst <= b_lst:
            del a_lst[0]
        else:
            del b_lst[0]

    cnt += 1

cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=np.cumsum(np.array([0]+a))
B=np.cumsum(np.array([0]+b))
ans=n+m
i=n
j=m
while A[i]+B[j]>k:
    if A[i]>B[j]:
        i-=1
    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()))
 
ans_list = []
ans_list.append(0)

sum_a = 0
for i in range(len(a)):
  sum_a += a[i]
  sum_b = 0
  if sum_a > k:
    break
  if sum_a == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(b)):
    if max(ans_list) < i+1+j:
      pass
    else:
      sum_b += b[j]
      if (sum_a + sum_b) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_a + sum_b) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
sum_b = 0
for i in range(len(b)):
  sum_b += b[i]
  sum_a = 0
  if sum_b > k:
    break
  if sum_b == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(a)):
    if max(ans_list) < i+1+j:
      pass
    else:
      sum_a += a[j]
      if (sum_b + sum_a) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_b + sum_a) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
print(max(ans_list))

Submission status: Wrong Answer

Solution code:
N, M ,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(2*10**10)
B.append(2*10**10)
A.append(2*10**10)
B.append(2*10**10)
 
ans = 0
t = 0
ia, ib = 0, 0
while t < K and (ia < N or ib < M):
    if A[ia] + A[ia+1] <= B[ib] + B[ib+1]:
        if t + A[ia] <= K:
            t += A[ia]
            ans += 1
            ia += 1
        else: break
    else:
        if t + B[ib] <= K:
            t += B[ib]
            ans += 1
            ib += 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()))

i = 0
for s in range(n+m):
    if i>k:
        if a[0]>=b[0]:
            i = i + a[0]
            del a[0]
        else:
            i = i + b[0]
            del a[0]
    else:
        print(s-1)

Submission status: Wrong Answer

Solution code:


def main3():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    time_sum = 0
    counter = 0
    ans = []

    if bb[0] >= aa[0]:
        if k < aa[0]:
            return counter
    if bb[0] <= aa[0]:
        if k < bb[0]:
            return counter

    if (sum(aa)+sum(bb)) <= k:
        return n+m

    for i in range(n+1):
        counter = i
        time_sum = sum(aa[:i])
        if time_sum > k:
            break
        elif time_sum == k:
            counter += 1
            ans.append(counter)
        else:
            for j in range(m):
                time_sum += bb[j]
                if time_sum < k:
                    counter += 1
                elif time_sum == k:
                    counter += 1
                    ans.append(counter)
                else:
                    ans.append(counter)
                    break

    if len(ans) == 1:
        return ans[0]
    else:
        return max(ans)


if __name__ == '__main__':
    ans = main3()
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)

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

ans_cand = []

def dfs(a_i, b_i, ans, time):
    if a_i < N and time + A[a_i] <= K:
        dfs(a_i + 1, b_i, ans + 1, time + A[a_i])
    else:
        return ans_cand.append(ans)

    if b_i < M and time + B[b_i] <= K:
        dfs(a_i, b_i + 1, ans + 1, time + B[b_i])
    else:
        return ans_cand.append(ans)


dfs(0, 0, 0, 0)

print(max(ans_cand))

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,K=nm()
INF=10**18
A=nl()
B=nl()
A.append(INF)
B.append(INF)
A_c=0
B_c=0
ans=0
sum_l_A=[INF]*(N+2)
sum_l_B=[INF]*(M+2)

sum_l_A[0]=0
sum_l_B[0]=0
for i in range(1,N+2):
    sum_l_A[i]=sum_l_A[i-1]+A[i-1]

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



ans=0
a_c=0
b_c=0
for j in range(N+M+4):
    resume=0
    if(sum_l_A[a_c+1]<=sum_l_B[b_c+1]):
        a_c+=1
    else:
        b_c+=1
    resume=sum_l_A[a_c]+sum_l_B[b_c]
    if(K<resume):
        print(ans)
        sys.exit(0)
    ans+=1

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = A + B
count = 0
while K > min(C):
    if A == []:
        K -= B.pop(0)
    elif B == []:
        K -= A.pop(0)
    else:
        K -= min(A[0],B[0])
        if A[0] > B[0]:
            del B[0]
        else:
            del A[0]
     
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

n, m, k = map(int, input().split())
a = [ int(x) for x in input().split() ]
b = [ int(x) for x in input().split() ]

ac = 0
bc = 0
c = 0

a.append(1000000000)
b.append(1000000000)

while True:
    if a[ac] > k and b[bc] > k:
        print(c)
        sys.exit()

    if a[ac] > b[bc]:
        k -= b[bc]
        bc += 1
    else:
        k -= a[ac]
        ac += 1
    c += 1

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()]
i,j= 0,0
cnt = 0
dp = [[0 for i in range(n+1)] for j in range(m+1)]
ans = 0
for i in range(n):
    dp[0][i+1] = dp[0][i]+a[i]
    if k>=dp[0][i+1]:
        ans = max(ans,i+1)
    else:
        break
#print(dp[0])
for j in range(m):
    dp[j+1][0] = dp[j][0]+b[j]
    if dp[j+1][0]<=k:
        ans = max(j+1,ans)
    else:
        break
    #print(dp[j+1][0])
#print(dp)
for i in range(1,m+1):
    for j in range(1,n+1):
        dp[i][j] = dp[0][j] + dp[i][0]
        if dp[i][j]<=k:
            ans = max(ans,i+j)
        else:
            break
print(ans)

Submission status: Wrong Answer

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

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

K = k
ans = 0

i = 0
while K-a[i]>=0:
    K -= a[i]
    i += 1
    if i==n:
        break
ans = i
    
# K = k
l = 0
for j in range(i-1, -1, -1):
    while l<m and K-b[l]>=0:
        K -= b[l]
        l += 1
        if l==m:
            break
    ans = max(ans, j+l+1)
    K += a[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=[0]*N
b=[0]*M
a[0]=A[0]
b[0]=B[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i]
for i in range(M-1):
    b[i+1]=b[i]+B[i]
diff=2*10**9
count=0
for i in range(N):
    for j in range(M):
        if 0<=K-(a[i]+b[j])<diff:
            diff=K-(a[i]+b[j])
            count=(i+1)+(j+1)
print(count)

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

Ax = []
Bx = []
aadd, badd = 0, 0
for a in A:
    aadd += a
    Ax.append(aadd)

for b in B:
    badd += b
    Bx.append(badd)

len_a, len_b = len(A), len(B)

def getNext(pos_a,pos_b):
    if pos_a == -1:
        a = 0
    elif pos_a >= len_a:
        a = 10**9+10
    else:
        a = Ax[pos_a]

    if pos_b == -1:
        b = 0
    elif pos_b >= len_b:
        b = 10**9+10
    else:
        b = Bx[pos_b]

    return (a + b)

# search
res, r, res_c = 0, 0, 0
pos_a, pos_b = -1, -1

while True:
    # diff
    ra = rb = 0
    ra = getNext(pos_a+1,pos_b)
    rb = getNext(pos_a,pos_b+1)

    if (ra > K and rb > K) or (ra == 0 and rb == 0):
        break

    if ra < rb:
        pos_a += 1
        res = ra
    else:
        pos_b += 1
        res = rb

print(pos_a+pos_b+2)

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()))
res = 0
while True:
    if k == 0:
        break
    if k < 0:
        res -= 1
        break
    if len(a) == len(b) == 0:
        break
    if len(a) == 0:
        if b[0] > k:
            break
        else:
            k -= b.pop(0)
            res += 1
            continue
    if len(b) == 0:
        if a[0] > k:
            break
        else:
            k -= a.pop(0)
            res += 1
            continue
    if a[0] < b[0]:
        k -= a.pop(0)
        res += 1
    else:
        k -= b.pop(0)
        res += 1
print(res)