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:
import sys
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_max = len(A)
B_max = len(B)
time = 0
A_cn = 0
B_cn = 0
while True:
    if len(A) != A_cn and len(B) != B_cn:
        if A[A_cn] <= B[B_cn]:
            time += A[A_cn]
            A_cn += 1
            if time > K:
                A_cn -= 1
                time -= A[A_cn]
                print(A_cn + B_cn)
                sys.exit()
            elif time == K:
                print(A_cn + B_cn)
                sys.exit()
        else:
            time += B[B_cn]
            B_cn += 1
            if time > K:
                B_cn -= 1
                time -= B[B_cn]
                print(A_cn + B_cn)
                sys.exit()
            elif time == K:
                print(A_cn + B_cn)
                sys.exit()
    elif len(A) == A_cn:
        time += B[B_cn]
        B_cn += 1
        if time > K:
            B_cn -= 1
            time -= B[B_cn]
            print(A_cn + B_cn)
            sys.exit()
        elif time == K:
            print(A_cn + B_cn)
            sys.exit()
    else:
        time += A[A_cn]
        A_cn += 1
        if time > K:
            A_cn -= 1
            time -= A[A_cn]
            print(A_cn + B_cn)
            sys.exit()
        elif time == K:
            print(A_cn + B_cn)
            sys.exit()

Submission status: Wrong Answer

Solution code:
from collections import deque

n,m,k = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
a.sort()
b.sort()

x = deque(a)
y = deque(b)

ans=0
for i in range(n + m):
    # print(x, y)
    try:
        temp = x.popleft() if x[0] <= y[0] else y.popleft()
    except:
        if len(x) == 0:
            temp = y.popleft()
        elif len(y) == 0:
            temp=x.popleft()

    # print(k)
    k -= int(temp)
    if k >= 0:
        ans += 1
    else:
        break
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_que = deque(A)
B_que = deque(B)
ans = 0
time = 0
while True:
    if len(A_que) == 0:
        while len(B_que) != 0:
            tmp_b = B_que.popleft()
            if time + tmp_b > K:
                break
            else:
                time += tmp_b
                ans += 1
        break
    if len(B_que) == 0:
        while len(A_que) != 0:
            tmp_a = A_que.popleft()
            if time + tmp_a > K:
                break
            else:
                time += tmp_a
                ans += 1
        break
    tmp_a = A_que.popleft()
    tmp_b = B_que.popleft()
    if min(tmp_a,tmp_b)+time > K:
        break
    if tmp_a >= tmp_b:
        time += tmp_b
        ans += 1
        A_que.appendleft(tmp_a)
    else:
        time += tmp_a
        ans += 1
        B_que.appendleft(tmp_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()))
A = deque(A)
B = list(map(int, input().split()))
B = deque(B)


count = 0
ans = 0
flag2 = 0
while (True):
    #print(A,B)

    if A[0] < B[0]: flag = 0
    else: flag = 1

    mini = min(A[0], B[0])
    if mini + count <= K:
        count += mini
        ans += 1
        if flag == 0: A.popleft()
        else: B.popleft()
    else: break

    if (len(A) == 0) | (len(B) == 0):
        flag2 = 1
        break

if flag2==1:
    if len(A) == 0:
        for b in B:
            if b + count <= K:
                count += b
                ans += 1
            else: break
    if len(B) == 0:
        for a in A:
            if a + count <= K:
                count += a
                ans += 1
            else: break


print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
from collections import deque
As=deque(As)
Bs=deque(Bs)
ans=0
inf=100000000000000000000000000000000000
while k>0:
    try:
        a=As.popleft()
    except:
        a=inf
    try:
        b=Bs.popleft()
    except:
        b=inf
    if a>b:
        k-=b
        As.appendleft(a)
    else:
        k -=a
        Bs.appendleft(b)
    ans+=1
print(ans-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
while (time <= K):
  if frag_j and frag_i:
    if A[i] >= B[j]:
      time +=B[j]
      if time <= K:
        count += 1
      j +=1
      if j >= M:
        frag_j = 0 
    else:
      time+=A[i]
      if time <= K:
        count +=1
      i +=1
      if i >= N:
        frag_i = 0
  elif frag_i and (not frag_j):
    time+=A[i]
    if time <= K:
      count +=1
    i +=1
    if i >= N:
      frag_i = 0
  elif frag_j and (not frag_i):
    time+=B[j]
    if time <=K:
      count +=1
    j +=1
    if j >= M:
      frag_j = 0
  else:
    break
print(count)

Submission status: Wrong Answer

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

aindex = 0
bindex = 0
timeconsumed = 0
readbooks = 0

while True:
    if aindex >= len(A) and bindex >= len(B):
        break
    atime = A[aindex] if aindex < len(A) else 10 ** 10
    btime = B[bindex] if bindex < len(B) else 10 ** 10
    if atime < btime:
        timeconsumed += atime
        aindex += 1
    else:
        timeconsumed += btime
        bindex += 1
    if timeconsumed > k:
        break
    readbooks += 1
print(readbooks)

Submission status: Wrong Answer

Solution code:
n,n,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()

total = 0
ans = 0
while True:

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

    if total + yonda > k :
        break
    
    total += yonda
    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_total = []
B_total = []
tmp = 0

for i in range(N):
    tmp += A[i]
    A_total.append(tmp)

tmp = 0
for i in range(M):
    tmp += B[i]
    B_total.append(tmp)

A_count = -1
B_count = -1

for i in range(N):
    if A_total[i] > K:
        break
    else:
        A_count = i

max_count = A_count + 1

for i in range(M):
    while A_total[A_count] + B_total[i] > K and A_count > 0:
        A_count -= 1
    if B_total[i] > K:
        break
    else:
        B_count = i
    if max_count < A_count + B_count + 2:
        max_count = A_count + B_count + 2

print(max_count)

Submission status: Wrong Answer

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

def solve():
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    cum_a = [0] * N
    cum_b = [0] * M
    for i in range(N):
        cum_a[i] = A[i] if i == 0 else A[i] + cum_a[i - 1]
    
    for i in range(M):
        cum_b[i] = B[i] if i == 0 else B[i] + cum_b[i - 1]

    d = 0
    for i in range(N):
        if cum_a[i] <= K:
            d = i + 1
        else:
            break
    
    rem = K - (cum_a[d - 1] if d != 0 else 0)
    e = 0
    for i in range(M):
        if cum_b[i] <= rem:
            e = i + 1
        else:
            break

    ans = d + e


    while True:
        d -= 1
        if d < 0:
            break
        rem = K - (cum_a[d - 1] if d != 0 else 0)
        while e <= M and cum_b[e - 1] <= rem:
            e += 1
        ans = max(ans, d + e)
    
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def getlistofstring(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)

n, m, k = get_ints()
a = deque(get_list())
b = deque(get_list())
ans = i = j = 0
while True:
    try:
        a1 = a[0]
    except:
        a1 = float('inf')
    try:
        b1 = b[0]
    except:
        b1 = float('inf')
    if a1 < b1:
        if k - a1 >= 0:
            k -= a1
            ans += 1
            a.popleft()
        else:
            break
    else:
        if k - b1 >= 0:
            k -= b1
            ans += 1
            b.popleft()
        else:
            break
print(ans)





# sys.setrecursionlimit(10**6)
# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Submission status: Wrong Answer

Solution code:
# C - Tsundoku
from collections import deque

N, M, K = map(int, input().split())
A = deque(int(a) for a in input().split())
B = deque(int(b) for b in input().split())
A.append(10**18)
B.append(10**18)

T = 0
ans = 0
while T <= K:
    #print(A, B)
    if not (A) and not (B):
        break
    elif not (A) or A[0] > B[0]:
        tmp = B.popleft()
        if tmp == 10**18:
            continue
        if tmp + T <= K:
            T += tmp
            ans += 1
    elif not (B) or A[0] <= B[0]:
        tmp = A.popleft()
        if tmp == 10**18:
            continue
        if tmp + T <= K:
            T += tmp
            ans += 1    
    #print(T, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect_left
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	ans = 0; i = 0; j = 0
	while k > 0 and i < a and j < b:
		if a_[i] < b_[j]:
			k -= a_[i]; i += 1
		else:
			k -= b_[j]; j += 1
		ans += 1
	while k > 0 and i < a:
		k -= a_[i]; i += 1
		ans += 1
	while k > 0 and j < b:
		k -= b_[j]; j += 1
		ans += 1
	if k < 0:
		ans -= 1
	print(ans)





		

if __name__ == "__main__":
	solve()

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
al = deque(al)
bl = deque(bl)

time = 0
cnt = 0
while time < K :
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] <= bl[0]:
            time += al[0]
            al.popleft()
        else:
            time += bl[0]
            bl.popleft()
    elif len(al) >= 1:
        time += al[0]
        al.popleft()
    elif len(bl) >= 1:
        time += bl[0]
        bl.popleft()
    else:
        pass
    cnt += 1

if time == K:
    print(cnt)
else:
    print(cnt-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()))

accum_a = [a[0]] * n
for i in range(1, n):
    accum_a[i] = accum_a[i - 1] + a[i]

accum_b = [b[0]] * m
for i in range(1, m):
    accum_b[i] = accum_b[i - 1] + b[i]

cnt = 0
time = 0
a_idx = 0
b_idx = 0
while a_idx < n or b_idx < m:
    if a_idx < n and (b_idx == m or accum_a[a_idx] < accum_b[b_idx]):
        if a[a_idx] > k - time:
            break

        time += a[a_idx]
        a_idx += 1
    else:
        if b[b_idx] > k - time:
            break

        time += b[b_idx]
        b_idx += 1

    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:

n,m,K=list(map(int,input().split()))
A=[int(j) for j in input().split()]
B=[int(j) for j in input().split()]
i=0
j=0
time=0
cnt=0
while(i<n and j<m):
    one=False
    if(A[i]<=B[j] ):
        x=A[i]
        one=True

    else:
        x=B[j]
    if(x+time<=K):
        time=time+x
        if(one):
            i+=1
        else:
            j+=1
        cnt+=1
    else:
        break
if(time<K):
    while(i<n ):
        if(A[i]+time<=K):
            cnt+=1
            i+=1
        else:
            break
    while(j<m ):
        if(B[j]+time<=K):
            cnt+=1
            j+=1
        else:
            break
    # print(time,cnt)
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()))

m = 0
mnt = 0
num = 0
for i, a in enumerate(A):
    num = i+1
    if mnt + a > K:
        num = i
        break
    mnt += a
A = A[:num]
ans = num

j = 0
for i in range(num):
    while j < M and mnt+B[j] <= K:
        mnt += B[j]
        j += 1
        ans = max(ans, j+num-i)
    mnt -= A[num-i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))[::-1]
B = list(map(int, input().split()))[::-1]
cnt = 0
while A or B:
    if not A:
        if B[-1] <= K:
            K -= B.pop()
            cnt += 1
            continue
        else:
            break
    if not B:
        if A[-1] <= K:
            K -= A.pop()
            cnt += 1
            continue
        else:
            break
    if A[-1] <= B[-1]:
        if A[-1] <= K:
            K -= A.pop()
            cnt += 1
        else:
            break
    else:
        if B[-1] <= K:
            K -= B.pop()
            cnt += 1
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#N=int(input())
import numpy
N,M,K=map(int, input().split())
AList=list(map(int, input().split()))
BList=list(map(int, input().split()))
#AList.extend(BList)
#AList=sorted(AList)
#print(AList)
#AList=list(numpy.cumsum(AList))
#BList=list(numpy.cumsum(BList))
#print(AList)
SUM=0
cnt=0
for i in range(N+M):
    if len(AList)!=0 and len(BList)!=0:
        if AList[0]<BList[0]:
            if SUM+AList[0]>K:
                print(cnt)
                quit()
            SUM+=AList[0]
            del AList[0]
            cnt+=1
        else:
            if SUM+BList[0]>K:
                print(cnt)
                quit()
            SUM+=BList[0]
            del BList[0]
            cnt+=1
    elif len(AList)==0 and len(BList)!=0:
        if SUM+BList[0]>K:
            print(cnt)
            quit()
        SUM+=BList[0]
        del BList[0]
        cnt+=1
    elif len(BList)==0 and len(AList)!=0:
        if SUM+AList[0]>K:
            print(cnt)
            quit()
        SUM+=AList[0]
        del AList[0]
        cnt+=1
    else:
        break
print(cnt)

Submission status: Wrong Answer

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

ans = 0
tm = 0
while True:
  if len(alist) == 0 and len(blist) == 0:
    break
  elif len(alist) == 0:
    tm += blist.pop(0)
  elif len(blist) == 0:
    tm += alist.pop(0)
  else:
    tm += alist.pop(0) if alist[0] < blist[0] else blist.pop(0)
    
  if tm > k:
    break
  ans += 1
    
print(ans)

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
while True:
    if len(a) == 0 and len(b) == 0:
        break

    if len(a) == 0:
        read = b.popleft()
    elif len(b) == 0:
        read = a.popleft()
    elif a[0] < b[0]:
        read = a.popleft()
    else:
        read = b.popleft()

    k -= read
    if k >= 0:
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

(n, m, k), aa, bb = [deque(map(int, l.split())) for l in open(0)]

i = 0

while 1:
    if len(aa) and len(bb):
        if k < min(aa[0],bb[0]):
            break
        if aa[0]>bb[0]:
            k -= bb.popleft()
            i+=1
        else:
            k -= aa.popleft()
            i+=1
    elif len(aa):
        if k < aa[0]:
            break
        k -= aa.popleft()
        i+=1
    elif len(bb):
        if k < bb[0]:
            break
        k -= bb.popleft()
        i+=1
    else:
        break
    

print(i)

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
count=0
while time<k:
    if count==(n+m-1) or count//2>=n:
        count=n+m+1
        break
    elif count//2>=n or count//2>=m:
        count+=1
        continue
    elif count%2==0:
        time+=a[count//2]
        count+=1
    else:
        time+=b[count//2]
        count+=1
print(count-1)

Submission status: Wrong Answer

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

reading = 0
read_book = 0
i = 0
while reading < K:
  if i+1 <= N:
    reading += A[i]
    if reading <= K:
      read_book += 1
    else:
      break
  if i+1 <= M:
    reading += B[i]
    if reading <= K:
      read_book += 1
    else:
      break
  i += 1

print(read_book)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
num = 0
an = 0
bn = 0
while (an < len(a)) & (bn < len(b)):
    if a[an] <= b[bn]:
        t += a[an]
        if t > k:
            break
        num += 1
        an += 1
    else:
        t += b[bn]
        if t > k:
            break
        num += 1
        bn += 1

if t < k:
    if an == len(a) - 1:
        while (bn < len(b)):
            t += b[bn]
            if t > k:
                break
            num += 1
            bn += 1
    elif bn == len(b) - 1:
        while (an < len(a)):
            t += a[an]
            if t > k:
                break
            num += 1
            an += 1

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

# print(a,b)

time = 0
ia = 0
ib = 0

while time < k:
    if ia >= len(a):
        time += b[ib]
        ib += 1
    elif ib >= len(b):
        time += a[ia]
        ia += 1
    elif a[ia] <= b[ib]:
        time += a[ia]
        ia += 1
    else:
        time += b[ib]
        ib += 1

if time > k:
    print(ia + ib - 1)
else:
    print(ia + ib)

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

counter = 0
while 1:
    a = b = 10**10
    if len(A) > 0:
        a = A[0]
    if len(B) > 0:
        b = B[0]
    if a < b and a <= K:
        # print(f"Aの方が早く読める {a} < {b}")
        A = A[1:]
        K -= a
        counter += 1
    elif b < a and b <= K:
        # print(f"Bの方が早く読める {b} < {a}")
        B = B[1:]
        K -= b
        counter += 1
    else:
        # print("もう読めない")
        break
    # print(f"残り {K}分")
print(counter)

Submission status: Wrong Answer

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

# print(n, m, k, a, b, sep='\n')
#
# print(a[1::])
cnt = 0
passed = 0

while True:
    if passed > k:
        cnt -= 1
        break
    elif not a and not b:
        break
    elif not a:
        passed += b[0]
        b = b[1::]
        cnt += 1
    elif not b:
        passed += a[0]
        a = a[1::]
        cnt += 1
    else:
        if a[0] > b[0]:
            passed += b[0]
            b = b[1::]
            cnt += 1
        else:
            passed += a[0]
            a = a[1::]
            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()))
count=0
while k>0:
    if a==[]:
        k-=b[0]
        del b[0]
    elif b==[]:
        k-=a[0]
        del a[0]
    elif a[0]<=b[0]:
        k-=a[0]
        del a[0]
    elif a[0]>b[0]:
        k-=b[0]
        del b[0]
    count+=1
if a==[] and b==[]:
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate


def binary(N,T):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if T < b[(l + r) // 2]:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r


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

ans = 0
for i, ai in enumerate(a):
    t = k - ai
    if t > 0:
        j = binary(m,t)
        ans = max(ans, i + j + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m,k=nii()
a=lnii()
b=lnii()

a_inx=0
b_inx=0
t=0
ans=0

while t<=k:
  if a_inx<=n-1:
    a_c=a[a_inx]
  else:
    a_c=10**18
  if b_inx<=m-1:
    b_c=b[b_inx]
  else:
    b_c=10**18

  if a_c<=b_c:
    ans+=1
    t+=a_c
    a_inx+=1
  else:
    ans+=1
    t+=b_c
    b_inx+=1

if ans==0:
  print(0)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
time = 0
A_i = 0
B_i = 0
while time < K:
    if A_i < N and B_i < M:
        if A[A_i] < B[B_i]:
            time += A[A_i]
            A_i += 1
        else:
            time += B[B_i]
            B_i += 1
    elif A_i < N and B_i >= M:
        time = A[A_i]
        A_i += 1
    elif A_i >= N and B_i < M:
        time = B[B_i]
        B_i += 1
    else:
        break

if time <= K:
    print(A_i + B_i)
else:
    print(A_i + B_i -1)

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)
for i in range(n):
    sa[i+1] = sa[i] + a[i]
sb = [0] * (m+1)
for i in range(m):
    sb[i+1] = sb[i] + b[i]

ans = 0
for i in range(1,n+1):
    if sa[i] > k:
        break
    bi = min(m, bisect.bisect_right(sb, max(0, k-sa[i]))-1)
    ans = max(ans, i + bi)
print(ans)

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
t = 0
ae = True
be = True
while t <= k:
    if len(a) != 0:
        ai = a.popleft()
    else:
        ae = False
    if len(b) != 0:
        bi = b.popleft()
    else:
        be = False

    if ai <= bi:
        if ai != (10**9 + 1):
            t += ai
        if be:
            b .appendleft(bi)
    else:
        if ai != (10**9 + 1):
            t += bi
        if ae:
            a.appendleft(ai)
    if ae == False and be == False:
        break
    if t <= k:
        cnt += 1
    ai = 10**9 + 1
    bi = 10**9 + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    res = 0
    time = 0
    a_ind = 0
    b_ind = 0
    ind = 0
    a_f=False
    b_f = False
    lis = []
    while(len(lis)<(n+m)):
        if(a[a_ind]>b[b_ind]):
            lis.append(b[b_ind])
            b_ind+=1
        else:
            lis.append(a[a_ind])
            a_ind+=1
        if(a_ind>=n):
            for i in range(b_ind,m):
                lis.append(b[i])
            break
        if(b_ind>=m):
            for i in range(a_ind,n):
                lis.append(a[i])
            break
        ind+=1

    for i in range(len(lis)):
        time+=lis[i]
        if(time<=k):
            res+=1
        else:
            print(res)
            exit()
    print(res)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, M, K = mi()
    A = list(mi())
    B = list(mi())

    A = deque(A)
    B = deque(B)
    t = 0
    cnt = 0
    while A or B:
        if A and B:
            if A[0] < B[0]:
                s = A[0]
                if t+s > K:
                    break
                t += A.popleft()
            else:
                s = B[0]
                if t+s > K:
                    break
                t += B.popleft()
        elif A:
            s = A[0]
            if t+s > K:
                break
            t += A.popleft()

        elif B:
            s = B[0]
            if t+s > K:
                break
            t += B.popleft()
    print(N+M-len(A)-len(B))


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

C = A+B

ans = 0
count = 0
a = 0
b = 0
while ans <= K:
  if a > len(A) - 1 and b > len(B)-1:
    break

  if a > len(A) - 1 and b <= len(B)-1:
    ans += B[b]
    if ans <= K:
      b += 1
      continue
    else:
      break
    

  if a <= len(A) - 1 and b > len(B)-1:
    ans += A[a]
    if ans <= K:
      a += 1
      continue
    else:
      break
     
  if A[a] >= B[b]:
    ans += B[b]
    if ans <= K:
      b += 1
    else:
      break
  else:
    ans += A[a]
    if ans <= K:
      a += 1
    else:
      break

print(a+b)

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 = K
A_count = 0
B_count = 0
ans = 0

f_inf = float('inf')
A.append(f_inf)
B.append(f_inf)

for i in range(N+M+1):
    if A_count >= N and B_count >= M:
        break
    if A[A_count] < B[B_count]:
        time -= A[A_count]
        if time < 0:
            break
        A_count += 1
        ans += 1
    elif A[A_count] >= B[B_count]:
        time -= B[B_count]
        if time < 0:
            break
        B_count += 1
        ans += 1

# if A_count >= N and B_count >= M:
# while time >= 0:
#     if A_count < N:
#         time -= A[A_count]
#         if time < 0:
#             break
#         ans += 1
#         A_count += 1
#     if B_count < M:
#         time -= B[B_count]
#         if time < 0:
#             break
#         ans += 1
#         B_count += 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()))

count = 0
time = 0
a = 0
b = 0
while time <= k:
    if a == n:
        if b == m:
            break
        else:
            time += B[b]
            b += 1
            count += 1
    elif b == m:
        time += A[a]
        a += 1
        count += 1
    elif A[a] <= B[b]:
        time += A[a]
        a += 1
        count += 1
    else:
        time += B[b]
        b += 1
        count += 1

    if time == k:
        print(count)
        sys.exit()
    
print(count-1)

Submission status: Wrong Answer

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

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

ans =0 

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

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


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

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





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()))
cnt=0
ans=0
if sum(a)+sum(b)<=k:
    print(n+m)
    sys.exit()
a.append(10**10)
b.append(10**10)
for i in range(2*10**5):
    if a[0]==min(a[0],b[0]):
        cnt+=a.pop(0)
    else:
        cnt+=b.pop(0)
    if cnt>k:
        print(ans)
        break
    ans+=1

Submission status: Wrong Answer

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

    A = [10**10]+A[::-1]
    B = [10**10]+B[::-1]

    a = 0
    while True:
        if A[-1] < B[-1] and K >= A[-1]:
            a += 1
            K -= A.pop()
        if K >= B[-1]:
            a += 1
            K -= B.pop()
        else:
            return a

print(hoge())