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

# 累積和
CA = A
CB = B
sA = sum(A)
sB = sum(B)
for i in range(N-1):
    CA[i+1] = CA[i] + A[i+1]
for i in range(M-1):
    CB[i+1] = CB[i] + B[i+1]

def countmax(CA, N, K):
    for i in range(N):
        if CA[i] > K:
            return i
    return N


if CA[-1] <= K: # 全読み可
    AyomiA = N
    AyomiB = countmax(CB, M, K - sA)
else:
    AyomiA = countmax(CA, N, K)
    AyomiB = countmax(CB, M, K-CA[AyomiA-1])

## Bの全読み
if CB[-1] <= K: # 全読み可
    ByomiB = M
    ByomiA = countmax(CA, N, K - sB)
else:
    ByomiB = countmax(CB, M, K)
    ByomiA = countmax(CA, N, K-CB[ByomiB-1])


# Bでカウントする時
if AyomiA - ByomiA > ByomiB - AyomiB:
    count = 0
    for b in range(AyomiB, ByomiB + 1):
        count = max(count, b + countmax(CA, N, K - CB[b-1]))
else:
# Aでカウントする時
    count = 0
    for a in range(ByomiA, AyomiA + 1):
        count = max(count, a + countmax(B, M, K - CA[a-1]))
         
print(count)

Submission status: Wrong Answer

Solution code:
import itertools

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

iter = [x for x in itertools.chain.from_iterable(itertools.zip_longest(A,B)) if x]
cnt =  0
sum = 0
for i in iter:
    sum += i
    if sum > K:
        break
    else:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
[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()]

ans =0 

while k > 0 and len(b)>0 and len(a)>0:
    if len(a) > 0 and a[0] <= b[0]:
        if k >= a[0]:
            k -= a[0]
            ans += 1
            a.pop(0)
        else:
            break

    elif len(b) > 0 and  b[0] <= a[0]:
        if k >= b[0]:
            k -= b[0]
            ans += 1
            b.pop(0)
        else:
            break


if len(b)>0:
    while len(b)>0 and k >= b[0]:
        k -= b[0]
        ans += 1
        b.pop(0)

elif len(a)>0:
    while len(a)>0 and k >= a[0]:
        k -= a[0]
        ans += 1
        a.pop(0)


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()))
Ain = 0
Bin = 0
check = False
if(min(A[0],B[0])>K):
    print(0)
    exit()
if(sum(A)+sum(B)<=K):
    print(N+M)
    exit()
while K>0:
    if(Ain != N and Bin !=M): 
        if(A[Ain] < B[Bin]):
            if(K-A[Ain]<0):
                break
            else:
                K-=A[Ain]
                Ain += 1
        elif(A[Ain]>B[Bin]):
            if(K-B[Bin]<0):
                break
            else:
                K-=B[Bin]
                Bin += 1
        
    elif((Ain == N) and (Bin == M)):
        check = True
        break
    elif(Ain==N):
        if(K-B[Bin]<0):
            break
        else:
            K -= B[Bin]
            Bin += 1
    elif(Bin==M):
        if(K-A[Ain]<0):
            break
        else:
            K -= A[Ain]
            Ain += 1
print(Ain+Bin)

Submission status: Wrong Answer

Solution code:

def main2():
    n, m, k = list(map(int, input().split()))
    a_books = list(map(int, input().split()))
    b_books = list(map(int, input().split()))

    minutes = 0
    count = 0
    a_idx = 0
    b_idx = 0
    if a_books[0] > k and b_books[0] > k:
        print(0)
        exit()
    elif sum(a_books) + sum(b_books) <= k:
        print(len(a_books) + len(b_books))
        exit()
    while minutes <= k:
        # print(minutes, a_idx, b_idx)

        if b_idx >= len(b_books) and a_idx >= len(a_books):
            break
        elif b_idx >= len(b_books) or (a_idx < len(a_books) and a_books[a_idx] <= b_books[b_idx]):
            minutes += a_books[a_idx]
            a_idx += 1
        elif a_idx >= len(a_books) or (b_idx < len(b_books) and b_books[b_idx] <= a_books[a_idx]):
            minutes += b_books[b_idx]
            b_idx += 1
        if minutes > k:
            break
        count += 1
    print(count)



if __name__ == '__main__':
    main2()

Submission status: Wrong Answer

Solution code:
"""
AtCoder :: Beginner Contest 172 :: C :: Tsundoku
https://atcoder.jp/contests/abc172/tasks/abc172_c

"""
import sys


def solve(A, B, K):
    """Solve puzzle."""
    a = b = 0
    books_read = 0
    read_time = 0
    while read_time <= K:
        book_time = 0
        if a >= len(A) and b >= len(B):
            break
        elif a >= len(A):
            book_time = B[b]
            b += 1
        elif b >= len(B):
            book_time = A[a]
            a += 1
        elif A[a] < B[b]:
            book_time = A[a]
            a += 1
        else:
            book_time = B[b]
            b += 1

        if book_time + read_time > K:
            break
        
        read_time += book_time
        books_read += 1

    return books_read


def main():
    """Main program."""
    N, M, K = (int(i) for i in sys.stdin.readline().split())
    A = [int(i) for i in sys.stdin.readline().strip().split()]
    B = [int(i) for i in sys.stdin.readline().strip().split()]
    print(solve(A, B, K))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a= list(map(int,input().split())) #n冊

b= list(map(int,input().split())) #m冊
#ab=a+b
#print(ab)

if n>m:
    q=0
    while q<=(n-m):
        b.append(100000000000)
        q+=1
elif m>n:
    p=0
    while p<=(m-n):
        a.append(100000000000)
        p+=1

ab=[110000000000]*(n+m)
ans=0
count=0
i=0
A=0
B=0
if sum(a)+sum(b)<=k:
    ans=n+m
    print(ans)
else:
    while i<(n+m) and A<n and B<m:
        ab[i]=min(a[A],b[B])
        if a[A]>=b[B]:
            B+=1
            i+=1
        else :
            A+=1
            i+=1
    for i in range(n+m):
        ans+=ab[i]
        if ans>k:
            break
        else:
            count+=1
    print(ab)
    print(count)

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

sum_minute = 0
ans = 0
while (sum_minute <= k) and (a or b):
    if a and b:
        if sum_minute + min(a[0], b[0]) <= k:
            if a[0] <= b[0]:
                r = a.popleft()
                sum_minute += r
                ans += 1
            else:
                r = b.popleft()
                sum_minute += r
                ans += 1
        else:
            break
    elif not a:
        if sum_minute + b[0] <= k:
            r = b.popleft()
            sum_minute += r
            ans += 1
        else:
            break
    elif not b:
        if sum_minute + a[0] <= k:
            r = a.popleft()
            sum_minute += r
            ans += 1
        else:
            break

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    sum += a[i]
for i in range(m):
    sum += b[i]

if sum<=k:
    print(n+m)
    sys.exit()


sum = 0
cnt =0
while sum < k and  (len(a) != 0 or len(b) != 0 ):
    if len(a) != 0 and len(b) != 0:
        if a[0]<b[0]:
            sum += a[0]
            del a[0]
        else:
            sum += b[0]
            del b[0]
    elif len(a) == 0:
        sum += b[0]
        del b[0]
    else :
        sum += a[0]
        del a[0]
    if sum<=k :
        cnt+=1
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
m,n,k =map(int,input().split())
ml=list(map(int,input().split()))
nl=list(map(int,input().split()))
t1=[]
tl=ml+nl
tl.sort()
sum=0
count=0
for i in range(len(tl)):
  if sum+tl[i]<k:
    sum=sum+tl[i]
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lla=[]
counta=0
for i in la:
    counta+=i
    lla.append(counta)
countb=0
llb=[]
for j in lb:
    countb+=j
    llb.append(countb)
for i in range(n):
    if lla[i]>k:
        break
if lla[n-1]<=k:
    book=n
    num=n-1
elif lla[n-1]>k and i==n-1:
    book=n-1
    num=n-2
elif i!=0:
    num=i-1
    book=i
else:
    num=0
    book=0
num=i
while num>=0 and book<m+n and book-num-1<=m-1:
    if num!=0:
        if lla[num]+llb[book-num-1]<=k:
            book+=1
        else:
            num-=1
    elif num==0:
        if llb[book-num-1]<=k:
            book+=1
        else:
            num-=1

print(book)

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

book, index_A, index_B = 0, 0, 0
for i in range(N+M):
    if index_A < N:
        book_A = A[index_A]
    else:
        book_A = 0
    if index_B < M:
        book_B = B[index_B]
    else:
        book_B = 0

    if book_A <= book_B:
        if book_A < K:
            K -= book_A
            index_A += 1
            book += 1
        else:
            break
    else:
        if book_B < K:
            K -= book_B
            index_B += 1
            book += 1
        else:
            break
print(book)

Submission status: Wrong Answer

Solution code:
booksA, booksB, timeLimit = [int(x) for x in input().split()]
tA = [int(x) for x in input().split()]
tB = [int(x) for x in input().split()]
count = 0
time = 0
while True:
    if len(tA) > 0 and len(tB) >0:
        if tA[0] < tB[0]:
            time += tA.pop(0)
        else:
            time += tB.pop(0)
        if time > timeLimit:
            break
        count+=1
    if len(tA) == 0:
        time += tB.pop(0)
        if time > timeLimit:
            break
        count+=1
        if len(tB) == 0:
            break
    elif len(tB) == 0:
        time += tA.pop(0)
        if time > timeLimit:
            break
        count+=1
        if len(tA) == 0:
            break
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
t=[]
if sum(a)+sum(b)<=k:
    c=n+m
elif a[0]==k and b[0]==k:
    c=1
elif a[0]>k:
    while k>=b[0]:
        k-=b[0]
        b=b[1:]
        c+=1
elif b[0]>k:
    while k>=a[0]:
        k-=a[0]
        a=a[1:]
        c+=1
else:
    for u in range(n):
        for r in range(m):
            if sum(a[:u])+sum(b[:r])<=k:
                t.append(u+r)
    c=max(t)
print(c)

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((map(int,input().split())))


time=0
ans=0
while True:
    if not A and not B:
        break
    elif not A:
        now=B.popleft()
    elif not B:
        now=A.popleft()
    else:
        if A[0]<=B[0]:
            now=A.popleft()
        else:
            now=B.popleft()
    if time+now>k:
        break
    else:
        time+=now
        ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input().split()[-1])
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=i=t=0
while len(a+b)>0:
	if len(b)==0 or len(a)>0 and a[0]<b[0]:t=a.pop(0)
	else:t=b.pop(0)
	if c+t>=k:break
	c+=t;i+=1
print(i)

Submission status: Wrong Answer

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

while total < int(M):
    if len(A) > 0:
        comp_A = A[0]
        if len(B) > 0:
            comp_B = B[0]
            if int(comp_A) < int(comp_B):
                total += int(comp_A)
                del A[0]
                count += 1
            else:
                total += int(comp_B)
                del B[0]
                count += 1
        else:
            comp_A = A[0]
            total += int(comp_A)
            del A[0]
            count += 1
    else:
        comp_B = B[0]
        total += int(comp_B)
        del B[0]
        count += 1
        
if total == int(M):
    print(count)
else:
    print(count - 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from bisect import bisect_left, bisect_right

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    if sum(A) + sum(B) <= K:
        print(N + M)
    elif A[0] > K or B[0] > K or A[0] + B[0] > K:
        print(0)
    else:
        # AとBの累積和
        cA = [0] * (N + 1)
        cB = [0] * (M + 1)
        for k in range(N):
            cA[k + 1] = cA[k] + A[k]
        for k in range(M):
            cB[k + 1] = cB[k] + B[k]

        # 読むAの冊数
        ans = -1
        for a in range(N):
            rem = K - cA[a]
            bli = bisect_left(cB, rem)
            bri = bisect_right(cB, rem)
            ans_a = None
            if bli == bri:
                ans_a = a + bli - 1
            else:
                ans_a = a + bli
            ans = max(ans, ans_a)
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# x = list(map(int, input().split()))   :  int の リスト入力
# x, y = map(int, input().split())      :  それぞれの変数に　int 入力
# z = set(map(int, input().split()))    :
# t = int(input())                      :   

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum = 0
i = 0
cnt = 0

while sum <= k:
    if len(a)+len(b)==0:
        i += 1
        break;
    elif len(a)==0:
        sum += b.pop(0)
    elif len(b)==0:
        sum += a.pop(0)
    elif a[0]<b[0]:
        sum += a.pop(0)
    elif a[0]>b[0]:
        sum += b.pop(0)
    else:
        if len(a)==1:
            sum += b.pop(0)
        elif len(b)==1:
            sum += a.pop(0)
        else:
            sum += a.pop(0)
    i += 1

    

print(i-1)

Submission status: Wrong Answer

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

a_i= 0
b_i= 0
f = True

if sum(a)+sum(b) <= k:
    print(n+m)
    exit()

for i in range(n+m):
    # print(a_i,b_i,k) 
    if a[a_i] < b[b_i]:
        k -= a[a_i]
        if k <= 0:
            print(a_i+b_i)
            exit()
        a_i += 1
        if a_i == n:
            for j in range(m):
                # print(a_i,b_i,k)
                k -= b[b_i]
                if k <= 0:
                    print(a_i+b_i)
                    exit()
                b_i += 1
    else:
        k -= b[b_i]
        if k <= 0:
            print(a_i+b_i)
            exit()
        b_i += 1
        if b_i == m:
            for j in range(n):
                # print(a_i,b_i,k)
                k -= a[a_i]
                if k <= 0:
                    print(a_i+b_i)
                    exit()
                a_i += 1

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]

x = a.pop()
y = b.pop()
v = len(a)
w = len(b)
ans = 0

while k >= 0:
    if x == 10**9 + 1 and y == 10**9 + 1:
        break
    if x >= y:
        k -= y
        if w == 0:
            y = 10**9 + 1
        else:
            y = b.pop()
            w -= 1
    else:
        k -= x
        if v == 0:
            x = 10**9 + 1
        else:
            x = a.pop()
            v -= 1
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
nmk = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_num = 0
b_num = 0
ans = 0
time = 0
priority = "tmp"
for i in range(nmk[0]+nmk[1]):
    try:
        if a[a_num]<b[b_num]:
            time += a[a_num]
            if time<=nmk[2]:
                ans += 1
                a_num += 1
            else:
                break
        elif a[a_num]==b[b_num]:
            a_tmp = a_num
            b_tmp = b_num
            while(True):
                a_tmp += 1
                b_tmp += 1
                if a[a_tmp]!=b[b_tmp]:
                    priority = "a" if a[a_tmp]<b[b_tmp] else "b"
                    if priority=="a":
                        time += a[a_num]
                        if time<=nmk[2]:
                            ans += 1
                            a_num += 1
                        else:
                            break
                    else:
                        time += b[b_num]
                        if time<=nmk[2]:
                            ans += 1
                            b_num += 1
                        else:
                            break
        elif a[a_num]>b[b_num]:
            time += b[b_num]
            if time<=nmk[2]:
                ans += 1
                b_num += 1
            else:
                break
    except:
        if a_num==nmk[0]:
            time += b[b_num]
            if time<=nmk[2]:
                ans += 1
                b_num += 1
            else:
                break
        elif b_num==nmk[1]:
            time += a[a_num]
            if time<=nmk[2]:
                ans += 1
                a_num += 1
            else:
                break

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

cumlA = [0]
for i in range(len(A)):
    cumlA.append(cumlA[-1]+A[i])

cumlB = [0]
for i in range(len(B)):
    cumlB.append(cumlB[-1]+B[i])

max = 0
for i in range(len(cumlA)):
    l = list(filter(lambda x: x <= K-cumlA[i], cumlB))
    if max < i + len(l) - 1:
        max = i + len(l) - 1

print(max)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b,c=mi()
l=list(mi())
m=list(mi())
p=0
ans=0
i=0
j=0
while i<a and j<b:
  if l[i]<=m[j]:
    p+=l[i]
    i+=1
  else:
    p+=m[j]
    j+=1
  if p<=c:
    ans+=1
  else:
    print(ans)
    sys.exit()
if i==a:
  while j<b:
    p+=m[j]
    j+=1
    if p<=c:
      ans+=1
    else:
      print(ans)
      sys.exit()
else:
   while i<a:
    p+=l[i]
    i+=1
    if p<=c:
      ans+=1
    else:
      print(ans)
      sys.exit() 
print(ans)

Submission status: Wrong Answer

Solution code:
number = input().split(" ")
a = int(number[0])
b = int(number[1])
time = int(number[2])

a_book = input().split(" ")
b_book = input().split(" ")

x = 0

while time >= 0 :
    if len(a_book)<=0 and len(b_book)<=0:
        break
    elif len(a_book)<=0:
        time -= int(b_book[0])
        b_book.pop(0)
        x += 1
    elif len(b_book)<=0:
        time -= int(a_book[0])
        a_book.pop(0)
        x += 1
    else:
        if int(a_book[0]) >= int(b_book[0]):
            time -= int(b_book[0])
            b_book.pop(0)
            x += 1
        else:
            time -= int(a_book[0])
            a_book.pop(0)
            x += 1
if time < 0:
    print(x-1)
else:
    print(x)

Submission status: Wrong Answer

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

i, j = 0, 0
readed = 0
count = 0

while True:
    if i >= n:
        if j >= m:
            break
        else:
            readed += b[j]
            j += 1
    elif j >= m:
        readed += a[i]
        i += 1
    elif a[i] <= b[j]:
        readed += a[i]
        i += 1
    else:
        readed += b[j]
        j += 1
    if readed > k:
        break
    count += 1
print(count)

Submission status: Wrong Answer

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

max_num = 0

for a in range(N+1):
    for b in range(max_num-a,M+1):
        if sum(A[:a])+sum(B[:b]) <= K:
            if max_num < a+b:
                max_num = a+b
        else:
            break

print(int(max_num))

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をi冊読む
sum_a = [0]*n
sum_b = [0]*m
sum_a[0] = a[0]
sum_b[0] = b[0]
for i in range(1, n):
    sum_a[i] = sum_a[i-1]+a[i]
for i in range(1, m):
    sum_b[i] = sum_b[i-1]+b[i]

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if list[high] <= item:
        return high+1
    if list[low] > item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low == 1:
            return high
        # if guess == item:
            # return mid
        if guess > item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n):
    tmp_ans = i+1
    tmp_k = k-sum_a[i]
    # print(i, tmp_k)
    if tmp_k <= 0:
        pass
    else:
        b_index = binary_search(sum_b, tmp_k)
        tmp_ans += b_index
        # print('a', i, b_index)
        if tmp_ans > ans:
            ans = tmp_ans

tmp_ans = 0
if sum_b[0] < k:
    tmp_ans = binary_search(sum_b, k)+1
if tmp_ans > ans:
    ans = tmp_ans
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
val=0
i=0
j=0
temp=0
for i in range(n+m):
    if(val<k):
        if(len(l1)>0)and(len(l2)>0):
            if(l1[0]<l2[0]):
                val+=l1[0]
                l1.remove(l1[0])
                temp+=1
            elif(l1[0]>l2[0]):
                val+=l2[0]
                l2.remove(l2[0])
                temp+=1
        elif(len(l1)>0)and(len(l2)<1):
            val+=l1[0]
            l1.remove(l1[0])
            temp+=1
        elif(len(l2)>0)and(len(l1)<1):
            val+=l2[0]
            l2.remove(l2[0])
            temp+=1
        elif(len(l1)<1)and(len(l2)<1):
            break
    else:
        break
if(val<=k):
    print(temp)
else:
    print(temp-1)

Submission status: Wrong Answer

Solution code:

n,m,K = map(int,input().split())
A = list(map(int,input().split())) #using a
B = list(map(int,input().split())) #using b
ans =0

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

while(K>0):
    if(A!= [10**10] or B!= [10**10] ):
        ans+=1
        if A[0]<=B[0]:
            K -= A.pop(0)
        else:
            K -= B.pop(0)
    else:
        break
if(K<0):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()]
a_i=0
b_i=0
a_c=0
b_c=0
for i in a:
    a_c+=i
    if a_c>=k:
        a_c-=i
        break
    a_i+=1
for i in b:
    b_c+=i
    if b_c>=k:
      b_c-=i
      break
    b_i+=1
if a_c+b_c<=k:
    print(a_i+b_i)
else:
    for j in a:
      b_c+=j
      if b_c>=k:
        break
      b_i+=1
    for j in b:
      a_c+=j
      if a_c>=k:
        break
      a_i+=1
    if a_i>b_i:
      print(a_i)
    else:
      print(b_i)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
from collections import deque
an= deque(map(int, input().split()))
bm= deque(map(int, input().split()))
ans =0
count = 0
while count <=k and len(an)+len(bm)>0:
    if len(an)>0 and len(bm)>0:
        if an[0] >= bm[0]:
            mini = bm.popleft()
            count += mini
            if count <=k:
                ans +=1
        else:
            mini = an.popleft()
            count += mini
            if count <= k:
                ans += 1
    elif len(an)>0 and len(bm)==0:
        mini = an.popleft()
        count += mini
        if count <= k:
            ans += 1
    elif len(bm)>0 and len(an)==0:
        mini = bm.popleft()
        count += mini
        if count <= k:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import deque
n,m,k=getNM()
a=getList()
b=getList()
a_=k
b_=k
check=True
ans=[0]
if a[0]<=k:
    ans.append(1)
if b[0]<=k:
    ans.append(1)
for i in range(1,n+1):
    if sum(a[:i])>k:
        break
    for j in range(1,m+1):
        if sum(b[:j])>k:
            break
        if sum(a[:i])+sum(b[:j])<=k:
            ans.append(i+j)
print(max(ans))

Submission status: Wrong Answer

Solution code:
n,m,k =map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(10**9+1)
b.append(10**9+1)
cnt = 0
cnt2 = 0
mo = 0
while mo <= k:
  if a[cnt] >= b[cnt2]:
    mo += b[cnt2]
    cnt2+=1
  else:
    mo += a[cnt]
    cnt += 1

print(cnt+cnt2-1)

Submission status: Wrong Answer

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

_sum = 0
count = -1
while _sum <= K:
    
    if A and B:
        if A[0]<B[0]:
            _sum += A[0]
            del A[0]
        else:
            _sum += B[0]
            del B[0]
    elif A:
        _sum += A[0]
        del A[0]
    elif B:
        _sum += B[0]
        del B[0]
    else:
        count += 1
        break
    
    count += 1

print(count)

Submission status: Wrong Answer

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

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]

ans = 0

for i, a in enumerate(A):
    time = K - a
    if time < 0:
        break
    cnt = i + 1
    if time != 0:
        tmp = bisect(B, time)
        cnt += tmp
    ans = max(ans, cnt)

print(ans)

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 or len(B) > 0:
    AA = copy.copy(A)
    BB = copy.copy(B)
    if len(AA) != 0:
        a = AA.pop(0)
        fa = True
    if len(BB) != 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:
        break
    if len(A) == 0 and len(B)==0:
        flag = True
    fa = False
    fb = False
    
    #print(tmp,A,B)
    
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()))

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

c=0

for i in range(10**10):
    a = A[0]
    b = B[0]
    if a < b:
        K = K-a
        if K<=0:
            break
        A = A[1:] 
        c = c+1
    else:
        K = K - b
        if K<=0:
            break
        B = B[1:]
        c = c+1
        
print(c)

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

if b[0] > k:
    pass
else:
    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:
a = input().split()
x = input().split()
y = input().split()
z = x + y
zz = []
zz = list(map(lambda i: int(i), z))
t = 0
m = 0
for i in range(len(zz)):
  if t < int(a[2]):
    t += sorted(zz)[i]
    m += 1
  else:
    break
    
print(m)

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

sumA=[A[0]]
sumB=[B[0]]


for i in range(1,N):
  sumA.append(sumA[-1]+A[i])

for a in range(len(sumA)):
  if sumA[a]>K:
    lessthanA=a-1
    break
if sumA[-1]<=K:
  lessthanA=N-1

 
for i in range(1,M):
  sumB.append(sumB[-1]+B[i])

  
totalBook=0
time=0

if A[0]>K and B[0]>K:
  totalBook=0
elif A[-1]+B[-1]<=K:
  totalBook=N+M

else:
  for a in range(lessthanA,-1,-1):
    print(a*10000)
    for b in range(len(sumB)):
      print(b*1000000)
      if sumB[b]>=K-sumA[a]:
        print("sumB")
        print(sumB[b])
        break
      
    if a+b>=totalBook:
      print("totalBook")
      print(a)
      print(b)
      totalBook=a+b+1

print(totalBook)