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 = [int(x) for x in input().split()]
stack_n = [int(x) for x in input().split()]
stack_m = [int(x) for x in input().split()]

i, j,count = 0, 0, 0
while i < N and j < M and K > 0:
	if stack_n[i] <= stack_m[j] and stack_n[i] <= K:
		count += 1
		K -= stack_n[i]
		i += 1
	elif stack_n[i] >= stack_m[j] and stack_m[j] <= K:
		count += 1
		K -= stack_m[j]
		j += 1
	else:
		break

while i < N and K > 0 and stack_n[i] <= K:
	count += 1
	K -= stack_n[i]
	i += 1

while j < M and K > 0 and stack_m[j] <= K:
	count += 1
	K -= stack_m[j]
	j += 1

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()))
a = []
b = []
p = 0
q = 0
for i in range(N):
  a.append(p+A[i])
for i in range(M):
  b.append(q+B[i])
ans = 0
for n, s in enumerate(a):
  if s > K:
    break
  for m, t in enumerate(b):
    if s + t <= K:
      ans = max(ans, n+m+2)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [10**18] + list(map(int, input().split()))[::-1]
B = [10**18] + list(map(int, input().split()))[::-1]

ans = 0
while K >= min(A[-1], B[-1]):
    if A[-1] > B[-1]:
        A, B = B, A
    K -= A.pop()
    ans += 1

print(ans)

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

ans=0
sa=a
for i in range(1,n):
  sa[i]=sa[i-1]+a[i]
sb=[b[0]]
for i in range(1,m):
  sb.append(sb[i-1]+b[i])

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

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()))
cum_a = np.r_[0,np.cumsum(a)]
# cum_b = np.r_[0, np.cumsum(b)]
# cum_a = np.cumsum(a)
cum_b = np.cumsum(b)
# high = m
# low = 0
# totaltime = 0
ans = 0
for i in range(n + 1):
    # # totaltime = cum_a[i]
    # while 1:
    #     mid = (high + low) // 2
    #     print(i, low, mid, high)
    #     if cum_a[i] + cum_b[mid] >= k:
    #         high = mid
    #     else:
    #         low = mid - 1
    #     if low == high:
    #         break
    if cum_a[i] > k:
    #     ans = max(ans, i - 1)
    #     print(s, i, ans)
        # break
        i = 0
    # else:
    s = np.searchsorted(cum_b, k - cum_a[i])#, side = "right")

    ans = max(ans, i + s)
print(ans)

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()))
cum_a = np.r_[0,np.cumsum(a)]
# cum_b = np.r_[0, np.cumsum(b)]
# cum_a = np.cumsum(a)
cum_b = np.cumsum(b)
# high = m
# low = 0
# totaltime = 0
ans = 0
for i in range(n + 1):
    # # totaltime = cum_a[i]
    # while 1:
    #     mid = (high + low) // 2
    #     print(i, low, mid, high)
    #     if cum_a[i] + cum_b[mid] >= k:
    #         high = mid
    #     else:
    #         low = mid - 1
    #     if low == high:
    #         break
    if cum_a[i] > k:
    #     ans = max(ans, i - 1)
    #     print(s, i, ans)
        # break
        i = 0
    # else:
    s = np.searchsorted(cum_b, k - cum_a[i])#, side = "right")
    print(i, s)
    ans = max(ans, i + s)
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()))


c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


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

print(ans)

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()))
cum_a = np.r_[0,np.cumsum(a)]
cum_b = np.r_[0, np.cumsum(b)]
ans = 0
for i in range(n + 1):
    if cum_a[i] > k:
        break
    else:
        s = np.searchsorted(cum_b, k - cum_a[i] - 1)
        ans = max(ans, i + s)

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

c = a + b
c.sort()

d = 0
cnt = 0
for i in c:
    d += i
    if d <= k:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
c = a + b
c.sort()
minuites = 0
cnt_book = 0
for min in c:
    if minuites + min <= K:
        minuites += min
        cnt_book += 1
    else:
        break
print(cnt_book)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
summ=0
bc1=0

for i in range(len(al)):
    summ+=al[i]
    if(summ>k):
        summ-=al[i]
        break
    bc1+=1
for j in range(len(bl)):
    summ+=bl[j]
    if(summ>k):
        summ-=bl[j]
        break
    bc1+=1

bc2=0
for j in range(len(bl)):
    summ+=bl[j]
    if(summ>k):
        summ-=bl[j]
        break
    bc2+=1
for i in range(len(al)):
    summ+=al[i]
    if(summ>k):
        summ-=al[i]
        break
    bc2+=1    
if(bc1>bc2):
    print(bc1)
else:
    print(bc2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    n, m, k = MI()
    a = LI()
    b = LI()

    ans = 0
    canContinue = True
    while canContinue:
        if len(a) == 0 and len(b) == 0:
            canContinue = False
            break
        if len(b) == 0:
            a_top = a.pop(0)
            k -= a_top
            if (k < 0):
                canContinue = False
                break
            ans += 1
            continue

        if len(a) == 0:
            b_top = b.pop(0)
            k -= b_top
            if (k < 0):
                canContinue = False
                break
            ans += 1
            continue

        a_top = a[0]
        b_top = b[0]

        if a_top <= b_top:
            a_top = a.pop(0)
            k -= a_top
            if (k < 0):
                canContinue = False
                break
            ans += 1
            continue
        else:
            b_top = b.pop(0)
            k -= b_top
            if (k < 0):
                canContinue = False
                break
            ans += 1
            continue
    print(ans)


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Wrong Answer

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

ans = 0

for i in reversed(range(0, N)):
    time = a - A[i]
    cnt = i
    if(time <= K):
        t = time
        for j in range(len(B)):
            t += B[j]
            if(t > K):
                ans = max(ans, cnt)
                break
            else:
                cnt += 1
                if(j == len(B)-1):
                    ans = max(ans, cnt)
                
if(a <= K):
    cnt = N
    t = a
    for i in range(len(B)):
        t += B[i]
        if(t > K):
            ans = max(ans, cnt)
            break
        else:
            cnt += 1
            if(i == len(B)-1):
                ans = max(ans, cnt)
                
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
summ=0
bc=0

for i in range(len(al)):
    summ+=al[i]
    if(summ>k):
        summ-=al[i]
        break
    bc+=1
for j in range(len(bl)):
    summ+=bl[j]
    if(summ>k):
        summ-=bl[j]
        break
    bc+=1
print(bc)

Submission status: Wrong Answer

Solution code:
N, M, K = input().split()
N, M, K = map(int, (N, M, K))
a = input().split()
b = input().split()

def to_init(list):
    for i in range(len(list)):
        list[i] = int(list[i])
    return list

c = []
c = a + b
# print(c)
# change for int
to_init(c)
d = sorted(c)
minuite = 0
cnt_book = 0
for i in d:
    if minuite + i <= K:
        minuite += i
        cnt_book += 1
    else:
        break

print(cnt_book)

Submission status: Wrong Answer

Solution code:
n,m,mnu=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
cnt=0

for _ in range(m):
  a.append(b[_])
  
a.sort()

for i in range(n+m):
  cnt=cnt+a[i]
  if i+1==n+m:
    print(ans+1)
    break
  if cnt>mnu:
    print(ans)
    break
  ans=ans+1

Submission status: Wrong Answer

Solution code:
n,m,z=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.reverse()
b.reverse()
k=0
d=0
while (a!=[] and b!=[]):
    if a[-1]<b[-1]:
        k+=a.pop()
    else:
        k+=b.pop()
    if k>z:
        break
    d+=1
if k<z:
    if a!=[]:
        while a!=[]:
            k+=a.pop()
            if k>z:
                break
            d+=1
    else:
        while b!=[]:
            k+=b.pop()
            if k>z:
                break
            d+=1
print(d)

Submission status: Wrong Answer

Solution code:
n,m,z=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.reverse()
b.reverse()
k=0
d=0
while (a!=[] and b!=[]):
    if a[-1]<b[-1]:
        temp=a.pop()
        if k+temp>z:
            break
        k+=temp
    else:
        temp=b.pop()
        if k+temp>z:
            break
        k+=temp
    d+=1
if k<z:
    if a!=[]:
        while a!=[]:
            temp=a.pop()
            if k+temp>z:
                break
            k+=temp
            d+=1
    else:
        while b!=[]:
            temp=b.pop()
            if k+temp>z:
                break
            k+=temp
            d+=1
print(d)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

#print(sort_array)
for i in range(0,len(sort_array)):
    if num >= sort_array[i]:
        num -= sort_array[i]
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

print(sort_array)
for i in range(0,len(sort_array)):
    if num >= sort_array[i]:
        num -= sort_array[i]
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

#print(sort_array)
for i in range(0,len(sort_array)):
    if num >= sort_array[i]:
        num -= sort_array[i]
    if num >= 0:
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

#print(sort_array)
for i in range(0,len(sort_array)):
    num -= sort_array[i]
    if num >= 0:
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

print(sort_array)
for i in range(0,len(sort_array)):
    num -= sort_array[i]
    if num >= 0:
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

for i in range(0,len(sort_array)):
    num -= sort_array[i]
    if num > 0:
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

print(sort_array)
print(sort_array[count])
while num > 0:
    num -= sort_array[count]
    count += 1

count -= 1
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()))
LA = [0]
LB = [0]
for i in range(N):
    C=LA[i]+A[i]
    if C>K:
        N=i
        break
    else:
        LA.append(C)
for j in range(M):
    C=LB[j]+B[j]
    if C>K:
        M=j
        break
    else:
        LB.append(C)
r=N
for i in range(N+1):
    c=N-i-1
    for j in range(r-N+i,M+1):
        if LA[N-i]+LB[j]<=K:
            c=c+1 # 最大のrを求めたいので結果をrefineする場合だけで回す
        else:
            break
    r=max(r,c) # 全部通ってしまうときの処理が意外と面倒. 改善余地あり
print(r)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M,K = I()
A = l()
B = l()
ruiseki = [-1]+list(itertools.accumulate(A))
num = 0
ans = 0
for i in range(M):
    num += B[i]
    if num > K:
        break
    ans = max(ans,bisect.bisect_right(ruiseki,K-num)+i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M,K = I()
A = l()
B = l()
ruiseki = [0]+list(itertools.accumulate(A))
num = 0
ans = 0
for i in range(M):
    num += B[i]
    if num > K:
        break
    ans = max(ans,bisect.bisect_right(ruiseki,K-num)+i)
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()))
LA = [0]
LB = [0]
for i in range(N):
    C=LA[i]+A[i]
    if C>K:
        N=i
        break
    else:
        LA.append(C)
for j in range(M):
    C=LB[j]+B[j]
    if C>K:
        M=j
        break
    else:
        LB.append(C)
r=N
for i in range(N+1):
    u=0
    for j in range(r-N+i,M+1):
        if LA[N-i]+LB[j]>K:
            r=max(r,N-i+j-1) # 最大のrを求めたいので結果をrefineする場合だけで回す
            u=1
            break
    if u==0:
        r=N-i+M
        break
print(r)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M,K = I()
A = l()
B = l()
ruiseki = [0]+list(itertools.accumulate(A))
num = 0
ans = 0
for i in range(M):
    num += B[i]
    ans = max(ans,bisect.bisect_right(ruiseki,K-num)+i)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    n, m, k  = [int(x) for x in input().split()]
    a = deque([int(x) for x in input().split()])
    b = deque([int(x) for x in input().split()])
    c = 0
    while(True):
        if len(b) == 0:
            if len(a) == 0:
                break
            elif k >= a[0]:
                k -= a.popleft()
            else:
                break
        elif len(a) == 0:
            if k >= b[0]:
                k -= b.popleft()
            else:
                break
        elif a[0] <= b[0] and k >= a[0]:
            k -= a.popleft()
        elif a[0] > b[0] and k >= b[0]:
            k -= b.popleft()
        else:
            break
        c += 1
    print(c)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

max = 0

for i in range(n + 1):
    j = m
    while j > 0:
        if (sa[i] + sb[j] <= k):
            if i + j > max:
                max = i + j
            break
        else:
            j -= 1
print(max)

Submission status: Wrong Answer

Solution code:
import itertools
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

max = 0

for i in range(n + 1):
    j = m -1
    while j > 0:
        if (sa[i] + sb[j] <= k):
            if i + j > max:
                max = i + j
            break
        else:
            j -= 1
print(max)

Submission status: Wrong Answer

Solution code:
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N,M,K=MI()
A=[0]+LI()
B=[0]+LI()
from itertools import accumulate
A=list(accumulate(A))
B=list(accumulate(B))
ans=0
for i in range(1,N+1):
  if A[i]>K:
    continue
  for j in range(M,-1,-1):
    if A[i]+B[j]>K:
      continue
    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()))
LA = [0]
LB = [0]
for i in range(N):
    C=LA[i]+A[i]
    if C>K:
        N=i
        break
    else:
        LA.append(C)
for j in range(M):
    C=LB[j]+B[j]
    if C>K:
        M=j
        break
    else:
        LB.append(C)
u=0
r=N
for i in range(N+1):
    for j in range(r-N+i,M+1):
        C=LA[N-i]+LB[j]
        if C>K:
            r=max(r,N-i+j-1) # 最大のrを求めたいので結果をrefineする場合だけで回す
            u=1
            break
    if u==0:
        r=N+M
        break
print(r)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

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

V = 0
ACount = bisect.bisect_right(A, K)
if ACount !=0:
    V = K- A[ACount-1]
else:
    V=K

AInitial = ACount

BCount = bisect.bisect_right(B, V)
final = ACount+BCount

for i in range (1, AInitial):
    V = K - A[AInitial-1-i]
    BCount = bisect.bisect_right(B, V)
    final = max(final, AInitial-i-1+BCount)

print(final)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

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

V = 0
ACount = bisect.bisect_right(A, K)
if ACount !=0:
    V = K- A[ACount-1]
else:
    V=K

AInitial = ACount

BCount = bisect.bisect_right(B, V)
final = ACount+BCount

for i in range (1, AInitial):
    V = K - A[AInitial-1-i]
    BCount = bisect.bisect_right(B, V)
    final = max(final, AInitial-i+BCount)

print(final)

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()))
  
  spendTime = 0
  cnt = 0
  indexA = 0
  indexB = 0
  
  while spendTime < K:
    if indexA == N and indexB == M: 
      break
    elif indexA == N:
      spendTime += B[indexB]
      indexB += 1
      cnt += 1
      continue
    elif indexB == M:
      spendTime += A[indexA]
      indexA += 1
      cnt += 1
      continue
    
    
    if A[indexA] <= B[indexB]:
      spendTime += A[indexA]
      indexA += 1
      cnt += 1
    else:
      spendTime += B[indexB]
      indexB += 1
      cnt += 1
  
  
  if spendTime == K:
    print(cnt)
  else:
    print(cnt-1)
  
  
  
main()

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()))
  
  spendTime = 0
  cnt = 0
  indexA = 0
  indexB = 0
  
  while spendTime < K:
    if indexA == N:
      spendTime += B[indexB]
      indexB += 1
      cnt += 1
      continue
    elif indexB == M:
      spendTime += A[indexA]
      indexA += 1
      cnt += 1
      continue
    
    if A[indexA] <= B[indexB]:
      spendTime += A[indexA]
      indexA += 1
      cnt += 1
    else:
      spendTime += B[indexB]
      indexB += 1
      cnt += 1
  
  
  if spendTime == K:
    print(cnt)
  else:
    print(cnt-1)
  
  
  
main()

Submission status: Wrong Answer

Solution code:
N, M, K = [ int(i) for i in input().split()]

list_A = map( int, input().split())

list_B = map( int, input().split())

ans = 0
passedtime = 0

tmp_A = next(list_A)
tmp_B = next(list_B)

while True:

        if(tmp_A < tmp_B):
            tmp = tmp_A
            try:
                tmp_A = next(list_A)
            except StopIteration:
                tmp_A = 1000000001
                
        else:
            tmp = tmp_B
            try:
                tmp_B = next(list_B)
            except StopIteration:
                tmp_B = 1000000001
                
        if passedtime + tmp <= K:
            passedtime += tmp
            ans += 1
        else:
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = [ int(i) for i in input().split()]

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

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

ans = 0
passedtime = 0

tmp_A = list_A.pop(0)
tmp_B = list_B.pop(0)

while True:

        if(tmp_A < tmp_B):
            tmp = tmp_A
            try:
                tmp_A = list_A.pop(0)
            except IndexError:
                tmp_A = 1000000001
                
        else:
            tmp = tmp_B
            try:
                tmp_B = list_B.pop(0)
            except IndexError:
                tmp_B = 1000000001
                
        if passedtime + tmp <= K:
            passedtime += tmp
            ans += 1
        else:
            break
            
print(ans)

Submission status: Wrong Answer

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

A = [0] + A
B = [0] + B

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

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


ans = 0
for i in range(N+1):
  for j in range(M, 0, -1):
    if A[i] + B[j] <= K:
      ans = max(ans, i+j)
      break

print(ans)

Submission status: Wrong Answer

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

sum_A = [0, A[0]]
sum_B = [0, B[0]]

for a in A[1:]:
  sum_A.append(sum_A[-1] + a)

for b in B[1:]:
  sum_B.append(sum_B[-1] + b)

ans = 0
for i in range(N+1):
  for j in range(M, 0, -1):
    if sum_A[i] + sum_B[j] <= K:
      ans = max(ans, i+j)
      break

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = [ int(i) for i in input().split()]

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

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

ans = 0
passedtime = 0

while True:
    if(len(list_A)==0 and len(list_B)==0):
        break
    elif(len(list_A) == 0 and len(list_B) != 0):
        tmp = list_B.pop(0)
    elif(len(list_A) != 0 and len(list_B) == 0):
        tmp = list_A.pop(0)
    elif (list_A[0] < list_B[0]):
        tmp = list_A.pop(0)
    else:
        tmp = list_B.pop(0)
    if passedtime + tmp <= K:
        passedtime += tmp
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys 
import numpy as np

read = sys.stdin.buffer.read 
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines 

N, M, K = map(int, readline().split())
A = np.array(readline().split(), np.int64)
B = np.array(readline().split(), np.int64)

Acum = np.zeros(N+1, np.int64)
Acum[1:] = np.cumsum(A)
Bcum = np.zeros(M+1, np.int64)
Bcum[1:] = np.cumsum(B)

print(Bcum)

Submission status: Wrong Answer

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

for i in range(1, N+1): A[i] += A[i - 1]
for i in range(1, M+1): B[i] += B[i - 1]
ans, j = 0, M
for i in range(N):
    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:
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202006_5th/C_input.txt")
else:
    f=sys.stdin
#----
M,N,K=map(int,f.readline().split())
ans=0
__=N
M_shelf=list(map(int,f.readline().split()))
N_shelf=list(map(int,f.readline().split()))
M_partial=[]
N_partial=[]
M_partial.append(0)
N_partial.append(0)
#----
for _ in range(M):
    M_partial.append(M_partial[_]+M_shelf[_])
for _ in range(N):
    N_partial.append(N_partial[_]+N_shelf[_])
for _ in range(1,M+1):
    R=K-M_partial[_]
    if R<0:
        break
    while R<N_partial[__]:
        __-=1
    ans=max(ans,_+__)
print(ans)
f.close()

Submission status: Wrong Answer

Solution code:
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202006_5th/C_input.txt")
else:
    f=sys.stdin
#----
M,N,K=map(int,f.readline().split())
ans=0
__=N
M_shelf=list(map(int,f.readline().split()))
N_shelf=list(map(int,f.readline().split()))
M_partial=[]
N_partial=[]
M_partial.append(0)
N_partial.append(0)
#----
for _ in range(M):
    M_partial.append(M_partial[_]+M_shelf[_])
for _ in range(N):
    N_partial.append(N_partial[_]+N_shelf[_])
for _ in range(1,M+1):
    R=K-M_partial[_]
    if R<0:
        continue
    while R<N_partial[__]:
        __-=1
    ans=max(ans,_+__)
print(ans)
f.close()

Submission status: Wrong Answer

Solution code:
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202006_5th/C_input.txt")
else:
    f=sys.stdin
#----
M,N,K=map(int,f.readline().split())
ans=0
M_shelf=list(map(int,f.readline().split()))
N_shelf=list(map(int,f.readline().split()))
M_partial=[]
N_partial=[]
M_partial.append(0)
N_partial.append(0)
#----
for _ in range(M):
    M_partial.append(M_partial[_]+M_shelf[_])
for _ in range(N):
    N_partial.append(N_partial[_]+N_shelf[_])
for _ in range(1,M+1):
    R=K-M_partial[_]
    if R<0:
        continue
    __=N
    while R<N_partial[__]:
        __-=1
    ans=max(ans,_+__)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
qA = deque(A)
B = list(map(int, input().split()))
qB = deque(B)

count = int()
total = int()
while total <= K :
    if len(qA) > 0 and len(qB) > 0 :
        if qA[0] <= qB[0] : total += qA.popleft()
        else : total += qB.popleft()
        count += 1
    elif len(qA) == 0 and len(qB) == 0:
        count += 1
        break;
    elif len(qA) == 0 :
        total += qB.popleft()
        count += 1
    elif len(qB) == 0 :
        total += qA.popleft()
        count += 1
print(count - 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()))
aa=[]
bb=[]
aa.append(0)
import bisect
for i in range(n):
    if i == 0 :
        aa.append(a[0])
    else: 
        aa.append(aa[i-1]+a[i])

for i in range(m):
    if i == 0 :
        bb.append(b[0])
    else:
        bb.append(bb[i-1]+b[i])
ans = 0
for i in range(n+1):
    x = k - aa[i]
    if x >= 0:
        insert_index = bisect.bisect_right(bb,x)
        if (ans < insert_index + i):
            ans = insert_index + i
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()))
aa=[]
bb=[]
import bisect
for i in range(n):
    if i == 0 :
        aa.append(a[0])
    else: 
        aa.append(aa[i-1]+a[i])

for i in range(m):
    if i == 0 :
        bb.append(b[0])
    else:
        bb.append(bb[i-1]+b[i])
ans = 0
for i in range(n):
    x = k - aa[i]
    insert_index = bisect.bisect_right(bb,x)
    if insert_index != 0:
        if ans < insert_index + i + 1:
            ans = insert_index + 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()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Submission status: Wrong Answer

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

for i in range(1,n):
  a[i] += a[i-1]
for i in range(1,m):
  b[i] += b[i-1]
  
a_max = 0
for i in range(n-1, 0, -1):
  if a[i] <= k:
    a_max = i + 1
    break
b_max = 0
for i in range(m-1, 0, -1):
  if b[i] <= k:
    b_max = i + 1
    break
    
ans = 0
for i in range(a_max, 0, -1):
  p = 0
  q = 0
  if a[i-1] <= k:
    p = a[i-1]
    q = i
  for j in range(b_max, 0, -1):
    if p + b[j-1] <= k:
      ans = max(ans, q + j)
    
print(ans)