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:
from collections import deque
n,m,k=map(int,input().split())
a=deque(list(map(int,input().split())))
b=deque(list(map(int,input().split())))

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

Submission status: Wrong Answer

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

sumz = 0
count = 0
idA = 0
idB = 0
endz = 0
while sumz <= K and idA < N and idB < M:
    if bookA[idA] < bookB[idB]:
        if sumz + bookA[idA] <= K:
            sumz += bookA[idA]
            idA += 1
            count += 1
        else: endz = 1
    else:
        if sumz + bookB[idB] <= K:
            sumz += bookB[idB]
            idB += 1
            count += 1
        else: endz = 1
    if endz: break

if idA < N and sumz <= K:
    while idA < N and sumz + bookA[idA] <= K:
        sumz += bookA[idA]
        idA += 1
        count += 1

if idB < M and sumz <= K:
    while idB < M and sumz + bookB[idB] <= K:
        sumz += bookB[idB]
        idB += 1
        count += 1

print(count)

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()))
RA=[0]*(n+1)
RB=[0]*(m+1)
for i in range(n):
    RA[i+1]=RA[i]+A[i]
for i in range(m):
    RB[i+1]=RB[i]+B[i]
#print(RA)
#print(RB)

r=0
for i in range(n+1):
    a=RA[i]
    if k-a>0:
        j=bisect.bisect_right(RB,k-a)
        r=max(r,i+j-1)
        #print(i,k-a,j)
print(r)

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()))
num = 0
while 1:
  if len(A) == 0 and len(B) != 0 and B[0] <= K:
    num += 1
    K -= B[0]
    B = B[1:]
  elif len(B) == 0 and len(A) != 0 and A[0] <= K:
    num += 1
    K -= A[0]
    A = A[1:]
  elif len(A) == 0 and len(B) == 0:
    break
  elif A[0] > K and B[0] > K:
    break
    
  elif A[0] <= B[0] and K >= A[0]:
    num += 1
    K -= A[0]
    A = A[1:]
  elif B[0] < A[0] and K >= B[0]:
    num += 1
    K -= B[0]
    B = B[1:]
  elif A[0] > K and B[0] <= K:
    num += 1
    K -= B[0]
    B = B[1:]
  elif B[0] > K and A[0] <= K:
    num += 1
    K -= A[0]
    A = A[1:]
      
     
    
print(num)

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 len(A)==0:
    A.append(9999999999999999999999999999999999)
  if len(B)==0:
    B.append(9999999999999999999999999999999999)
    
  if A[0]<=B[0] and A[0]<=k:
    k=k-A.popleft()
    cnt+=1
  elif A[0]>=B[0] and B[0]<=k:
    k=k-B.popleft()
    cnt+=1
  else:
    break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

n,m,k = map(int,input().split())
a = list(map(int,input().split())) + [float('inf')]
b = list(map(int,input().split())) + [float('inf')]
aind = 0
bind = 0
ans = 0
while True:
    if min(a[aind],b[bind]) > k:
        print(ans)
        break
    else:
        if a[aind] == float('inf') and b[bind] == float('inf'):
            print(ans)
            break
        if a[aind] <= b[bind]:
            ans += 1
            k -= a[aind]
            if aind < n:
                aind += 1


        else:
            ans += 1
            k -= b[bind]
            if bind < m:
                bind += 1

Submission status: Wrong Answer

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

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

remain = K
count = 0
i = 0
j = 0
while True:
  if i > N - 1 and j > M - 1:
    break
  elif j > M - 1:
    next_book = A[i]
    i += 1
  elif i > N - 1:
    next_book = B[j]
    j += 1
  elif A[i] <= B[j]:
    next_book = A[i]
    i += 1
  else:
    next_book = B[j]
    j += 1
  remain -= next_book 
  if remain >= 0:
    count += 1

print(count)

Submission status: Wrong Answer

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

time = 0
ans = 0
flag = True
while True:
  tar = min(a[0], b[0])
  if (tar == a[0]):
    del a[0]
  else:
    del b[0]

  time += tar
  ans += 1
  if (time > k):
    ans -= 1
    break

  if (len(a) == 0):
    flag = False
    lis = b
    break
  if (len(b) == 0):
    flag = False
    lis = a
    break

if (flag is False):
  while time < k:
    time += lis[0]
    ans += 1
    if (time > k):
      time -= lis[0]
      ans -= 1
      break
    
    del lis[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()))

tmp = 0
ans = 0
idx = 0
for i in range(N):
    if tmp + A[i] > K:
        break
    tmp += A[i]
    ans += 1
    idx += 1

idx -= 1
max_ans = ans

for i in range(M):
    if tmp + B[i] <= K:
        ans += 1
        max_ans = max(ans, max_ans)
        tmp += B[i]
        continue
    else:
        if idx >= 0:
            tmp -= A[idx]
            ans -= 1
            idx -= 1
        if tmp + B[i] <= K:
            ans += 1
            tmp += B[i]
            max_ans = max(ans, max_ans)
        else:
            break

print(max_ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=[int(i) for i in input().split()]+[10**9]
B=[int(i) for i in input().split()]+[10**9]
a=b=ans=0
for _ in range(n+m):
    if A[a]<B[b]:
        k-=A[a]
        a+=1
    else:
        k-=B[b]
        b+=1
    if k<0:
        print(ans)
        exit()
    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()]

total = 0
cnt = 0
while True:
    if A and B:
        A_top = A[0]
        B_top = B[0]
        if A_top > B_top:
            if total + B_top <= K:
                total += B_top
                cnt += 1
                B = B[1:]
            else:
                break
        else:
            if total + A_top <= K:
                total += A_top
                cnt += 1
                A = A[1:]
            else:
                break

    elif A:
        if total + A[0] <= K:
            total += A[0]
            cnt += 1
            A = A[1:]
        else:
            break

    elif B:
        if total + B[0] <= K:
            total += B[0]
            cnt += 1
            B = B[1:]
        else:
            break

    else:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
for i in range(N+M):
    if len(A)==0:
        A.append(1000000001)
    if len(B)==0:
        B.append(1000000001)
    if A[0]>B[0]:
        pop=B.pop(0)
        K-=pop
    else:
        pop=A.pop(0)
        K-=pop
    if K==0:
        count=i+1
        break
    if K<0:
        K+=pop
        count=i
        break
print(count)

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

A = np.array(A)
B = np.array(B)

A_sum = np.array( list(map(lambda i: np.sum(A[:i+1]), range(N))) )
B_sum = np.array( list(map(lambda i: np.sum(B[:i+1]), range(M))) )

a_read = len( A_sum[np.where(A_sum < K)])
b_read = 0
ans =0

while a_read>=0:
    K_B = K - A_sum[a_read-1]
    b_read = len( B_sum[np.where(B_sum <= K_B)])
    if ans < a_read+b_read:
        ans = a_read + b_read
    a_read -= 1

print(ans)

Submission status: Wrong Answer

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

c=a+b
c=sorted(c)

ans=0

for i in c:
    if i <= K:
        ans += 1
        K -= i

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import os
import operator
from collections import defaultdict
import sys
from io import BytesIO, IOBase
import bisect

# def power(x, p):
#     res = 1
#     while p:
#         if p & 1:
#             res = res * x % 1000000007
#         x = x * x % 1000000007
#         p >>= 1
#     return res;

def main():
    # for _ in range(int(input())):
    #     n=int(input())
    #     n,k=map(int,input().split())
    #     arr=[int(k) for k in input().split()]
    #n=int(input())
    # n,k=map(int,input().split())
    # arr=[int(k) for k in input().split()]
    n,m,k=map(int,input().split())
    arr1=[int(el)for el in input().split()]
    arr2 = [int(el) for el in input().split()]
    stack1=[]
    stack2=[]
    for i in range(n-1,-1,-1):
        stack1.append(arr1[i])
    for i in range(m-1,-1,-1):
        stack2.append(arr2[i])
    count=0
    while True:
        if stack1 and stack2:
            el1=stack1.pop()
            el2=stack2.pop()
            if el1<el2:
                if el1<=k:
                    k-=el1
                    count+=1
                    stack2.append(el2)
                else:
                    break
            else:
                if el2<=k:
                    k-=el2
                    count+=1
                    stack1.append(el1)
                else:
                    break
        elif len(stack1)==0 and len(stack2)>0:
            el2=stack2.pop()
            if el2<=k:
                k-=el2
                count+=1
            else:
                break
        elif len(stack2)==0 and len(stack1)>0:
            el1=stack1.pop()
            if el1<=k:
                k-=el1
                count+=1
            else:
                break
        else:
            break
    print(count)































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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
N, M , lim = mi()

A = li()
B = li()

A += [10**9+1]
B += [10**9+1]
ind_a = 0 
ind_b = 0

cnt = ans = 0

while True:
    if A[ind_a] > B[ind_b]:
        if cnt + B[ind_b] <= lim:
            ans += 1
            cnt += B[ind_b]
            if ind_b != M:
                ind_b += 1
        else:
            break

    elif A[ind_a] < B[ind_b]:
        if cnt + A[ind_a] <= lim:
            ans += 1
            cnt += A[ind_a]
            if ind_a != N:
                ind_a += 1
        else:
            break

    else:
        if ind_a == N and ind_b == M:
            break
        elif ind_a == N:
            if cnt + B[ind_b] <= lim:
                ans += 1
                cnt += B[ind_b]
                if ind_b != M:
                    ind_b += 1
            else:
                break
        elif ind_b == M:
            if cnt + A[ind_a] <= lim:
                ans += 1
                cnt += A[ind_a]
                if ind_a != N:
                    ind_a += 1
            else:
                break
        else:
            if A[ind_a+1] >= B[ind_b+1]:
                if cnt + B[ind_b] <= lim:
                    ans += 1
                    cnt += B[ind_b]
                    if ind_b != M:
                        ind_b += 1
                else:
                    break
            else:
                if cnt + A[ind_a] <= lim:
                    ans += 1
                    cnt += A[ind_a]
                    if ind_a != N:
                        ind_a += 1
                else:
                    break

print(ans)

Submission status: Wrong Answer

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

i = j = 0
books = 0
while i < n or j < m:
	if i < n and j < m:
		if a[i] <= b[j]:
			if a[i] <= k:
				k -= a[i]
				i += 1
				books += 1
			else:
				i += 1
		else:
			if b[j] <= k:
				k -= b[j]
				j += 1
				books += 1
			else:
				j += 1
	elif i < n:
		if a[i] <= k:
			k -= a[i]
			i += 1
			books += 1
		else:
			i += 1
	elif j < m:
		if b[j] <= k:
			k -= b[j]
			j += 1
			books += 1
		else:
			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()))

p_time = 0
time = 0
while time < k:
    if len(a) > 0 and len(b) > 0:
        if a[0] >= b[0]:
            time += a[0]
            a.remove(a[0])
        else:
            time += b[0]
            b.remove(b[0])
    elif len(a) <= 0 and len(b) <= 0:
        break
    elif len(a) <= 0 < len(b):
        time += b[0]
        b.remove(b[0])
    elif len(b) <= 0 < len(a):
        time += a[0]
        a.remove(a[0])
    if time <= k:
        p_time += 1

print(p_time)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

cnt = 0
time = 0
a = A.popleft()
b = B.popleft()

while time < K:
    if a < b:
        time += a
        try:
            a = A.popleft()
        except:
            a = 10**9 + 1
    else:
        time += b
        try:
            b = B.popleft()
        except:
            b = 10**9 + 1
    if time >= K:
        break

    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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
for i in range(n+m):
    if A[A_i] <= B[B_i]:
        ans += A[A_i]
        if ans > k:
            ans -= A[A_i]
            print(count)
            exit()
        count += 1
        A_i += 1
    else:
        ans += B[B_i]
        if ans > k:
            ans -= B[B_i]
            print(count)
            exit()
        count += 1
        B_i += 1
    if A_i == n or B_i == m:
        break
if A_i == n:
    for i in range(m-B_i):
        ans += B[B_i]
        if ans > k:
            ans -= B[B_i]
            print(count)
            exit()
        count += 1
        B_i += 1
elif B_i == m:
    for i in range(n-A_i):
        ans += A[A_i]
        if ans > k:
            ans -= A[A_i]
            print(count)
            exit()
        count += 1
        A_i += 1
print(n+m)

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

a_c = 0
b_c = 0
while K>0:
    if len(A) > a_c and len(B) > b_c:
        if A[a_c] < B[b_c]:
            K = K-A[a_c]
            a_c+=1
        else:
            K = K-B[b_c]
            b_c+=1
    elif len(A) <= a_c and len(B) > b_c:
        K = K-B[b_c]
        b_c+=1
    elif len(A) > a_c and len(B) <= b_c:
        K = K-A[a_c]
        a_c+=1
    
if K>=0:
    print(a_c + b_c)
else:
    print(a_c + b_c - 1)

Submission status: Wrong Answer

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

time = 0
count = 0
i = 0
j = 0
frag_i = 1
frag_j = 1
frag = 1
while (time <= K):
  if frag_j and frag_i:
    if A[i] >= B[j]:
      time +=B[j]
      count += 1
      j +=1
      if j >= M:
        frag_j = 0 
    else:
      time+=A[i]
      count +=1
      i +=1
      if i >= N:
        frag_i = 0
  elif frag_i and (not frag_j):
    time+=A[i]
    count +=1
    i +=1
    if i >= N:
      frag_i = 0
  elif frag_j and (not frag_i):
    time+=B[j]
    count +=1
    j +=1
    if j >= M:
      frag_j = 0 
  else:
    frag = 0
    break
if frag:
    print(count-1)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

ans = 0
time = 0
A_i = 0
B_i = 0

while time < K:
    # 一方が尽きた場合
    if A_i == N:
        time += B[B_i]
        B_i += 1
        ans += 1
        continue
    if B_i == M:
        time += A[A_i]
        A_i += 1
        ans += 1
        continue

    if A[A_i] < B[B_i]:
        time += A[A_i]
        A_i += 1
        ans += 1
        continue
    elif A[A_i] > B[B_i]:
        time += B[B_i]
        B_i += 1
        ans += 1
        continue
    elif A[A_i] == B[B_i]:
        new_A_i = A_i + 1
        new_B_i = B_i + 1
        while True:
            # 一方が尽きた場合
            if new_A_i == N:
                time += B[B_i]
                B_i += 1
                ans += 1
                break
            if new_B_i == M:
                time += A[A_i]
                A_i += 1
                ans += 1
                break

            if A[new_A_i] < B[new_B_i]:
                time += A[A_i]
                A_i += 1
                ans += 1
                break
            elif A[new_A_i] > B[new_B_i]:
                time += B[B_i]
                B_i += 1
                ans += 1
                break
            new_A_i += 1
            new_B_i += 1

# 超過してる
if time != K:
    ans = ans - 1
print(ans)

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 sumA + A[ai] > K and sumA + B[bi] > K:
            break
        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
    if ai < N:
        for i in range(ai, N):
            if sumA + A[i] <= K:
                sumA += A[i]
                ai += 1
            else:
                break
    if 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 = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
i = 0
j = 0
while i <= n and j <= m and time <= k:
    if i == n:
        if j == m:
            break
        time += b[j]
        j += 1
        continue
    if j == m:
        time += a[i]
        i += 1
        continue
    if a[i] < b[j]:
        time += a[i]
        i += 1
        continue
    else:
        time += b[j]
        j += 1
        continue
if time > k:
    print(i+j-1)
else:
    print(i+j)

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a = deque(map(int, input().split()))
    b = deque(map(int, input().split()))
    r = 0
    time = 0
    while a or b:
        if a and b:
            if a[0] < b[0]:
                time += a.popleft()
                if time > k:
                    break
                else:
                    r += 1
            else:
                time += b.popleft()
                if time > k:
                    break
                else:
                    r += 1
        elif a:
            time += a.popleft()
            if time > k:
                break
            else:
                r += 1
        else:
            time += b.popleft()
            if time > k:
                break
            else:
                r += 1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

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

print(count)

Submission status: Wrong Answer

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

max = N
if N < M:
  max = M
sum = 0

for i in range(max):
  k = 0
  if len(a) > 0:
    k = a[0]
  if len(b) > 0 and k > b[0]:
    k = b[0]
  
  if KK - k > 0:
    sum += 1
    KK -= k
print(sum)

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

akari = [0]*(n+1)
bkari = [0]*(m+1)
for i in range(n):
	akari[i+1] = akari[i] + a[i]

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

def bin(ls,s,e,sikii):
	if e - s <= 1:
		return s
	mid = (s+e)//2
	if sikii < ls[mid]:return bin(ls,s,mid,sikii)
	else:return bin(ls,mid,e,sikii)

ans = 0
for i in range(n):
	time = akari[i+1]
	if k - time <= 0:break
	ref = bin(bkari,0,m+1,k-time)
	ans = max(ans,ref+i+1)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
total,count=0,-1
A_index,B_index=0,0
while total<=K:
    if A_index==N and B_index==M:
        count+=1
        break
    elif A_index==N:
        total+=B[B_index]
        B_index+=1
        count+=1
    elif B_index==M:
        total+=A[A_index]
        A_index+=1
        count+=1
    elif A[A_index]<B[B_index]:
        total+=A[A_index]
        A_index+=1
        count+=1
    else:
        total+=B[B_index]
        B_index+=1
        count+=1
print(count)

Submission status: Wrong Answer

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

def Main(N, M, K, A, B):
    i = j = 0
    ans = 0
    read = 0
    while read <= K:
        if i < N and j < M:
            if A[i] <= B[j]:
                read += A[i]
                i += 1
            else:
                read += B[j]
                j += 1
            ans += 1
        elif i < N and j == M:
            read += A[i]
            i += 1
            ans += 1
        elif j < M and i == N:
            read += B[j]
            j += 1
            ans += 1
        else:
            break
    if read > ans:
        return ans-1
    else:
        return ans
            
        
                    
out = Main(N, M, K, A, B)
print(out)

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()))
cnt = 0
T = 0
maxi=N
cnt = N
for i in range(N):
    T += A[i]
    if T>K:
        maxi = i
        cnt = i
        T = T-A[i]
        break

out = cnt
Life=K-T
Bt = 0
while (Bt<=M-1) and (maxi>=0):
    Bcnt=0
    if Life-B[Bt]>=0:
        Life += -1*B[Bt]
        Bt += 1
        Bcnt+=1
    else:
        Life += -1*A[maxi-1]
        maxi += -1
        Bcnt += -1
    cnt = cnt+Bcnt
    out = max(out,cnt)
print(out)

Submission status: Wrong Answer

Solution code:
def m():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    while K >= 0:
        if len(A) == 0 and len(B) == 0:
            return ans
        if len(A) == 0:
            for b in B:
                K -= b
                if K >= 0:
                    ans += 1
                else:
                    return ans
            return ans
        if len(B) == 0:
            for a in A:
                K -= a
                if K >= 0:
                    ans += 1
                else:
                    return ans
            return ans

        if A[0] < B[0]:
            tmp = A.pop(0)
        else:
            tmp = B.pop(0)
        K -= tmp
        if K >= 0:
            ans += 1
        else:
            return ans


print(m())

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

total = 0
res = 0
i_a = 0
i_b = 0
while total < k:
  if i_a >= n and i_b >= m:
    break
  if i_a >= n:
    total += b[i_b]
    i_b +=1
  elif i_b >= m:
    total += a[i_a]
    i_a += 1
  else:
    if a[i_a] < b[i_b]:
      total += a[i_a]
      i_a += 1
    else:
      total += b[i_b]
      i_b += 1
  if total <= k:
    res += 1
print(res)

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

c,summ=0,0
while(summ<=k):
    if(len(l1)>=1 and len(l2)>=1):
        if(l1[0]>l2[0]):
            summ+=l2[0]
            c+=1
            l2.pop(0)
        else:
            summ+=l1[0]
            c+=1
            l1.pop(0)
    elif(len(l1)>=1):
        summ+=l1[0]
        c+=1
        l1.pop(0)
    elif(len(l2)>=1):
        summ+=l2[0]
        c+=1
        l2.pop(0)
    else:
        break
if(summ==k):    
    print(c)
else:
    print(c-1)

Submission status: Wrong Answer

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

cnt = 0

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