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()))
cnt=0
T=K
while(K>0):
  if(A[0]<B[0]):
    read=A[0]
    del A[0]
    A.append(T)
  else:
    read=B[0]
    del B[0]
    B.append(T)
  last=K-read
  if(last>=0):
    K=last
    cnt+=1
  else:
    break
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()))
import bisect

class Cumulative_Sum:
    def __init__(self, a):
        la = len(a)
        self.s = [0] * (la + 1)
        for i in range(la):
            self.s[i+1] = self.s[i] + a[i]
    # s[l]からs[r]までの和
    def sum(self, l, r):
        return self.s[r] - self.s[l]
csa = Cumulative_Sum(a)
csb = Cumulative_Sum(b)
#print(csa.s)
#print(csb.s)
ans = 0
for i in range(n+1):
    t = csa.s[i]
    if t > k:
        continue
    p = k - t
    bi = bisect.bisect_left(csb.s, p)
    #print(i, bi-1, t, p)
    if bi == m and csb.s[bi] <= p:
        ans = max(ans, i + bi)
    else:
        ans = max(ans, i + bi-1)

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()))
    a.append(10**9+1)
    b.append(10**9+1)
    a, b = a[::-1], b[::-1]
    sum = 0
    for _ in range(400001):
        x = a.pop() if a[-1] <= b[-1] else b.pop()
        if x > 10**9:
            break
        k -= x
        if k < 0:
            break
        sum += 1
    print(sum)

if __name__ == "__main__":
    main()

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()]
t=0
for p in range(n):
    if t+a[p]>k:
        p-=1
        break
    t+=a[p]
for q in range(m):
    if t+b[q]>k:
        q-=1
        break
    t+=b[q]
ans=p+q+2
if q<m-1:
    z=ans
    for s in range(p,-1,-1):
        t-=a[s]
        z-=1
        while q<m and t+b[q]<=k:
            t+=b[q]
            q+=1
            z+=1
        if z>ans:
            ans=z
        if q==m:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
nmk = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(10**9+1)
b = list(map(int, input().split()))
b.append(10**9+1)

an=0
bm=0

ans = 0
sum = 0
while(True):
  if an == nmk[0] and bm == nmk[1]:
    break
  if a[an] <= b[bm]:    # B側の本がが時間がかかる時
    sum += a[an]
    # if comp(sum,nmk[2]) == False:
    if sum > nmk[2]:
      print(ans)
      sys.exit()
    ans += 1
    an += 1
  else:                  # A側の本がが時間がかかる時
    sum += b[bm]
    # if comp(sum,nmk[2]) == False:
    if sum > nmk[2]:
      print(ans)
      sys.exit()
    ans += 1
    bm += 1
  
print(ans)

Submission status: Wrong Answer

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

time = 0
count = 0
while len(a) > 0 and len(b) > 0:
    if len(a) ==  0:
        book_b = b.popleft()
        time += book_b
        count += 1
    elif len(b) == 0:
        book_a = a.popleft()
        time += book_a
        count+= 1
    elif a[0] > b[0]:
        book_b = b.popleft()
        time += book_b
        count += 1
    else:
        book_a = a.popleft()
        time += book_a
        count += 1
    if time > k:
        count -= 1
        break
    elif time == k:
        break
    
print(count)

Submission status: Wrong Answer

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


b_counter=0
ans_a=0
ans=0
time=0
a_accum=[0]
b_accum=[0]

for j in range(M):
	b_counter+=b_ls[j]
	if b_counter>K:
		break
	else:
		a_counter=0
		for i in range(N):
			a_counter+=a_ls[i]
			if a_counter+b_counter>K:
				break
			else:
				ans_a=i+1
		
		ans=max(ans,1+j+ans_a)
		

print(ans)


# 2darray [[0] * 4 for i in range(3)]

Submission status: Wrong Answer

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

sum_alist=[0]
for i in range(N):
  sum_alist.append(sum_alist[-1]+alist[i])
#print(sum_alist)

sum_blist=[0]
for i in range(M):
  sum_blist.append(sum_blist[-1]+blist[i])
#print(sum_blist)

limit_a=bisect.bisect(sum_alist,K)
#print(limit_a)

limit_b=bisect.bisect(sum_blist,K)
#print(limit_b)

answer=0
for i in reversed(range(1,limit_a)):
  a_sum=sum_alist[i]
  b_sum=K-a_sum
  pos_b=bisect.bisect(sum_blist,b_sum)
  #print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
  answer=max(answer,i+pos_b-1)
  
if limit_a==1:
  pos_b=bisect.bisect(sum_blist,K)
  answer=pos_b-1
  
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()))

ans = 0
flag = 0
count = 0

if A[0] < B[0]:
    tmp = ans + A[0]

else:
    tmp = ans + B[0]
    flag = 1

if tmp > K:
    print(count)
    exit(0)
else:
    ans = tmp
    count = count + 1
    if flag == 0:
        A.pop(0)
    else:
        B.pop(0)
        flag = 0

while 1:
    if len(A) == 0 and len(B) == 0:
        break

    elif len(A) == 0:
        tmp = ans + B[0]
        flag = 1

    elif len(B) == 0:
        tmp = ans + A[0]

    elif A[0] < B[0]:
        tmp = ans + A[0]

    else:
        tmp = ans + B[0]
        flag == 1

    if tmp > K:
        break

    else:
        ans = tmp
        count = count + 1
        if flag == 0:
            A.pop(0)
        else:
            B.pop(0)
            flag = 0

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left, bisect_right
import sys

input = sys.stdin.buffer.readline
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AA = list(accumulate([0] + A))
BB = list(accumulate([0] + B))
apos = bisect_right(A, k)

# bpos = bisect_right(B, k)
# j = 0
ans = 0
for i in range(apos, -1, -1):
    temp_a = AA[i]
    remain = k - temp_a
    pos = bisect_left(BB, remain)
    if pos == m + 1:
        pass
    else:
        if BB[pos] == remain:
            pos += 1
    ans = max(ans, i + pos - 1)
    # while j <= bpos:
    #     if remain >= BB[j]:
    #         j += 1
    #     else:
    #         break
    # ans = max(ans, i + j - 1)
    # print(i, pos)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
nums=input().split()
a=int(nums[0])
b=int(nums[1])
n=int(nums[2])
lista=input().split()
listb=input().split()
listb.append(-1)
listall=[]

acount=0
bcount=0
count=0
time=0
for i in lista:
  anum=int(i)
  for j in range(bcount,b+1):
    bnum=int(listb[j])
    if j==b:
      listall.append(anum)
      break
    if anum<bnum:
      listall.append(anum)
      break
    else:
      listall.append(bnum)
      bcount+=1

if bcount!=b:
  for i in range(bcount,b):
    listall.append(int(listb[i]))

for i in listall:
  if i+time>n:
    print(count)
    sys.exit()
  else:
    time+=i
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AB = list()
a = 0
b = 0
for i in range(N+M):
  if (((a+1) <= N) and ((b+1) <= M)):
    if(A[a] < B[b]):
      AB.append(A[a])
      a += 1
    else:
      AB.append(B[b])
      b += 1
  elif((a) >= N):
    for j in range(M-b):
      AB.append(B[b])
      b += 1
    break
  elif((b) >= M):
    for j in range(N-a):
      AB.append(A[a])
      a += 1
    break

ans = 0
ab = 0
i = 0
while K >= 0:
  K -= AB[ans]
  ans += 1
  if(ans == (N+M)):
    print(N+M)
    sys.exit()
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
import bisect

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

S = []
sum_ = 0

C = []
while True:
    if A[0] < B[0]:
        C.append(A[0])
        A.pop(0)
    else:
        C.append(B[0])
        B.pop(0)
    if not A:
        C.extend(B)
        break
    elif not B:
        C.extend(A)
        break

S = []
sum_ = 0
for c in C:
    sum_ += c
    S.append(sum_)

print(bisect.bisect_right(S, 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()))
A.append(0)
B.append(0)
run_time = K
count_A = 0
count_B = 0
#print(N, M ,K)
while(run_time > 0 or count_A + count_B >= N + M):
#	print(count_B , M)
	if(A[count_A] >= B[count_B] and run_time > A[count_A]):
#		print(N)
		run_time -= A[count_A]
		count_A += 1
#		print(count_A, N)
	elif(A[count_A] < B[count_B] and run_time > B[count_B]):
		
		run_time -= B[count_B]
		count_B += 1
	else:
		break
print(count_A + count_B)

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

AL = []
BL = []
a = 0
for i in A:
    a += i
    AL.append(a)
a = 0
for i in B:
    a += i
    BL.append(a)

#print(AL)
#print(BL)

a = 0
for i in range(len(AL)):
    if AL[i] > k:
        a = i
        break
else:
    a = len(AL)

b = 0
for i in range(len(BL)):
    if BL[i] > k:
        b = i
        break
else:
    b = len(BL)

#print(a,b)

m = 0

for j in reversed(range(a)):
    t = k-AL[j-1]
    for i in reversed(range(b)):
        if t-BL[i]>=0:
            if m < j+1 + i +1:
                m = j+1 + i +1
            break
    if j+1+b<=m:
        break
if b > 0:
    m = b
print(m)

Submission status: Wrong Answer

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

ans = 0
x = 1
while x == 1:
    if len(lsa) == 0 :
        if len (lsb) == 0:
            x = 0
        elif lsb[0] <= k:
            ans += 1
            k -= lsb[0]
            del lsb[0]
        else:
            x = 0
    else:
        if len(lsb) == 0:
            if lsa[0] <= k:
                ans += 1
                k -= lsa[0]
                del lsa[0]
        elif min(lsa[0],lsb[0]) <= k:
            ans += 1
            if lsa[0] <= lsb[0]:
                k -= lsa[0]
                del lsa[0]
            else:
                k -=  lsb[0]
                del lsb[0]
        else:
            x = 0

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
c = [int(_) for _ in input().split()]
d = [int(_) for _ in input().split()]

a = deque(c)
b = deque(d)

aa = a.popleft()
bb = b.popleft()

ans = 0
time = 0
for i in range(n+m):
    if time + min(aa, bb) > k:
        break
    if aa <= bb:
        time += aa
        if len(a) == 0:
            aa = 10**9+1
        else:
            aa = a.popleft()
    else:
        time += bb
        if len(b) == 0:
            bb = 10**9+1
        else:
            bb = b.popleft()
    ans += 1
    #print(ans, aa, bb)


a_sum = 0
a_cnt = 0
for i in c:
    if a_sum + i > k:
        break
    a_sum += i
    a_cnt += 1

ans = max(ans, a_cnt)

b_sum = 0
b_cnt = 0
for i in d:
    if b_sum + i > k:
        break
    b_sum += i
    b_cnt += 1

ans = max(ans, b_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()))

# まずaを全部読む
# 全部読めたならbも読む
# 最後の本を捨てて、それがなければどこまでいけるかを試す

ans = 0
cost = a[0]
b_i = 0
if not (a[0] >= k and b[0] >= k):
  while cost <= k:
    ans += 1
    if ans >= n:
      if ans-n>=m:
        break
      cost += b[n-ans]
      b_i += 1
    else:
      cost += a[ans]

  max_ans = ans
  if b_i == 0:
    for i in range(ans-1,-1,-1):
      ans -= 1
      cost -= a[i]
      while cost <= k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)
  else:
    for i in range(n-1,-1,-1):
      ans -= 1
      cost -= a[i]
      while cost <= k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)

  print(max_ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]
c = []
while len(a)!=0 and len(b)!=0:
  if a[-1]>b[-1]:
    c.append(b[-1])
    b.pop()
  else:
    c.append(a[-1])
    a.pop()
if len(a)==0:
  c += b
if len(b)==0:
  c += a
cou = 0
c = c[::-1]
while k>0:
  if len(c)==0:
    print(cou)
    exit()
  if k-c[-1]>=0:
    cou += 1
    k -= c[-1]
    c.pop()
  else:
    print(cou)
    exit()
print(cou)

Submission status: Wrong Answer

Solution code:
from sys import stdin
An, Bn, t = [int(x) for x in stdin.readline().rstrip().split()]

A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]


idxA = 0
idxB = 0

cnt = 0

for i in range(max(An , Bn)):
	if t < 0 : break

	if An > i :
		t -= A[idxA]
		if t < 0 : break
		cnt += 1
		idxA += 1

	if Bn > i :
		t -= B[idxB]
		if t < 0 : break
		cnt += 1
		idxB += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

AList.append(10**10)
BList.append(10**10)

ASList = [AList[0]]
for i in range(1,N+1):
  a = ASList[-1] + AList[i]
  ASList.append(a)

BSList = [0,BList[0]]
for i in range(1,M+1):
  a = BSList[-1] + BList[i]
  BSList.append(a)  
  
ans = 0
for i in range(M+1):
  b = BSList[i]
  c = K-b
  if c > 0:
    d = bisect.bisect_left(ASList,c)
    if ASList[d] == c:
      d +=1 
    ans = max(ans,i+d)
  elif c == 0:
  	ans = max(ans,i+d)
  else:
    d = bisect.bisect_left(ASList,K)
    ans = max(ans,d)
  
print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

n_l = list(map(int, input().split()))
m_l = list(map(int, input().split()))

cnt_book = 0
cnt_time = 0

while cnt_time < k:
    # 両方の机に本なし
    if len(n_l) == 0 and len(m_l) == 0:
        break
    # A机の判定
    elif len(n_l) > 0 and len(m_l) == 0:
        if cnt_time + n_l[0] <= k:
            cnt_book = cnt_book + 1
            cnt_time = cnt_time + n_l.pop(0)
        else:
            break
    # B机の判定
    elif len(n_l) == 0 and len(m_l) > 0: # mの判定
        if cnt_time + m_l[0] <= k:
            cnt_book = cnt_book + 1
            cnt_time = cnt_time + m_l.pop(0)
        else:
            break
    # A,B机の判定
    else:
        if n_l[0] <= m_l[0]: # nの本を読む場合の分岐
            if cnt_time + n_l[0] <= k:
                cnt_book = cnt_book + 1
                cnt_time = cnt_time + n_l.pop(0)
            else:
                break
        else: # mの本を読む場合の分岐
            if cnt_time + m_l[0] <= k:
                cnt_book = cnt_book + 1
                cnt_time = cnt_time + m_l.pop(0)            
            else:
                break

print(cnt_book)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N,M,K=map(int,input().split())
As=list(map(int,input().split()))
As=[a for a in accumulate(As) if a <= K]
Bs=list(map(int,input().split()))
Bs=[b for b in accumulate(Bs) if b <= K]
# print(As)
# print(Bs)

anses = []
for ai in range(len(As)-1, 0-1, -1):
    ans = -1
    nokori = K-As[ai]
    for bi in range(len(Bs)-1, 0-1, -1):
        if Bs[bi] <= nokori:
            now = ai+1 + bi+1
            if now > ans:
                ans = now
            elif now == ans:
                continue
            else:
                anses.append(ans)
            # print(now, ai+1, bi+1)

if anses == []:
    print(0)
else:
    print(max(anses))

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
total = 0
idx = -1

for i in range(N):
  t = total + A[i]
  if t > K:
    break
  total = t
  count += 1
  idx = i

max_total = total
ans = count

for j in range(M):
  t = total + B[j]
  if t > K:
    # print(idx)
    for k in range(idx, -1, -1):
      t -= A[k]
      if t <= K:
        total = t
        count -= (idx - k - 1)
        idx = k - 1
        if max_total < total:
          max_total = total
          ans = count
  else:
    total = t
    max_total = total
    count += 1
    ans = count

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

ans = 0
a,b = A.popleft(), B.popleft()

while k > 0:
    while a <= b:
        if a <= k:
            ans += 1
            if A and a+A[0] <= k: a += A.popleft()
            else: break
        else: break
    if a <= b:
        k -= a
        if A:a = A.popleft()
        else: a = 10 ** 9 + 1
    while a >= b:
        if b <= k:
            ans += 1
            if B and b+B[0] <= k: b += B.popleft()
            else: break
        else: break
    if a >= b:
        k -= b
        if B:b = B.popleft()
        else: b = 10 ** 9 +1
print(ans)

Submission status: Wrong Answer

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

read_min = K
read_cnt = 0
ai = 0
bi = 0

for _ in range(N+M):
  if ai < N and bi < M:
    if A_list[ai] < B_list[bi]:
      read_min -= A_list[ai]
      ai += 1
    elif A_list[ai] >= B_list[bi]:
      read_min -= B_list[bi]
      bi += 1
  else:
    if ai >= N:
      read_min -= B_list[bi]
      bi += 1
    elif bi >= M:
      read_min -= A_list[ai]
      ai += 1
    else:
      break
    
  if read_min < 0:
    break
  read_cnt += 1  

print(read_cnt)

Submission status: Wrong Answer

Solution code:
A,B,time = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
while time > 0:
    if len(a) > 0 and len(b) > 0:  
        if time >= a[0] and time >= b[0]:
            if a[0] <= b[0]:
                ans += 1
                time -= a[0]
                del a[0]

            else:
                ans += 1
                time -= b[0]
                del b[0]

        elif time >= a[0]:
            ans += 1
            time -= a[0]
            del a[0]

        elif time >= b[0]:
            ans += 1
            time -= b[0]
            del b[0]
        else:
            break
    elif len(a) == 0 and len(b) > 0:
        if time >= b[0]:
            ans += 1
            time -= b[0]
            del b[0]
        else:
            print(ans)
            exit()
    elif len(a) > 0 and len(b) == 0:
        if time >= a[0]:
            ans += 1
            time -= a[0]
            del a[0]
        else:
            print(ans)
            exit()
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
Bs = [0] + list(map(int, input().split()))
csum_A = list(accumulate(As))
csum_B = list(accumulate(Bs))

ok = 0
ng = N + M + 2
while ng - ok > 1:
    mid = (ng + ok) // 2
    min_time = 10 ** 9 + 10
    for t in range(max(0, mid-M), min(mid, N+1)):
        min_time = min(min_time, csum_A[t] + csum_B[mid - t])
    
    if K >= min_time:
        ok = mid
    else:
        ng = mid

print(ok)

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
n = 0

while K > t :
    if len(A)>0 and len(B)>0 :
        if A[0] <= B[0] :
            t += A[0]
            n += 1
            del A[0]
        else :
            t +=B[0]
            n += 1
            del B[0]
    elif len(A)== 0 and len(B)>0 :
        t += B[0]
        n += 1
        del B[0]
    elif len(A)>0 and len(B) == 0 :
        t += A[0]
        n += 1
        del A[0]

print(n)

Submission status: Wrong Answer

Solution code:
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heappushpop, heapreplace
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['NET', 'DA']
############# CODE STARTS HERE #############


test_case=1
while test_case:
    test_case-=1


    n, m, k=mi()
    a=li()
    b=li()
    t=c=i=j=0
    while t<=k:
        c+=1
        if i<n and j<m:
            if a[i]<b[j]:
                t+=a[i]
                i+=1
            else:
                t+=b[j]
                j+=1
        elif i<n:
            t+=a[i]
            i+=1
        elif j<m:
            t+=b[j]
            j+=1
        else:
            break
    print(c-1)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))
def sub(l,k):
    res = 0
    for i in l:
        if k >= i:
            k -= i
            res += 1
        else:
            return k,res
    return k,res
        
def main(n,m,k,ln,lm):
    nk = sum(ln)
    mk = sum(lm)
    if k>=nk+mk:
        return n+m
    elif k>nk:
        ik, res = sub(lm, k-nk)
        res += n
        startn = n - 1
        startm = res - 1
    else:
        ik, res = sub(ln, k)
        startn = res - 1
        ik, res2 = sub(lm, ik)
        res += res2
        startm = res2
        
    ires = res
    for i in range(startn,-1,-1):
        ik += ln[i]
        ik, delta = sub(lm[startm:], ik)
        startm += delta
        ires = ires - 1 + delta
        res = max(res, ires)
    return res

main(n,m,k,ln,lm)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
b = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
ans = 0
kazu = 0
c_a = 0
c_b = 0
time = 0
'''
a.append(10**9 + 1)
b.append(10**9 + 1)


while True:
    if time + min(a[c_a],b[c_b])>k:
        break
    if a[c_a]>b[c_b]:
        time += b[c_b]
        c_b += 1
    elif a[c_a]<b[c_b]:
        time += a[c_a]
        c_a += 1

    ans += 1
'''
for c_a in range(1,n):
    time = sum(a[:c_a])
    if time > k:
        break
    kazu = c_a
    for c_b in range(1,m):
        time += sum(b[:c_b])
        if time > k:
            break
        kazu += c_b
    ans = max(ans, kazu)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
A=list(map(int,input().split()))+[0]
B=list(map(int,input().split()))+[0]
cnt=0
temp=0
Ai=0
Bi=0
for i in range(n+m):
  if Ai==n and Bi==m:
    break;
  elif Ai==n and Bi<m:
    if temp+B[Bi]<=k:
      temp+=B[Bi]
      cnt+=1
      Bi+=1
    else:
      break;
  elif Bi==m and Ai<n:
    if temp+A[Ai]<=k:
      temp+=A[Ai]
      cnt+=1
      Ai+=1
    else:
      break;
  elif Ai<n and Bi<m:
    if A[Ai]<=B[Bi]:
      if temp+A[Ai]<=k:
        temp+=A[Ai]
        cnt+=1
        Ai+=1
      else:
        break;
    elif A[Ai]>B[Bi]:
      if temp+B[Bi]<=k:
        temp+=B[Bi]
        cnt+=1
        Bi+=1
      else:
        break;
      
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k,*ab = map(int, open(0).read().split())
aa = ab[:n]
bb = ab[n:]
ans = 0
i = j = 0
while True:
    if n <= i and m <= j:
        break
    elif n > i and m > j:
        a = aa[i]
        b = bb[j]
        if a < b:
            if a > k:
                break
            i += 1
            ans += 1
            k -= a
        else:
            if b > k:
                break
            j += 1
            ans += 1
            k -= b
    elif n > i:
        a = aa[i]
        if a > k:
            break
        i += 1
        ans += 1
        k -= a
    else:
        b = bb[j]
        if b > k:
            break
        j += 1
        ans += 1
        k -= b
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
j = 0
time = 0
book = 0
while True:
    if i < n and j < m:
        if a[i] < b[j]:
            time += a[i]
            if time > k:
                break
            i += 1
            book += 1
        else:
            time += b[j]
            if time > k:
                break
            j += 1
            book += 1
    elif i < n and j >= m:
        time += a[i] 
        if time > k:
            break
        i += 1
        book += 1
    elif i >= n and j < m:
        time += b[j]
        if time > k:
            break
        j += 1
        book += 1
    else:
        break
print(book)

Submission status: Wrong Answer

Solution code:
import copy
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()))
a = 0
b = 0

tmp = 0
ans = 0
# for i in range(200000):
#     if A[a] < B[b]:
#         if tmp <= K:
#             tmp += A[a]
#             ans += 1
#             a += 1
#     elif A[a] > B[b]:
#         if tmp <= K:
#             tmp += B[b]
#             ans += 1
#             b += 1
#     if a > len(A)-1 or b > len(B)-1:
#         break
fa = False
fb = False
flag = False
while len(A) >= 0 and len(B) >= 0:
    AA = copy.copy(A)
    BB = copy.copy(B)
    if len(A) != 0:
        a = AA.pop(0)
        fa = True
    if len(B) != 0:
        b = BB.pop(0)
        fb = True
    if fa and fb:
        if a<=b:
            tmp += a
            ans += 1
            A = AA
        else:
            tmp += b
            ans += 1
            B = BB
    else:
        if fa:
            tmp += a
            ans += 1
            A = AA
        if fb:
            tmp += b
            ans += 1
            B = BB

    if tmp > K or ( len(A)==0 and len(B)==0):
        if len(A)==0 and len(B)==0:
            flag = True
        break
    fa = False
    fb = False
    
    #print(tmp)
    
if flag:
    print(ans)
else:
    print(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()))

ans = 0
time = 0


for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
tmp = ans
sub = ans

for j in range(len(b)):
    time += b[j]
    if time > k:
        if sub != 0: 
            for i in range(sub):
                time -= a[sub - 1 - i]
                if time <= k:
                    tmp = tmp - i - 1
                    sub = sub - i - 1
                    break
        else:
            break
    
    tmp += 1
    if tmp > ans :
        ans = tmp
    
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left, bisect_right
import sys

input = sys.stdin.buffer.readline
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AA = list(accumulate([0] + A))
BB = list(accumulate([0] + B))
apos = bisect_right(A, k)

# bpos = bisect_right(B, k)
# j = 0
ans = 0
for i in range(apos, -1, -1):
    temp_a = AA[i]
    remain = k - temp_a
    pos = bisect_left(BB, remain)
    if pos == m + 1:
        pass
    else:
        if BB[pos] == remain:
            pos += 1
    ans = max(ans, i + pos - 1)
    # while j <= bpos:
    #     if remain >= BB[j]:
    #         j += 1
    #     else:
    #         break
    # ans = max(ans, i + j - 1)
    print(i, pos)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

n,m,k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a_cumsum = list(accumulate(a_list))

b_cumsum = list(accumulate(b_list))

ans=0
for i in range(n):
  if k<a_cumsum[i]:
    continue
  b_max=k-a_cumsum[i]
  b_index = max(bisect_right(b_cumsum, b_max)-1,0)  
  koho=i+1+b_index+1
  ans = max(ans,koho)

  
  
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()))
b = list(map(int,input().split()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k >= 0 and min(ad[0],bd[0]) != float('inf'):
        if ad[0] > bd[0]:
            bd.popleft()
        else:
            ad.popleft()
        count += 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


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

    As = map(int, input().split())
    Bs = map(int, input().split())

    mod = 10**9+7

    count = 0
    total = 0

    a = next(As)
    b = next(Bs)

    n = 1
    m = 1

    while True:

        if a == b == mod:
            break

        elif a > b:
            total += b
            if m < M:
                m += 1
                b = next(Bs)
            else:
                b = mod
        else:
            total += a
            if n < N:
                n += 1
                a = next(As)
            else:
                a = mod

        if total > K:
            break
        else:
            count += 1

    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()