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()))
c = a+b
c.sort()
ia = ib = 0
ans = 0
count = 0
if sum(c) <= k:
    print(n+m)
    exit()
if c[0] > k:
    print(0)
    exit() 

while True:
    if ia  == len(a):
        ans += b[ib]
        ib += 1
    elif ib  == len(b):
        ans += a[ia]
        ia += 1       
    elif a[ia] >= b[ib]:
        ans += b[ib]
        ib += 1
    else:
        ans += a[ia]
        ia += 1
    if ans > k:
        print(count)
        break
    count += 1

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()))
a = deque(a)
b = deque(b)
t = 0
book = deque()
while len(b):
    if b[0]+t <= k:
        t += b[0]
        book.append(b.popleft())
    else:
        break
nn = len(book)
# 逆じゅん
new_book = deque()
for i in range(nn):
    new_book.append(book.pop())
book = new_book
# aも詰め込めるだけ
while len(a):
    if a[0]+t <= k:
        t += a[0]
        book.append(a.popleft())
    else:
        break

ans = len(book)
for i in range(nn):
    t -= book.popleft()
    while len(a) and t+a[0]<k:
        ta = a.popleft()
        t += ta
        book.append(ta)
    ans = max(ans, len(book))

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

cnt = 0
time = 0
A_s = sum(A)
B_s = sum(B)

if A_s + B_s <= k:
  print(len(A)+len(B))
  
elif A[0] > k and B[0] > k:
  print(0)
  
else:
  while time <= k:
      if A[0] >= B[0]:
          time += B[0]
          B.pop(0)
          cnt += 1
          if len(B) == 0:
              B.append(10000000000)
      else:
         time += A[0]
         A.pop(0)
         cnt += 1
         if len(A) == 0:
             A.append(10000000000)
  print(cnt-1)

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

    ans = 0
    tmp = 0
    A_d = deque()
    A_d.append(0)
    B_d = deque()
    B_d.append(0)
    for a in A:
        if tmp + a >= K:
            break
        tmp += a
        A_d.append(A_d[-1]+a)
    tmp = 0
    for b in B:
        if tmp + b >= K:
            break
        tmp += b
        B_d.append(B_d[-1]+b)
    A_d.popleft()
    B_d.popleft()

    tmp = len(A_d)
    for i, b in enumerate(B_d, 1):
        if A_d[-1] + b >= K:
            break
        tmp += 1
    ans = tmp
    tmp = len(B_d)
    for i, a in enumerate(A_d, 1):
        if B_d[-1] + a >= K:
            break
        tmp += 1
    print(max(ans, tmp))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp=0
an,bn=0,0
ans=0
while temp<=k:
    if an==n and bn==m: break
    if an>=n:
        temp+=b[bn]
        if temp>k: break
        bn+=1
    elif bn>=m:
        temp+=a[an]
        if temp>k: break
        an+=1
    else:
        if a[an]<b[bn]:
            temp+=a[an]
            if temp>k: break
            an+=1
        elif a[an]>b[bn]:
            temp+=b[bn]
            if temp>k: break
            bn+=1
        else:
            cnt=0
            while True:
                if an==n:
                    bn-=cnt
                    break
                if bn==m:
                    an-=cnt
                    break
                if a[an]<b[bn]:
                    temp+=a[an]
                    an+=1
                    bn-=cnt
                    break
                elif a[an]>b[bn]:
                    temp+=b[bn]
                    bn+=1
                    an-=cnt
                    break
                temp+=a[an]
                if temp>k:
                    break
                flag=1
                an+=1
                bn+=1
                ans+=1
                cnt+=1
            if temp>k:
                break
    ans+=1
print(ans)

Submission status: Wrong Answer

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

cnt = 0

list = A + B
list = [int(s) for s in list]
list.sort()
print(min(list))
ans = min(list)

min = int(int(K)/int(min(list)))
for s in range(len(list)):
    if ans <= int(K):
        cnt += 1
        ans += list[s]

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

cost = 0
cnt = 0

a.extend(b)
a = np.sort(a)

for i in a:
    cnt += 1
    cost += i
    if cost > k:
        cnt-=1
        break


print(cnt)

Submission status: Wrong Answer

Solution code:
gen_input = list(map(int, input().split()))
time_a = list(map(int, input().split()))
time_b = list(map(int, input().split()))

length_a = gen_input[0]
length_b = gen_input[1]
time_const = gen_input[2]

if sum(time_a) + sum(time_b) == time_const:
    print(length_a + length_b)
elif time_const < min(time_a[0], time_b[0]):
    print(0)
elif time_const == min(time_a[0], time_b[0]):
    print(1)

else:
    num_read_books = 0
    i = 0
    j = 0
    while True:
        if (i < length_a) & (j < length_b):
            if time_a[i] >= time_b[j]:
                time_const -= time_b[j]
                j += 1
            else:
                time_const -= time_a[i]
                i += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break
        
        elif (i == length_a) & (j < length_b):
            time_const -= time_b[j]
            j += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break

        elif (i < length_a) & (j == length_b):
            time_const -= time_a[i]
            i += 1
            num_read_books += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break
        else:
            break
    print(num_read_books)

Submission status: Wrong Answer

Solution code:
import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list
while (sum(list_[:cnt+1])<=k) & (cnt<len(list_)):
  cnt+=1

print(cnt)

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()))
sum_a=[0]*(n+1)
for i in range(n):
  sum_a[i+1]=(sum_a[i]+a[i])
sum_b=[0]*(m+1)
for i in range(m):
  sum_b[i+1]=(sum_b[i]+b[i])
ans=0
nokori=k
for i in range(n+1):
  if k>sum_a[i]:
    cnt=i
    nokori=k-sum_a[i]
    cnt+=(bisect.bisect(sum_b,nokori)-1)
    ans=max(ans,cnt)
  else:
    pass
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n,m,k = LI()
a = LI()
b = LI()

i=0
j=0
t=0
while(t <= k):
    if(i == n):
        t += b[j]
        j += 1
    elif(j == m):
        t += a[i]
        i += 1
    else:
        if(a[i] < b[j]):
            t += a[i]
            i += 1
        elif(a[i] > b[j]):
            t += b[j]
            j += 1
        else:
            if(j == m-1 or a[i] > b[j+1]):
                t += b[j]
                j += 1
            elif(i == n-1 or b[j] > a[i+1]):
                t += a[i]
                i += 1
            else:
                t += a[i]
                i += 1


    if(i == n and j == m):
        break

if(t > k):
    print(i + j - 1)
else:
    print(i + j)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    if n < m:
        a_lst, b_lst = b_lst, a_lst
        n, m = m, n

    a_time = [0]
    b_time = []

    t = 0
    for a in a_lst:
        t += a
        if t > k:
            break
        a_time.append(t)
    t = 0
    for b in b_lst:
        t += b
        if t > k:
            break
        b_time.append(t)

    a_que = deque(a_time)
    b_que = deque(b_time)
    cnt = len(a_que)
    c_max = cnt - 1
    while c_max <= cnt and a_que and b_que:
        cnt -= 1
        a = a_que.pop()
        b = b_que.popleft()
        while a + b <= k:
            cnt += 1
            c_max = cnt
            if b_que:
                b = b_que.popleft()
            else:
                break

    print(c_max)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
[n,m,k] = map(int,input().split(" "))
A = list(map(int,input().split()))
B= list(map(int,input().split()))
L = len(A)+len(B)
for i in range(L):
    if len(A) >0 and len(B)>0:
        if A[0]<B[0]:
            k = k-A[0]
            A.pop(0)
        else:
            k = k-B[0]
            B.pop(0)
    elif len(A) >0 and len(B) == 0:
            k = k-A[0]
            A.pop(0)
    elif len(B) >0 and len(A) == 0:
            k = k-B[0]
            B.pop(0)
    if k<0:
        break
    elif len(A)==0 and len(B)==0:
        i = L
        break

print(i)

Submission status: Wrong Answer

Solution code:
#C
from itertools import accumulate
from collections import deque
import bisect

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

cnt = 0

a_c = list(accumulate(list(a)))
b_c = list(accumulate(list(b)))
result = []

idx_a = bisect.bisect_left(a_c,k)
idx_a_b = bisect.bisect_left(b_c,k-list(a_c)[idx_a-1])
result.append(idx_a + idx_a_b)

idx_b = bisect.bisect_left(b_c,k)
idx_b_a = bisect.bisect_left(a_c,k-list(b_c)[idx_b-1])
result.append(idx_b + idx_b_a)

for i in range(n+m):
    if len(a) > 0 and len(b) > 0:
        s,t = a.popleft(),b.popleft()
    elif len(a) > 0:
        s = a.popleft()
        t = float('inf')
    elif len(b) > 0:
        s = float('inf')
        t = b.popleft()
    else:
        break
    if s >= t:
        k -= t
        a.appendleft(s)
    else:
        k -= s
        b.appendleft(t)
    if k < 0:
        break
    else:
        cnt += 1
        #print('a:',a)
        #print('b:',b)
    
result.append(cnt)

print(max(result))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0
    a_time = [0]
    b_time = [0]
    for i in range(1, len(a) + 1):
        a_time.append(a_time[i - 1] + a[i - 1])
    for i in range(1, len(b) + 1):
        b_time.append(b_time[i - 1] + b[i - 1])

    a_max = 0
    b_max = 0
    for i in range(len(a_time)):
        if a_time[i] > k:
            break
        else:
            a_max = i
    for i in range(len(b_time)):
        if a_time[a_max] + b_time[i] <= k:
            ans = max(ans, a_max + i)
        if b_time[i] > k:
            break
        else:
            b_max = i

    for i in range(len(a_time)):
        if b_time[b_max] + a_time[i] <= k:
            ans = max(ans, b_max + i)
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ca = 0
cb = 0
count = 0
ea = False
eb = False
while k >= 0:
  if ea and eb:
    break
  elif ea:
    if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == m):
          eb = True
    else:
      break
  elif eb:
    if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == n):
          ea = True
    else:
      break
  else:
    if a[ca] <= b[cb]:
      if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == n):
          ea = True
      else:
        break
    else:
      if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == m):
          eb = True
      else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
totalbook = 0
totaltime = 0
for a in a_list:
  if totaltime+a <= K:
    totaltime+=a
    totalbook+=1
  else:
    break
ans = totalbook
nowaind = totalbook-1 if totalbook > 0 else 0
nowbind = 0
for b in b_list:
  if totaltime+b<=K:
    totaltime+=b
    totalbook+=1
    nowbind+=1
  else:
    break
ans = max(ans,totalbook)
for b in range(nowbind,len(b_list)):
  while nowaind >= 0 and totaltime+b_list[b]>K:
    totalbook-=1
    totaltime-=a_list[nowaind]
    nowaind-=1
  totaltime+=b_list[b]
  if totaltime<=K:
    totalbook+=1
ans = max(ans,totalbook)

totalbook = 0
totaltime = 0
for b in b_list:
  if totaltime+b <= K:
    totaltime+=b
    totalbook+=1
  else:
    break
ans = max(ans,totalbook)

totalbook
nowbind = totalbook-1 if totalbook > 0 else 0
nowaind = 0
for a in a_list:
  if totaltime+a<=K:
    totaltime+=a
    totalbook+=1
    nowaind+=1
  else:
    break
ans = max(ans,totalbook)
for a in range(nowaind,len(a_list)):
  while nowbind >= 0 and totaltime+a_list[a]>K:
    totalbook-=1
    totaltime-=b_list[nowbind]
    nowbind-=1
  totaltime+=a_list[a]
  if totaltime<=K:
    totalbook+=1
ans = max(ans,totalbook)
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()))
counter = 0
 
for i in range(max(n,m)):
  if len(a) == 0 and len(b) == 0:
    break
  elif len(a) == 0:
    k -= b.pop(0)
  elif len(b) == 0:
    k -= a.pop(0)
  else:
    if  a[0] > b[0]:
      k -= b.pop(0)
    else:
      k -= a.pop(0)
  counter += 1
if k < 0:
  counter -= 1
print(counter)

Submission status: Wrong Answer

Solution code:
N, M, K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
import numpy as np
a=np.cumsum(A)
b=np.cumsum(B)
ida=np.where(a<=K)
idb=np.where(b<=K)
la=len(a[ida])
lb=len(b[idb])
if la>lb:
    ans=la
    K-=a[la-1]
    for x in b:
        if K>=x:
            ans+=1
        else:
            break
elif la<lb:
    ans=lb
    K-=b[lb-1]
    for y in a:
        if K>=y:
            ans+=1
        else:
            break
elif la==lb:
    ansa=la
    K-=a[la-1]
    for i in range(lb):
        if b[i]<=K:
            ansa+=1
        else:
            break
    ansb=lb
    K-=b[lb-1]
    for i in range(la):
        if a[i]<=K:
            ansb+=1
        else:
            break
    ans=max(ansa, ansb)
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]
    nmk[2] -= a[an]
    # if comp(sum,nmk[2]) == False:
    # if sum > nmk[2]:
    if nmk[2] < 0:
      print(ans)
      sys.exit()
    ans += 1
    an += 1
  else:                  # A側の本がが時間がかかる時
    # sum += b[bm]
    nmk[2] -= b[bm]
    # if comp(sum,nmk[2]) == False:
    # if sum > nmk[2]:
    if nmk[2] < 0:
      print(ans)
      sys.exit()
    ans += 1
    bm += 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
temp = [int(i) for i in input().split(" ")]
n = temp[0]
m = temp[1]
k = temp[2]

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


counter = 0
time = 0

while True:

    target = 0

    if len(a) > 0 and len(b) > 0:
        if a[0] <= b[0]:
            target = a.pop(0)
        else:
            target = b.pop(0)

    elif len(a) > 0 and len(b) == 0:
        target = a.pop(0)

    elif len(b) > 0 and len(a) == 0:
        target = b.pop(0)


    time += target
    if time <= k:
        counter += 1
    else:
        break

    if len(a) == 0 and len(b) == 0:
        break

print(counter)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    INF = 10**18
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.append(INF)
    b.append(INF)
    ap = -1
    bp = -1

    cnt = 0
    now = 0
    for i in a:
        if now + i <= k:
            now += i
            cnt += 1
            ap += 1
        else:
            break

    for i in b:
        if now + i <= k:
            now += i
            cnt += 1
            bp += 1
        elif now - a[ap] + i <= k and ap >= 0:
            now = now - a[ap] + i
            ap -= 1
        else:
            break

    print(cnt)

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()))
s=0
t=0
i=n+m
while s==0:
    for j in range(i):
        if i-(j+1)<=m:
            t=sum(a[0:j])+sum(b[0:i-j])
        if 0<t<=k:
            s+=1
    i=i-1
    if i==-1:
        s+=1
print(i+1)

Submission status: Wrong Answer

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

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

b.append(k)
cnt = 0
for i in range(n-1):
    a[i+1] += a[i]

for j in range(m):
    b[j+1] += b[j]

# print(a, b)
ans = 0
for i in range(n):
    nokori = k-a[i]
    if nokori < 0:
        break
    if b[0] > nokori:
        ans = max(i+1, ans)
        continue

    r, l = 0, m

    while(l-r > 1):
        if b[(r+l)//2] <= nokori:
            r = (r+l)//2
        else:
            l = (r+l)//2
        # print(l, r)
    ans = max(i+l+1, ans)
    # print(i, r, l, nokori)

r, l = 0, m

while(l-r > 1):
    if b[(r+l)//2] <= k:
        r = (r+l)//2
    else:
        l = (r+l)//2
        # print(l, r)
ans = max(l+1, ans)
# print(i, r, l, nokori)


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

# print(K)
# print(a)
# print(b)

# K=2
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0
inf=K*2

for i in range (len(a)+len(b)+2):
    A=a[0]
    B=b[0]
    if K<min (A,B):
        break
    else:
        pass
    if A<B:
        ans+=1
        K-=a.pop(0)
        a.append(inf)
    elif A>B:
        ans+=1
        K-=b.pop(0)
        b.append(inf)
    else:
        if len(a)>=2 and len(b)>=2:
            AA=a[0]+a[1]
            BB=b[0]+b[1]
            if AA<=BB:
                ans+=1
                K-=a.pop(0)
                a.append(inf)
            else:
                ans+=1
                K-=b.pop(0)
                b.append(inf)
        else:
            ans+=1
            K-=a.pop(0)
            a.append(inf)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
INF=float("inf")
a.append(INF)
b.append(INF)
for i in range(N+M):
    if a[0]<b[0]:
        K-=a[0]
        ans+=1
        a.pop(0)
    else:
        K-=b[0]
        ans+=1
        b.pop(0)
    if K<=0:
        flag=0
        break
if K>=0:
    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


while K >= 0:
    ans_time = 0
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        ans_time += B.pop(0)
    elif len(B) == 0:
        ans_time += A.pop(0)
    else:
        if A[0] >= B[0]:
            ans_time += B.pop(0)
        else:
            ans_time += A.pop(0)

    if K >= ans_time:
        ans += 1
        ##print(K, ans_time, sep= " ")
        K -= ans_time
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:


N,M,K = map(int, input().split())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))

time = 0
count = 0

while(True):
  if (len(Alist) == 0) and (len(Blist) == 0):
    break
  
  elif (len(Alist) == 0) and (len(Blist) != 0):
    if time+Blist[0] > K:
      break
    else:
      time += Blist.pop(0)
      count += 1
  
  elif (len(Alist) != 0) and (len(Blist) == 0):
    if time+Alist[0] > K:
      break
    else:
      time += Alist.pop(0)
      count += 1
  
  elif (len(Alist) != 0) and (len(Blist) != 0):
    if Blist[0] <= Alist[0]:
      if time+Blist[0] > K:
        break
      else:
        time += Blist.pop(0)
        count += 1  
    else:
      if time+Alist[0] > K:
        break
      else:
        time += Alist.pop(0)
        count += 1
    
print(count)

Submission status: Wrong Answer

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

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

R = K
A_index = 0
B_index = 0
ans = 0
while N > 0:
    if R >= A[A_index]:
        R = R - A[A_index]
        ans += 1
        A_index += 1
        N -= 1
    else:
        A_index -= 1
        break
if N == 0:
    A_index -= 1

while M > 0:
    if R >= B[B_index]:
        R = R - B[B_index]
        ans += 1
        B_index += 1
        M -= 1
    else:
        B_index -= 1
        break

if M == 0:
    B_index -= 1

if N == 0 and M == 0:
    print(ans)
    sys.exit()

max = ans

while True:
    if A_index >= 0:
        R += A[A_index]
        A_index -= 1
        ans -= 1
        while B_index < len(B):
            if R >= B[B_index]:
                R -= B[B_index]
                B_index += 1
                ans += 1
            else:
                break
        
        if ans > max:
            max = ans
    else:
        break

print(max)

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 csum(l,ll):
    s = 0
    res = [0] * ll
    for i in range(ll):
        s += l[i]
        res[i] = s
    return res

csln = csum(ln,n)
cslm = csum(lm,m)

import numpy as np

lk = [k-x for x in csln if k-x >=0]
res = np.searchsorted(np.array(cslm), np.array(lk), side='right')
rmax = 0
for i,j in zip(range(1,len(lk)+1), res):
    rmax = max(rmax, i+j)
print(rmax)

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
n=i[0]
m=i[1]
k=i[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a=b=0 #それぞれの読んだ数
cal=0 #読んだ時間
if max(A)>1000000000 or max(B)>1000000000:
    print(0)
else:
    while True:
        if a!=n and b!=m:
            if A[a]<B[b]:
                cal+=A[a]
                a+=1
                if cal>k:
                    a-=1
                    break
            elif B[b]<A[a]:
                cal+=B[b]
                b+=1
                if cal>k:
                    b-=1
                    break
        elif a==n and b==m:
            break
        elif a==n:
            cal+=B[b]
            b+=1
            if cal>k:
                b-=1
                break
        elif b==m:
            cal+=A[a]
            a+=1
            if cal>k:
                a-=1
                break
    print(a+b)

Submission status: Wrong Answer

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

count = sum(a)
p = n-1
ans = 0
judge = True
for i in range(m+1):
  flag = False
  count += b[i]
  while count > k and judge:
    count -= a[p]
    p -= 1
    if p == -1:
      if count > k:
        flag = True
      else:
        judge = False
      break
  if flag:
    break
  sub = p+1+i
  if ans < sub:
    ans = sub
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
N, M, K = map(int, input().split())
A = deque([int(i) for i in input().split()])
B = deque([int(i) for i in input().split()])
cur = 0
ans = 0
while cur < K and ans < N+M:
    if len(A) != 0 and len(B) != 0:
        a = A.popleft()
        b = B.popleft()
        if a <= b:
            cur += a
            if cur > K:
                break
            B.appendleft(b)
            ans += 1
        else:
            cur += b
            if cur > K:
                break
            A.appendleft(a)
            ans += 1
    elif len(A) == 0:
        b = B.popleft()
        cur += b
        if cur > K:
            break
        ans += 1
    elif len(B) == 0:
        a = A.popleft()
        cur += a
        if cur > K:
            break
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = input().split(" ")
lista = [int(n) for n in a]
b = input().split(" ")
listb = [int(n) for n in b]
time = 0
count = 0
while k>=time:
  if (len(lista)>0 and len(listb)>0 and lista[0]>=listb[0]) or (len(listb)>0 and len(lista)==0):
    time+=listb.pop(0)
    count+=1  
  elif (len(lista)>0 and len(listb)>0 and listb[0]>=lista[0]) or (len(lista)>0 and len(listb)==0):
    time+=lista.pop(0)
    count+=1
  else:
    count+=1
    break
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()))
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:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

from collections import deque
a=deque(a)
b=deque(b)

t=0
c=0

while 1:
    if len(a)==0 and len(b)==0:
        print(c)
        break
    elif len(a)!=0 and len(b)!=0:
        if a[0]<=b[0]:
            t+=a[0]
            if t<=k:
                c+=1
                a.popleft()
            else:
                print(c)
                break
        else:
            t+=b[0]
            if t<=k:
                c+=1
                b.popleft()
            else:
                print(c)
                break
    else:
        if len(a)==0:
            t+=b[0]
            if t<=k:
                c+=1
                b.popleft()
            else:
                print(c)
                break
        else:
            t+=a[0]
            if t<=k:
                c+=1
                a.popleft()
            else:
                print(c)
                break

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = [int(x) for x in input().split()]+[10**10]
B = [int(y) for y in input().split()]+[10**10]
a = 0
b = 0
hon = 0
C = []
D = []

for p in range(0,N):
    if p == 0:
        C += [int(A[0])]
    else:
        C += [int(A[p])+int(C[p-1])]
for q in range(0,M):
    if q == 0:
        D += [int(B[0])]
    else:
        D += [int(B[q])+int(D[q-1])]

for p in range(0,N):
    for q in range(0,M):
        if C[p]+D[q] <= K:
            hon = max(p+q+2,hon)
print(hon)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
ac = 0
bc = 0
alen = len(a)
blen= len(b)
allbook = alen + blen
count = 0
while True:
  if k < total:
    count -= 1
    break
  if bc < blen:
    if ac < alen and a[ac] < b[bc]:
      total += a[ac]
      ac += 1
      count += 1
      continue
    else:
      total += b[bc]
      bc += 1
      count += 1
      continue
  if ac < alen:
    if bc < blen and a[ac] > b[bc]:
      total += b[bc]
      bc += 1
      count += 1
      continue
    else:
      total += a[ac]
      ac += 1
      count += 1
      continue
  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
cost = 0
for i, x in enumerate(a):
    cost += x
    if cost > k:
        cnt = i
        cost -= x
        break
else:
    for j, y in enumerate(b):
        cost += y
        if cost > k:
            cnt = n + j
            cost -= y
            break
    else:
        cnt = n + m

if cnt <= n:
    i_max, j = cnt - 1, 0
else:
    i_max, j = n - 1, cnt - n - 1

while cost + b[j] <= k and j < m - 1:
    j += 1
    cnt += 1
    cost += b[j]

ans = cnt
for i in range(i_max, -1, -1):
    if j == m - 1: break
    cost -= a[i]
    cnt -= 1
    while cost + b[j] <= k and j < m - 1:
        j += 1
        cnt += 1
        cost += b[j]
    ans = max(cnt, ans)

print(ans)