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()))
a.sort()
b.sort()
alen=0
blen=0
minute=0
ans=0
while(minute<=k):
    if(alen==n and blen==m):
        break
    elif(alen==n):
        minute+=b[blen]
        ans+=1
        blen+=1
    elif(blen==m):
        minute+=a[alen]
        ans+=1
        alen+=1
    else:
        if(a[alen]<b[blen]):
            minute+=a[alen]
            alen+=1
        else:
            minute+=b[blen]
            blen+=1
        ans+=1
if(minute<=k):
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
def resolve():
    N, M, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    sumA = 0
    ai, bi = 0, 0
    while ai < N and bi < M:
        if A[ai] < B[bi] and sumA + A[ai] <= K:
            sumA += A[ai]
            ai += 1
        elif sumA + B[bi] <= K:
            sumA += B[bi]
            bi += 1
        else:
            break
    if ai < N:
        for i in range(ai, N):
            if sumA + A[i] <= K:
                sumA += A[i]
                ai += 1
            else:
                break
    elif bi < M:
        for i in range(bi, M):
            if sumA + B[i] <= K:
                sumA += B[i]
                bi += 1
            else:
                break
    print(ai + bi)


resolve()

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
minu=0
while 1:
  if a_i==n and b_i==m:
    break
  if a_i==n:
    minu+=b[b_i]
    b_i+=1
    continue
  if b_i==m:
    minu+=a[a_i]
    a_i+=1
    continue
  if minu+min(a[a_i],b[b_i]) >= k:
    break
  if a[a_i] < b[b_i]:
    minu+=a[a_i]
    a_i+=1
  elif a[a_i] > b[b_i]:
    minu+=b[b_i]
    b_i+=1
  else:
    if minu + a[a_i]*2 < k:
      minu+=a[a_i]*2
      a_i+=1
      b_i+=1
    else:
      minu+=a[a_i]
      a_i+=1
      break
print(a_i+b_i)

Submission status: Wrong Answer

Solution code:

from collections import deque



# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def main():
    # n = int(input())
    # l = [int(j) for j in input().split()]
    
# 3 4 240
# 60 90 120
# 80 150 80 150

    # for t in range(int(input())):
    n,m,k = [int(j) for j in input().split()]
    l1 = [int(j) for j in input().split()]
    l2 = [int(j) for j in input().split()]
    pre = [0]*n
    mon = 0
    i = 0
    j = 0
    # book = 0
    while(mon<=k and i<n and j<m):
        if(l1[i]>l2[j]):
            if mon+l2[j]<=k:
                mon+=l2[j]
                j+=1
            else:
                mon = k+1
        else:
            if mon+l1[i]<=k:
                mon+=l1[i]
                i+=1
            else:
                mon = k+1
        # print(i,j,mon)
    while i<n and mon<=k:
            if mon+l1[i]<=k:
                mon+=l1[i]
                i+=1
            else:
                mon = k+1
    while j<m and mon<=k:
            if mon+l2[j]<=k:
                mon+=l2[j]
                j+=1
            else:
                mon = k+1
    print(i+j)




# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def c_tsundoku():
    N, M, K = [int(i) for i in input().split()]
    A = sorted([int(i) for i in input().split()], reverse=True)
    B = sorted([int(i) for i in input().split()], reverse=True)

    time = 0
    ans = 0
    for _ in range(M + N):
        a = float('inf') if len(A) == 0 else A[-1]
        b = float('inf') if len(B) == 0 else B[-1]

        if a < b:
            t = A.pop()
            time += t
            ans += 1
        else:
            t = B.pop()
            time += t
            ans += 1

        if time > K:
            ans -= 1
            break
        elif time == K:
            break
    return ans

print(c_tsundoku())

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

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

print (str(r))

Submission status: Wrong Answer

Solution code:
# C

import itertools

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

cumsuma_l = list(itertools.accumulate(a_l)) 
cumsumb_l = list(itertools.accumulate(b_l))

ans = 0
for i in range(n):
    _a = cumsuma_l[i]
    if _a > k:
        continue
    for j in range(m):
        if _a + cumsumb_l[j] <= k:
            ans = max(ans, i+j+2)
        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori


def main():
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    maxcount=0
    totaltime=0
    maxa=0
    for i in range(n):
        if totaltime+a[i]<=k:
            totaltime+=a[i]
            maxcount+=1
        else:
            maxa=i-1
            break
    for i in range(m):
        if totaltime+b[i]<=k:
            totaltime+=b[i]
            maxcount+=1
        else:
            if maxa<0:
                break
            else:
                if totaltime-a[maxa]+b[i]<=k:
                    totaltime=totaltime-a[maxa]+b[i]
                    maxa-=1
    print(maxcount)


if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
import sys
import bisect

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    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()]

    ruisekia = [0] * N
    ruisekib = [0] * M

    for i, a in enumerate(A):
        ruisekia[i] = ruisekia[i - 1] + a

    for i, b in enumerate(B):
        ruisekib[i] = ruisekib[i - 1] + b

    ruisekia = [0] + ruisekia
    ruisekib = [0] + ruisekib


    ans = 0
    for i in range(N + 1):
        nokori = K - ruisekia[i]
        if nokori <= 0:
            continue
        x = bisect.bisect_right(ruisekib, nokori)
        ans = max(ans, x + i - 1)

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
A.reverse()
B.reverse()
cnt=0
for i in range(N+M):
    if len(A)>0 and len(B)>0:
        if A[-1] > B[-1]:
            K -= B.pop()
        else:
            K -= A.pop()
    elif len(A)>0:
        K-=A.pop()
    elif len(B)>0:
        K-=B.pop()
    if(K<0):
        break
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,K = map(int, readline().split())
    A = deque([int(i) for i in readline().split()])
    B = deque([int(i) for i in readline().split()])

    ans = 0
    time = 0
    while time <= K:
        if (not A) and B:
            time += B.popleft()
            ans += 1
        if (not B) and A:
            time += A.popleft()
            ans += 1
        if (not A) and (not B):
            break
        if A and B:
            if A[0] <= B[0]:
                time += A.popleft()
                ans += 1
            else:
                time += B.popleft()
                ans += 1
                
    if time == K:
        print(ans)
    else:
        print(ans - 1)


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()))
a_i=0
b_i=0
ans=0
t=0
while t<=k:
  if a_i==n and b_i==m:
    print(n+m);exit()
  elif a_i==n:    
    t+=B[b_i]
    b_i+=1
  elif b_i==m:
    t+=A[a_i]
    a_i+=1
  else:
    if A[a_i]<=B[b_i]:
      t+=A[a_i]
      a_i+=1
    else:
      t+=B[b_i]
      b_i+=1    
  ans+=1
print(ans-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()))

books = 0

while True:
	if n > 0 and m > 0:
		if A[0] < B[0]:
			if A[0] <= k:
				books += 1
				k -= A.pop(0)
				n -= 1
			else:
				break
		else:
			if B[0] <= k:
				books += 1
				k -= B.pop(0)
				m -= 1
			else:
				break
	elif n > 0:
		if A[0] <= k:
			books += 1
			k -= A.pop(0)
			n -= 1
		else:
			break
	elif m > 0:
		if B[0] <= k:
			books += 1
			k -= B.pop(0)
			m -= 1
		else:
			break
	else:
		break
print(books)

Submission status: Wrong Answer

Solution code:
#ABC172-C
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())))

t=0
cnt =0
while A or B:
    if A and B:
        if A[0]<=B[0]:
            if t+A[0]<=K:
                tmp=A.popleft()
                t +=tmp
                cnt +=1
            else:
                break
        else:
            if t+B[0]<=K:
                tmp=B.popleft()
                t +=tmp
                cnt +=1
            else:
                break
    elif A:
        if t+A[0]<=K:
            tmp=A.popleft()
            t +=tmp
            cnt +=1
        else:
            break
    elif B:
        if t+B[0]<=K:
            tmp=B.popleft()
            t +=tmp
            cnt +=1
        else:
            break
            
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()))

SA = [0]*(N+1)
SB = [0]*(M+1)
T = 0


ans = 0

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

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

for i in range(1, N+1):
    if SA[i] > K:
        break
    id = bisect.bisect_right(SB, K - SA[i]) - 1
    ans = max(ans, i + id)


print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))
for i in range(n):
	a[i+1]+=a[i]
for i in range(m):
	b[i+1]+=b[i]
from bisect import bisect_right
ans=0
for i in range(n+1):
	if k-a[i]>0:
		r=bisect_right(b,k-a[i])
		ans=max(r+i-1,ans)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
n, m, k = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

rui_al = [0] + list(itertools.accumulate(al))
rui_bl = [0] + list(itertools.accumulate(bl))


ans = 0

for i in range(1, n+1):
    sum_a = rui_al[i]
    if sum_a >= k:
        continue
    j = bisect.bisect_right(rui_bl, k-sum_a)
    ans = max(ans, i+j-1)

print(ans)

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

time = 0
A_i = 0
B_i = 0
count = 0

while True:
    min_time = 0
    if (A_i == len(A) and B_i == len(B)):
        break
    elif (A_i == len(A)):
        min_time = B[B_i]
        read_flag = "B"
    elif (B_i == len(B)):
        min_time = A[A_i]
        read_flag = "A"
    elif (A[A_i] < B[B_i]):
        min_time = A[A_i]
        read_flag = "A"
    else:
        min_time = B[B_i]
        read_flag = "B"

    if (time + min_time > K):
        break

    time += min_time
    count += 1

    if (read_flag == "A"):
        A_i += 1
    else:
        B_i += 1

print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(float("INF"))
b.append(float("INF"))
ai = 0
bi = 0
ans = 0
while k > 0:
    if a[ai]==float("INF") and b[bi]==float("INF"):
        break
    if a[ai]<b[bi]:
        k -= a[ai]
        if k<0: break
        ai += 1
        ans += 1
    else:
        k -= b[bi]
        if k<0: break
        bi += 1
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N, M, K = in_nn()
    A = deque(in_nl())
    B = deque(in_nl())

    now = 0
    count = 0
    while True:
        if A and B:
            if A[0] < B[0]:
                now += A.popleft()
            else:
                now += B.popleft()
        elif A:
            now += A.popleft()
        elif B:
            now += B.popleft()

        if now > K:
            break

        count += 1
        if not A and not B:
            break

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    cnt = 0
    inf = 10**18
    for i in range(m+n):
        if n > 0:
            p = a.popleft()
        if m > 0:
            q = b.popleft()
        if p <= q:
            n -= 1
            b.appendleft(q)
            k -= p
        else:
            a.appendleft(p)
            m -= 1
            k -= q
        if k >= 0:
            cnt += 1
        if k <= 0:
            break
        p = inf
        q = inf
    print(cnt)              


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()))
from itertools import accumulate
ar=[0]+list(accumulate(a))
bru=[0]+list(accumulate(b))
from bisect import bisect_left as bl,bisect_right as br
ans=0

for i in range(n+1):
    g=ar[i]
    if g>k:break
    if k-g>=bru[-1]:ans=max(ans,i+m);continue
    j=bl(bru,k-g)
    ans=max(ans,i+j-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    N, M, K = map(int, input().split())
    A = deque(map(int, input().split()))
    B = deque(map(int, input().split()))
    ans = 0
    time = 0
    while time <= K:
        if not A and not B:
            print(ans)
            return
        if not A and B:
            if time + B[0] > K:
                print(ans)
                return
            ans += 1
            time += B[0]
            #print(0, B[0])
            B.popleft()
        elif not B and A:
            if time + A[0] > K:
                print(ans)
                return
            ans += 1
            time += A[0]
            #print(1, A[0])
            A.popleft()
        elif A[0] <= B[0]:
            if time + A[0] > K:
                print(ans)
                return
            ans += 1
            time += A[0]
            #print(2, A[0])
            A.popleft()
        else:
            if time + B[0] > K:
                print(ans)
                return
            ans += 1
            time += B[0]
            #print(3, B[0])
            B.popleft()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n,m,k = na()
    honA = na() + [float('inf')]
    honB = na() + [float('inf')]
    i,j = 0,0
    ans = 0
    while k > 0:
        if honA[i] <= k and honB[j] <= k:
            if honA[i] < honB[j]:
                k -= honA[i]
                i += 1
                ans += 1
            else:
                k -= honB[j]
                j += 1
                ans += 1
        elif honA[i] <= k:
            k -= honA[i]
            i += 1
            ans += 1
        elif honB[j] <= k:
            k -= honB[j]
            j += 1
            ans += 1
        else:
            break
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

acc1 = list(itertools.accumulate(a))
acc2 = list(itertools.accumulate(b))

ans = 0
for i in range(n):
    num = i+1
    temp = acc1[i]
    rest = k-temp

    if rest > 0:
        hoge = bisect.bisect_right(acc2,rest)

        num += hoge

        if num > ans:
            ans = num

print(ans)

Submission status: Wrong Answer

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

from collections import deque

an = deque(map(int, input().split()))

bn = deque(map(int, input().split()))

elapsed = 0
count = 0
max = 10**9+10
while elapsed < k:
    sum = 0

    an_ = an[0] if len(an) > 0 else max
    bn_ = bn[0] if len(bn) > 0 else max

    if an_ > bn_:
        sum = bn.popleft()
    else:
        sum = an.popleft()

    if elapsed + sum > k:
        break

    elapsed += sum
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m,k=MI()
lisa=LI()
lisb=LI()
i=0
j=0
qa=deque(lisa)
qb=deque(lisb)
a=qa.popleft()
b=qb.popleft()
time=0
count=0
while True:
    if a>=b:
        if time+b>k:
            break
        else:
            time+=b
            count+=1
            if qb:
                b=qb.popleft()
            else:
                b=inf
    else:
        if time+a>k:
            break
        else:
            time+=a
            count+=1
            if qa:
                a=qa.popleft()
            else:
                a=inf
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()))

time=0
ans=0
i=0
j=0
for _ in range(N+M):
    if i==N and j==M:
        break
    elif i==N:
        time+=B[j]
        if time<=K:
            ans+=1
        else:
            break
        j+=1
        continue
    elif j==M:
        time+=A[i]
        if time<=K:
            ans+=1
        else:
            break
        i+=1
        continue


    if A[i]<=B[j]:
        time+=A[i]
        if time<=K:
            ans+=1
        else:
            break
        i+=1
    else:
        time+=B[j]
        if time<=K:
            ans+=1
        else:
            break
        j+=1
print(ans)

Submission status: Wrong Answer

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

A.append(10000000000000)
B.append(10000000000000)

time = 0
a_num = 0
b_num = 0
for i in range(N+M):
    if A[a_num] <B[b_num]:
        time += A[a_num]
        a_num+=1
    else:
        time += B[b_num]
        b_num+=1
    
    if time > K:
        break
else:
    print(a_num+b_num)
    sys.exit()
print(a_num+b_num-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()))

nowt=0
nowa=0
nowb=0
ans=0

while True:
    a=float("INF")
    b=float("INF")
    if 0<=nowa<N:
        a=A[nowa]
    if 0<=nowb<M:
        b=B[nowb]

    if nowt+min(a,b)>K:
        break
    if a<=b:
        ans+=1
        nowt+=a
        nowa+=1
    else:
        nowt+=b
        ans+=1
        nowb+=1
    #print(nowt,a,b)
    

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()))
a=deque(a)
b=deque(b)
ans=0
cnt=0
while cnt<k:
    if a and b:
        if a[0]<b[0]:
            if a[0]+cnt<=k:
                cnt+=a.popleft()
                ans+=1
            else:
                break
        else:
            if b[0]+cnt<=k:
                cnt+=b.popleft()
                ans+=1
            else:
                break
    else:
        if a:
            if a[0]+cnt<=k:
                cnt+=a.popleft()
                ans+=1
            else:
                break
        elif b:
            if b[0]+cnt<=k:
                cnt+=b.popleft()
                ans+=1
            else:
                break
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,N):
  A[i] += A[i-1]
for i in range(1,M):
  B[i] += B[i-1]
  
ans = 0
for i in range(N):
  K1 = K - A[i]
  if(K1 >= 0 and K1 < B[0]):
    ans = max(ans, i+1)
  elif(K1 >= 0):
    j = bisect.bisect_right(B, K1)
    ans = max(ans, i+j+1)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,t=map(int,input().split())
arr=[]
brr=[]
for i in range(1):
    arr=list(map(int,input().split()))
    
for i in range(1):
    brr=list(map(int,input().split()))
arr.reverse()
brr.reverse()
ans=0
while(t>0 and (len(arr)+len(brr)>0)):
    if(len(arr)==0):
        if(t>=brr[-1]):
            ans+=1
            t-=brr.pop()
        else:
            break
    elif(len(brr)==0):
        if(t>=arr[-1]):
            ans+=1
            t-=arr.pop()
        else:
            break
    else:
        if(arr[-1]<brr[-1]):
            if(t>=arr[-1]):
                ans+=1
                t-=arr.pop()
            else:
                break
        else:
            if(t>=brr[-1]):
                ans+=1
                t-=brr.pop()
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
a_index = 0
b_index = 0
count = 0

while k > 0:
    a_min = 1e10
    b_min = 1e10
    if a_index < len(a_list):
        a_min = a_list[a_index]
    if b_index < len(b_list):
        b_min = b_list[b_index]

    if a_min == 1e10 and b_min == 1e10:
        breaka
    elif a_min < b_min:
        count += 1
        k -= a_min
        a_index += 1
    else:
        count += 1
        k -= b_min
        b_index += 1

print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = [*map(int, input().split())]
B = [*map(int, input().split())]
A += [10**9] * (200000 - N)
B += [10**9] * (200000 - M)
book_num = 0
n_t = 0

while True:
    if A[0] < B[0]:
        n_t += A[0]
        A.pop(0)
    else:
        n_t += B[0]
        B.pop(0)
    if n_t > K:
        break
    book_num += 1

print(book_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()))
c = a+b
c.sort()
i = 0
ans = 0
count = 0
if sum(c) == k:
    print(n+m)
    exit()
while True:
    ans += c[i]
    i += 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 = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
cnt = 0
while K >= 0:
    if A:
        a = A.popleft()
    else:
        a = 10**16
    if B:
        b = B.popleft()
    else:
        b = 10**16
    if a <= b:
        i = a
        B.appendleft(b)
    else:
        i = b
        A.appendleft(a)
    K -= i
    if K >= 0:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

aidx = 0
bidx = 0
time = 0
judge = True

while time <= K and judge:
    judge = False
    if aidx < N and bidx < M:
        if A[aidx] < B[bidx]:
            time += A[aidx]
            aidx += 1
        else:
            time += B[bidx]
            bidx += 1
        judge = True
    else:
        if aidx < N:
            time += A[aidx]
            aidx += 1
            judge = True
        elif bidx < M:
            time += B[bidx]
            bidx += 1
            judge = True

if aidx == N and bidx == M:
    print(aidx + bidx)
else:
    print(aidx + bidx - 1)

Submission status: Wrong Answer

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

C = A + B
C.sort()
cntTime = 0 
result = 0
for i in range(len(C)):
    cntTime += C[i]
    if cntTime <= K:
        result += 1
    else:
        break
print(result)

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
t = 0
ai = 0
bi = 0
while t <= K:
    if count == N + M:
        break

    readA = True
    if ai != N and bi != M:
        if A[ai] > B[bi]:
            readA = False

    if ai == N:
        readA = False

    if bi == M:
        readA = True

    if readA:
        t += A[ai]
        ai += 1
    else:
        t += B[bi]
        bi += 1

    if t <= K:
        count += 1

print(count)