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:
A,B,time = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
while time > 0:
    if len(a) > 0 and len(b) > 0:  
        if time >= a[0] and time >= b[0]:
            if a[0] <= b[0]:
                time -= a[0]
                a.pop()
                ans += 1
            else:
                time -= b[0]
                b.pop()
                ans += 1
        elif time >= a[0]:
            time -= a[0]
            a.pop()
            ans += 1
        elif time >= b[0]:
            time -= b[0]
            b.pop()
            ans += 1
        else:
            break
    elif len(a) == 0 and len(b) > 0:
        if time >= b[0]:
            time -= b[0]
            b.pop()
            ans += 1
        else:
            print(ans)
            exit()
    elif len(a) > 0 and len(b) == 0:
        if time >= a[0]:
            time -= a[0]
            a.pop()
            ans += 1
        else:
            print(ans)
            exit()
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n,m,k = map(int, raw_input().split(' '))
ais = collections.deque(map(int,raw_input().split(' ')))
bis = collections.deque(map(int,raw_input().split(' ')))

mem = {}
quantity = 0
while(ais and bis):
	m = min(ais[0], bis[0])
	if m <= k:
		if m == ais[0]:
			ais.popleft()
			quantity += 1
			k-=m
		elif m == bis[0]:
			bis.popleft()
			quantity += 1
			k-=m
	else:
		break

while(bis):
	m = bis[0]
	if m <= k:
		bis.popleft()
		quantity += 1
		k-=m
	else:
		break
while(ais):
	m = ais[0]
	if m <= k:
		ais.popleft()
		quantity += 1
		k-=m
	else:
		break

print quantity

Submission status: Wrong Answer

Solution code:
n, m, k =map(int, input().split())
a = [int(x) for x  in input().split()]
b = [int(x) for x in input().split()]
i,j=0,0
cnt = 0
while k>=0 and i<n and j<m:
    if a[i]<b[j]:
        if k>=a[i]:
            k-=a[i]
            #print(k, a[i])
            i+=1
            cnt +=1

        else:
            break
    else:
        if k>=b[j]:
            k-=b[j]
            #rint(k, b[j])
            cnt +=1
            j+=1
        else:
            break

while k>=0 and i<n:
    if k >= a[i]:
        k -= a[i]
        #print(k, a[i])
        cnt += 1
    else:
        break

while k>=0 and j<m:
    if k >= b[j]:
        k -= b[j]
        #print(k, b[j])
        cnt += 1
        j += 1
    else:
        #print(k,b[j])
        break
print(cnt)

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

C = A + B
C.sort()

book = 0
ans = 0
for c in C:
    book += c
    if book <= K:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))
ans=bisect.bisect_right(B,k)
for i in range(len(a)):
    r = (k-A[i])
    if r<=0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(B,r))
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right


N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


B_time = []
time = 0
for B in B_list:
	time += B
	B_time.append(time)

i = bisect_right(B_time, K)
if i > 0:
	count = i
else:
	count = 0

time = 0
for i, A in enumerate(A_list):
	time += A
	j = bisect_right(B_time, K - time)
	if j > 0:
		c = i + 1 + j
		if c > count:
			count = c
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(10**10)
B.append(10**10)

cnt_a = 0
cnt_b = 0
time = 0
ans = 0

while time <= k:
    if A[cnt_a] < B[cnt_b] and time+A[cnt_a]<=k:
        time += A[cnt_a]
        cnt_a += 1
        ans += 1
    elif A[cnt_a] >= B[cnt_b] and time+B[cnt_b]<=k:
        time += B[cnt_b]
        cnt_b += 1
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
anum, bnum, time= map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

cost = 0
count = 0
while(True):
    if count == anum + bnum:
        print(count)
        break
    else:
        if len(a) == 0:
            cost += b[0]
            b = b[1:]
            count += 1
        elif len(b) == 0:
            cost += a[0]
            a = a[1:]
            count += 1
        else:
            if a[0] <= b[0]:
                cost += a[0]
                a = a[1:]
                count += 1
            else:
                cost += b[0]
                b = b[1:]
                count += 1
    if cost > time:
        print(count - 1)
        break

Submission status: Wrong Answer

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

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

    cnt = 0
    now = 0
    while now <= k:
        if a[ap] <= b[bp]:
            now += a[ap]
            ap += 1
        else:
            now += b[bp]
            bp += 1
        if now <= k:
            cnt +=1
        if ap + bp == len(a) + len(b) - 2:
            break
    print(cnt)

main()

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.reverse()
b.reverse()
ans = 0
time = 0
while time <= k:
    if a and b:
        if a[-1] <= b[-1]:
            time += a[-1]
            ans += 1
            a.pop()
        else:
            time += b[-1]
            ans += 1
            b.pop()
    else:
        if a:
            time += a[-1]
            ans += 1
            a.pop()
        elif b:
            time += b[-1]
            ans += 1
            b.pop()
        else:
            break
if time > k:
    ans -= 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()))
a.reverse()
b.reverse()
a.insert(0, 999999999999)
b.insert(0, 999999999999)

p1 = n
p2 = m
tmp = 0
ans = 0

while 1:
    mn = min(a[p1], b[p2])
    if tmp + mn > k: break
    tmp += mn
    ans -= -1
    if a[p1] < b[p2]: p1 += -1
    else: p2 += -1
    if p1 == 0 and p2 == 0: break
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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(1,N+1,1):
    A[i]=A[i-1]+A[i]
for i in range(1,M+1,1):
    B[i]=B[i-1]+B[i]

ans = 0
for i in range(0,N+1,1):
    j = bisect_right(B,K-A[i])-1
    if K-A[i]>0:
        ans = max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(10**10)
B.append(10**10)
time = 0
read = 0
a_read = 0
b_read = 0
while time < K:
    if A[a_read] <= B[b_read]:
        #print(A[a_read])
        if time + A[a_read] > K:
            break
        time += A[a_read]
        a_read += 1

    else:
        #print(B[b_read])
        if time + B[b_read] > K:
            break
        time += B[b_read]
        b_read += 1
    read += 1
print(read)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M, K = MAP()
    A = LIST()
    B = LIST()

    qa = deque(A)
    qb = deque(B)
    qa.append(INF)
    qb.append(INF)

    times = 0
    cnt = 0
    while times < K:
        if qa[0] < qb[0]:
            times += qa.popleft()
        else:
            times += qb.popleft()

        if times > K: break
        cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
import bisect

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


#Cum_A = []
Cum_B = []
yoryoku = []



na = K
for i in range(len(A)):
    na -= A[i]
    yoryoku.append(na)
    #Cum_A.append(na)

nb = 0
for j in range(len(B)):
    nb += B[j]
    Cum_B.append(nb)

#print(Cum_A)
#print(yoryoku)
#print(Cum_B)
    


ans = 0
for i in range(len(A)):
    r = yoryoku[i]
    if(r < 0):
        break
    #print(i + 1 + bisect.bisect_right(Cum_B, r))
    ans = max(ans , i+1+bisect.bisect_right(Cum_B, r))
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = [int(i) for i in input().split()][::-1]
b = [int(i) for i in input().split()][::-1]
ans = 0
cnt = 0
while True:
    if a and b:
        if a[-1] < b[-1]: nxt = a.pop()
        else: nxt = b.pop()
    elif a: nxt = a.pop()
    elif b: nxt = b.pop()
    else: break
    if cnt + nxt > k: break
    else:
        cnt += nxt
        ans += 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()))
n, m = map(len, (A, B))
cur = 0
res = 0
i = j = 0
while i < n and j < m and cur <= K:
    if A[i] < B[j]:
        if cur + A[i] <= K:
            res += 1
            cur += A[i]
            i += 1
        else:
            break
    else:
        if cur + B[j] <= K:
            res += 1
            cur += B[j]
            j += 1
        else:
            break
while i < n and cur <= K:
    if cur + A[i] <= K:
        res += 1
        cur += A[i]
        i += 1
    else:
        break
while j < m and cur <= K:
    if cur + B[j] <= K:
        res += 1
        cur += B[j]
        j += 1
    else:
        break
print(res)

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

dq_A = deque(A)
dq_B = deque(B)

cnt = 0
while K > 0:
    if len(dq_A) > 0 and len(dq_B) > 0:    
        if dq_A[0] > dq_B[0]:
            tmp = dq_B.popleft()
            K -= tmp
            cnt += 1
        else:
            tmp = dq_A.popleft()
            K -= tmp
            cnt += 1
    elif len(dq_A) > 0:
        tmp = dq_A.popleft()
        K -= tmp
        cnt += 1
    elif len(dq_B) > 0:
        tmp = dq_B.popleft()
        K -= tmp
        cnt += 1

if K == 0:
    print(cnt)
else:
    if cnt > 0:
        print(cnt-1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import queue
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
a = 0
b = 0
time = 0
while(time < K):
    m = 0
    if a < N and b < M:
        if A[a] < B[b]:
            m = A[a]
            a += 1
        else:
            m = B[b]
            b += 1
    elif a < N and b == M:
        m = A[a]
        a += 1
    elif a == N and b < M:
        m = B[b]
        b += 1
    else:
        break

    time += m
    # print(time, K)
    if time <= K:
        ans += 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 = 0
cur = 0
len_A = len(A)
len_B = len(B)
i = 0
j = 0
while True:
  a_i = A[i] if i < len_A else 1e10
  b_j = B[j] if j < len_B else 1e10
  if a_i < b_j:
    cur += a_i
    i += 1
  else:
    cur += b_j
    j += 1
  if cur > K:
    break
  total += 1
  
print(total)

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

ans = 0
cnt = 0
while cnt < k:
    if a and b:
        at = a.popleft()
        bt = b.popleft()
        if at < bt:
            cnt += at
            b.appendleft(bt)
        else:
            cnt += bt
            a.appendleft(at)
    elif a:
        at = a.popleft()
        cnt += at
    elif b:
        bt = b.popleft()
        cnt += bt
    ans += 1
if cnt > k:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

As.append(np.inf)
Bs.append(np.inf)

count = 0
a_ind = 0
b_ind = 0
a = As[a_ind]
b = Bs[b_ind]
while K >= min(a, b) and K > 0:
    if a <= b:
        K -= a
        a_ind += 1
        a = As[a_ind]
    else:
        K -= b
        b_ind += 1
        b = Bs[b_ind]
    count += 1

print(count)

Submission status: Wrong Answer

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

for i in range(len(B)):
    A.append(B[i])

A.sort
goukei=0
if(K<A[0]):
    print(0)
    exit()
for i in range(len(A)):
    goukei=goukei+A[i]
    if(K<goukei):
        print(i+1)
        exit()


print(N+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()))

i, j = 0, 0
time, books = 0, 0
while True:
    if i < n and j < m:
        if a[i] > b[j]:
            if k - time >= b[j]:
                time += b[j]
                books += 1
                j += 1
            else:
                break
        elif a[i] < b[j]:
            if k - time >= a[i]:
                time += a[i]
                books += 1
                i += 1
            else:
                break
        else:
            if k - time >= 2 * a[i]:
                time += a[i]
                time += b[j]
                books += 2
                i += 1
                j += 1
            elif k - time >= a[i] and k - time < 2 * a[i]:
                time += a[i]
                books += 1
                i += 1
            else:
                break

    elif i < n and j >= m:
        if k - time >= a[i]:
            time += a[i]
            books += 1
            i += 1
        else:
            break

    elif i >= n and j < m:
        if k - time >= b[j]:
            time += b[j]
            books += 1
            j += 1
        else:
            break
    
    else:
        break
    
    if time >= k:
        break

print(books)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
x=[int(x) for x in input().split()]
y=[int(x) for x in input().split()]
c=0
cost=0

for i in range(n):
    if i<n and cost<k and cost+x[i]<=k and i<n:
        cost+=x[i]
        c+=1
    if i<m and  cost<k and cost+y[i]<=k :
        cost+=y[i]
        c+=1

if m>n:
    while(i<(m)):
        if cost+y[i]<=k and cost<k:
            cost+=y[i]
            c+=1
        i+=1
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
ans = 0
time = 0

while time <= K and (len(A) > 0 or len(B) > 0):
    if len(A) == 0:
        time += B.popleft()
    elif len(B) == 0:
        time += A.popleft()
    elif A[0] < B[0]:
        time += A.popleft()
    else:
        time += B.popleft()
    ans += 1
if (len(A) > 0 or len(B) > 0):
    ans -= 1
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
SUM=0
while SUM<=k:
    if len(A)>0 and len(B)>0:
        if A[0]>=B[0]:
            x=B.popleft()
        else:
            x=A.popleft()
        if SUM+x<=k:
            SUM+=x
            ans+=1
        else:
            break
    elif len(A)==0 and len(B)>0:
        x=B.popleft()
        if SUM+x<=k:
            SUM+=x
            ans+=1
        else:
            break
    elif len(A)>0 and len(B)==0:
        x=A.popleft()
        if SUM+x<=k:
            SUM+=x
            ans+=1
        else:
            break
    else:
        break

    #print(A,B,ans,SUM)
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()))
asu=[]
s=0
for i in a:
  s+=i
  asu.append(s)
bsu=[]
s=0
for i in b:
  s+=i
  bsu.append(s)
  
ac=n-1
bc=0
maxc=0

while (bc!=m)and(ac>=0):
  while (bc!=m) and (asu[ac]+bsu[bc]<=k):
    bc+=1
  if asu[ac]+bsu[bc-1]<=k:
    maxc=max(maxc,ac+bc+1)
  ac-=1
print(maxc)

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *                    # ll = deepcopy(l)
from heapq import *                    # heappush(hp,x)
from string import *                # alpha = ascii_lowercase
from random import *                # l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *                # bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin                # bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize                # minn = -maxsize
from operator import *                # d = sorted(d.items(), key=itemgetter(1))
from itertools import *                # pre = [0] + list(accumulate(l))
from decimal import Decimal         # a = Decimal(a)    # use this for math questions
from collections import Counter        # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
3 4 240
60 90 120
80 150 80 150
'''

def solve(n,m,k,a,b):
	i,j = 0,0
	ans = 0
	tot = 0
	while(tot < k and i < n and j < m):
		if(a[i] <= b[j] and tot + a[i] <= k):
			ans += 1
			tot += a[i]
			i += 1
		elif(a[i] > b[j] and tot + b[j] <= k):
			ans += 1
			tot += b[j]
			j += 1
		else:
			break
	while(i < n and tot < k):
		if(a[i] + tot <= k):
			tot += a[i]
			ans += 1
			i += 1
		else:
			break
	while(j < m and tot < k):
		if(b[j] + tot <= k):
			tot += b[j]
			ans += 1
			j += 1
		else:
			break
	# print(tot)
	return ans

	

N,M,K = list(map(int, stdin.readline().rstrip().split()))
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
ans = solve(N,M,K,a,b)
print(ans)

Submission status: Wrong Answer

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

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
        if tmp + B[i] <= K:
            ans += 1
            tmp += B[i]
            max_ans = max(ans, max_ans)

print(max_ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m, k = map(int, input().split())
a = np.array([0] + list(map(int, input().split())))
b = np.array([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]

ans = 0

for i in range(n+1):
    l = 0
    r = m + 1
    while r- l > 1:
        mid = (l + r) // 2
        if b[mid] + a[i] <= k:
            l = mid
        else:
            r = mid

    ans = max(ans, i + l)

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)

atop = a.popleft()
btop = b.popleft()
time = 0
ans = 0

while time <= k:
    ans += 1
    if atop <= btop:
        time += atop
        if a:
            atop = a.popleft()
        else:
            atop = float('inf')
    else:
        time += btop
        if b:
            btop = b.popleft()
        else:
            btop = float('inf')
    if atop == float('inf') and btop == float('inf'):
        print(ans)
        exit()
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 = 0
b = 0
ans = 0
for _ in range(N+M):
    if a == N:
        if K >= B[b]:
            K -= B[b]
            ans += 1
            b += 1
        else:
            break
    elif b == M:
        if K >= A[a]:
            K -= A[a]
            ans += 1
            a += 1
        else:
            break
    elif A[a] < B[b]:
        if K >= A[a]:
            K -= A[a]
            ans += 1
            a += 1
        else:
            break
    else:
        if K >= B[b]:
            K -= B[b]
            ans += 1
            b += 1
        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
ina = 0
inb = 0
T = K
while ina != -1 or inb != -1:
    if ina != -1 and inb != -1:
        if A[ina] < B[inb]:
            if T > A[ina]:
                T -= A[ina]
                ans += 1
                ina += 1
                if ina == N:
                    ina = -1
            else:
                break
        elif A[ina] >= B[inb]:
            if T > B[inb]:
                T -= B[inb]
                ans += 1
                inb += 1
                if inb == M:
                    inb = -1
            else:
                break
    elif ina == -1:
        if T > B[inb]:
            ans += 1
            inb += 1
            if inb == M:
                inb = -1
    else:
        if T > A[ina]:
            ans += 1
            ina += 1
            if ina == N :
                ina = -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()))

t = 0
c = 0
for i in range(n + m):
    if a[0] > b[0]:
        t += b[0]
        b = (b[1:] if len(b) != 1 else [10**9 + 1])
    else:
        t += a[0]
        a = (a[1:] if len(a) != 1 else [10**9 + 1])

    if t > k:
        break
    else:
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answer=0
numbers=[]
while A and B:
    if A[0]>=B[0]:
        numbers.append(B[0])
        del B[0]
    else:
        numbers.append(A[0])
        del A[0]
if A:
    for a in A:
        numbers.append(a)
else:
    for b in B:
        numbers.append(b)
for a in range(1,N+M+1):
    if sum(numbers[:a])<=K:
        answer+=1
print(answer)

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
count = 0
while(K>0):
    if a_i == N and b_i == M:
        pass
    elif a_i == N:
        K -= B[b_i]
        b_i += 1
        count+=1
    elif b_i == M:
        K -= A[a_i]
        a_i += 1
        count+=1
    else:
        if A[a_i]<B[b_i]:
            K -= A[a_i]
            a_i += 1
        else:
            K -= B[b_i]
            b_i += 1
        count+=1
    if K<0:
        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()))

cnt = 0
while k >= 0:
    if la == []:
        if lb == []:
            break
        elif lb[0] <= k:
            k -= lb[0]
            cnt += 1
            lb.remove(lb[0])
        else:
            break
    elif lb == []:
        if la[0] <= k:
            k -= la[0]
            cnt += 1
            la.remove(la[0])
        else:
            break
    elif la[0] > lb[0]:
        if lb[0] <= k:
            k -= lb[0]
            cnt += 1
            lb.remove(lb[0])
        else:
            break
    elif la[0] <= lb[0]:
        if la[0] <= k:
            k -= la[0]
            cnt += 1
            la.remove(la[0])
        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()))
i=j=0
ans=0
while i<n and j<m and k>0 and (k>=a[i] or k>=b[j]):
  if(a[i]<=b[j]):
    k-=a[i]
    i+=1
  else:
    k-=b[j]
    j+=1
  ans+=1
while k>0 and i<n and k>=a[i]:
  k-=a[i]
  i+=1
  ans+=1
while k>0 and j<m and k>=b[j]:
  k-=b[j]
  j+=1
  ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left

def resolve():
    n, m, k  = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    aac = [0] + list(accumulate(a))
    bbc = [0] + list(accumulate(b))
    ans = 0
    for i, aa in enumerate(aac):
        if aa > k:
            break
        tmp = k - aa
        idx = bisect_left(bbc, tmp)
        if ans < i + idx - 1:
            ans = i + idx
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import math

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

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

sum_ = 0
cnt=0
while True:
  if len(a_list)>=1:
    a_top = a_list[-1]
  else:
    a_top = math.inf
  if len(b_list)>=1:
    b_top = b_list[-1]
  else:
    b_top = math.inf
  
  if a_top<b_top:
    tmp = sum_ + a_top
    a_list.pop()
  else:
    tmp = sum_ + b_top
    b_list.pop()
    
  if tmp>k:
    break
  elif (len(a_list)==0) & (len(b_list)==0):
    sum_ = tmp
    cnt+=1
    break
  else:
    sum_ = tmp
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, m, k = LI()
a = deque(LI())
b = deque(LI())
ans = 0
while k > 0:
    if len(a) > 0 and (len(b) == 0 or a[0] <= b[0]) and k >= a[0]:
        k -= a.popleft()
        ans += 1
    elif len(b) > 0 and (len(a) == 0 or b[0] <= a[0]) and k >= b[0]:
        k -= b.popleft()
        ans += 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()))

books = sorted(a+b)
minutes = 0

for i in range(len(books)):
    minutes += books[i]
    if minutes > k:
        print(i)
        break
    elif i == len(books)-1:
        print(len(books))
        break

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
A, B = deque(A), deque(B)
ans = 0
while K > 0:
    if A and B:
        if A[0] <= K and B[0] <= K:
            if tuple(A) < tuple(B): K -= A.popleft()
            else: K -= B.popleft()
            ans += 1
        elif A[0] <= K and B[0] > K: K -= A.popleft(); ans += 1
        elif B[0] <= K and A[0] > K: K -= B.popleft(); ans += 1
        else: break
    elif A:
        if A[0] <= K: K -= A.popleft(); ans += 1
        else: break
    elif B:
        if B[0] <= K: K -= B.popleft(); ans += 1
        else: break
    else:
        break
print(ans)