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 sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n,m,k=map(int,readline().split())
    a=list(map(int,readline().split()))
    b=list(map(int,readline().split()))

    a=np.array(a,dtype=np.int64).cumsum()
    b=np.array(b,dtype=np.int64).cumsum()

    a=a[a<=k]
    a=k-a

    if a.size>=1:
        res=np.searchsorted(b,a,side="right")
        tmp=np.arange(1,a.size+1,dtype=np.int64)

        print((res+tmp).max())
    
    else:
        b=b[b<=k]
        print(b.size)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n,m,k=map(int,readline().split())
    a=list(map(int,readline().split()))
    b=list(map(int,readline().split()))

    a=np.array(a,dtype=np.int64).cumsum()
    b=np.array(b,dtype=np.int64).cumsum()

    a=a[a<=k]
    a=k-a

    if a.size>=1:
        res=np.searchsorted(b,a,side="right")
        tmp=np.arange(a.size,dtype=np.int64)

        print((res+tmp+1).max())
    
    else:
        print(0)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import maxsize

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

# check
cnt = 0
while K >= min(A[0], B[0]):
    if A[0] < B[0]:
        K -= A[0]
        del A[0]
        if len(A) == 0:
            A = [maxsize]
    else:
        K -= B[0]
        del B[0]
        if len(B) == 0:
            B = [maxsize]
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True


n,m,k=input2()
A=input_array()
B=input_array()

ca=0
cb=0
count=0
SUM=0
for i in range(n+m):
	if ca >= n:
		SUM+=B[cb]
		cb+=1
	elif cb >= m:
		SUM+=A[ca]
		ca+=1
	elif A[ca]<=B[cb]:
		SUM+=A[ca]
		ca+=1
	else:
		SUM+=B[cb]
		cb+=1

	if SUM >k:
		break
	else:
		count+=1
print(count)

Submission status: Wrong Answer

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

n, m, k = map(int, input().split())
s = list(map(int, input().split()))
s.extend(list(map(int, input().split())))
s.sort()
sm = [0, 0]
if s[0] > k: print(0)
else:
    for i in range(n + m):
        sm[0] += s[i]
        if sm[0] > k: break
        sm[1] += 1
    print(sm[1])

Submission status: Wrong Answer

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

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()))
count1,count2,count3 = 0,0,0
time1,time2,time3 = 0,0,0
for i in A:
    if i + time1 < K:
        time1 += i
        count1 += 1
for i in B:
    if i + time2 < K:
        time2 += i
        count2 += 1
for i in range(max(N,M)):
    if i < N and i < M:
        if A[i] + B[i] + time3 <= K:
            time3 += A[i]+B[i]
            count3 += 2
        elif A[i] + time3 <= K:
            time3 += A[i]
            count3 += 1
        elif B[i] + time3 <= K:
            time3 += B[i]
            count3 += 1
    elif i < N and i >= M:
        if A[i] + time3 <= K:
            time3 += A[i]
            count3 += 1

    elif i >= N and i < M:
        if B[i] + time3 <= K:
            time3 += B[i]
            count3 += 1

result = max(count1,count2,count3)

print(result)

Submission status: Wrong Answer

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

C = sorted(A + B)
j = 0
k = 0

for i in range(N + M):
  j += C[i]
  k += 1
  if j > K:
    break

print(k-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(' ')))
x = 0
i = 0
j = 0
T = 0

while T + A[i] <= K or T + B[j] <= K:
  if A[i] <= B[j]:
    T += A[i]
    i += 1
    x += 1
    if i == N:
      break
  else:
    T += B[j]
    j += 1
    x += 1
    if j == M:
      break
if i == N and T +B[j] <= K:
  while T + B[j] <= K:
    T += B[j]
    j += 1
    x += 1
    if j == M:
      break
elif j == M and T + A[i] <= K:
  while T + A[i] <= K:
    T += A[i]
    i += 1
    x += 1
    if i == N:
      break
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
read = sys.stdin.read


N, M, K = map(int, input().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)

left = 0
for i, b in enumerate(B):
    if b > K:
        left = i - 1
        break

ans = 0
if A[-1] + B[-1] <= K:
    ans = N + M
else:
    for i in range(len(A)):
        if A[i] > K:
            break

        while A[i] + B[left] > K:
            left -= 1

        ans = max(ans, left + i)

print(ans)

Submission status: Wrong Answer

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

#０冊を初期値にする
A=[0]
B=[0]


for a in At:
    if A[-1]+a<K:
        A.append(A[-1]+a)
    else:
        break
for b in Bt:
    if B[-1]+b<K:
        B.append(B[-1]+b)
    else:
        break

def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    if Ak+B[arg]<=K:
        return True
    else:
        return False


def meguru_bisect(ng, ok):
    '''
    めぐる2分探査
    okはBの冊数たりうる値
    ngはBの冊数たり得ない値を入れる。
    '''

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


Ak=0

maxBooks=0
for Ai in range(len(A)): 
    Ak=A[Ai]
    Bi=meguru_bisect(len(B),0) #len(B)は配列の要素数として使われるとき最大＋１
    if maxBooks<(Ai+Bi):
        maxBooks=Ai+Bi
print( maxBooks )

Submission status: Wrong Answer

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

#０冊を初期値にする
A=[0]
B=[0]


for a in At:
    if A[-1]+a<K:
        A.append(A[-1]+a)

for b in Bt:
    if B[-1]+b<K:
        B.append(B[-1]+b)

def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    if Ak+B[arg]<=K:
        return True
    else:
        return False


def meguru_bisect(ng, ok):
    '''
    めぐる2分探査
    okはBの冊数たりうる値
    ngはBの冊数たり得ない値を入れる。
    '''

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


Ak=0

maxBooks=0
for Ai in range(len(A)): 
    Ak=A[Ai]
    Bi=meguru_bisect(len(B),0) #len(B)は配列の要素数として使われるとき最大＋１
    if maxBooks<(Ai+Bi):
        maxBooks=Ai+Bi
print( maxBooks )

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
c = 0

aN = 0
bM = 0

T = 0

if N == 0:
  aN = 1
elif M == 0:
  bM = 1
else:
  pass


while T < K:
  if aN == 1 and bM == 1:
    break
    
  elif aN == 1:
    T += B[b]
    b += 1
  
  elif bM == 1:
    T += A[a]
    a += 1

  elif A[a] > B[b]:
    T += B[b]
    b += 1

  elif A[a] < B[b]:
    T += A[a]
    a += 1
  
  else:
    if a < b:
      T += A[a]
      a += 1
    else:
      T += B[a]
      b += 1

  if N == a:
    aN = 1
  elif M == b:
    bM = 1
  else:
    pass
  
  if T > K:
    c -= 1
    break
  elif T == K:
    break

ans = a + b + c
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 = 0
b = 0
c = 0

aN = 0
bM = 0

T = 0

if N == 0:
  aN = 1
elif M == 0:
  bM = 1
else:
  pass


while T < K:
  if aN == 1:
    T += B[b]
    b += 1
  
  elif bM == 1:
    T += A[a]
    a += 1

  elif A[a] > B[b]:
    T += B[b]
    b += 1

  elif A[a] < B[b]:
    T += A[a]
    a += 1
  
  else:
    if a < b:
      T += A[a]
      a += 1
    else:
      T += B[a]
      b += 1

  if N == a:
    aN = 1
  elif M == b:
    bM = 1
  else:
    pass
  
  if T > K:
    c -= 1
    break
  elif T == K:
    break

ans = a + b + c
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# binary search 1

from bisect import bisect_left, bisect_right

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

cumsum_b = [0 for _ in range(m+1)]
for i in range(1,m+1):
    cumsum_b[i] = cumsum_b[i-1] + b[i-1]
cumsum_a = [0 for _ in range(n+1)]
for i in range(1,n+1):
    cumsum_a[i] = cumsum_a[i-1] + a[i-1]

ans = -1
for i in range(n+1):
    res = k-cumsum_a[i]
    bl = bisect_right(cumsum_b, res) - 1 
    tmp = i + bisect_right(cumsum_b, res) - 1 
    if ans <= tmp:
        ans = tmp 

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 = 0
b = 0
c = 0

aN = 0
bM = 0

T = 0

while T < K:
  if aN == 1:
    T += B[b]
    b += 1
  
  elif bM == 1:
    T += A[a]
    a += 1

  elif A[a] > B[b]:
    T += B[b]
    b += 1

  elif A[a] < B[b]:
    T += A[a]
    a += 1
  
  else:
    if a < b:
      T += A[a]
      a += 1
    else:
      T += B[a]
      b += 1

  if N == a:
    aN = 1
  elif M == b:
    bM = 1
  else:
    pass
  
  if T > K:
    c -= 1
    break
  elif T == K:
    break

ans = a + b + c
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# binary search 1

from bisect import bisect_left, bisect_right

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

cumsum_b = [0 for _ in range(m+1)]
for i in range(1,m+1):
    cumsum_b[i] = cumsum_b[i-1] + b[i-1]
cumsum_a = [0 for _ in range(n+1)]
for i in range(1,n+1):
    cumsum_a[i] = cumsum_a[i-1] + a[i-1]

ans = -1
for i in range(n+1):
    res = k-cumsum_a[i]
    if res <= 0:
        ans = i 
        break
    bl = bisect_right(cumsum_b, res)
    tmp = i + bisect_right(cumsum_b, res) - 1 
    if ans <= tmp:
        ans = tmp 

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# binary search 1

from bisect import bisect_left, bisect_right

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

cumsum_b = [0 for _ in range(m+1)]
for i in range(1,m+1):
    cumsum_b[i] = cumsum_b[i-1] + b[i-1]
cumsum_a = [0 for _ in range(n+1)]
for i in range(1,n+1):
    cumsum_a[i] = cumsum_a[i-1] + a[i-1]

ans = -1
for i in range(n+1):
    res = k-cumsum_a[i]
    if res <= 0:
        break
    bl = bisect_right(cumsum_b, res)
    tmp = i + bisect_right(cumsum_b, res) - 1 
    print
    if ans <= tmp:
        ans = tmp 

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# binary search 1

from bisect import bisect_left, bisect_right

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

cumsum_b = [0 for _ in range(m+1)]
for i in range(1,m+1):
    cumsum_b[i] = cumsum_b[i-1] + b[i-1]
ans = -1
for i in range(n+1):
    res = k-sum(a[:i])
    if res <= 0:
        break
    bl = bisect_right(cumsum_b, res)
    tmp = i + bisect_right(cumsum_b, res) - 1 
    print
    if ans <= tmp:
        ans = tmp 

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect

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

cum_sum_A = [ A_list[0] ]
cum_sum_B = [ B_list[0] ]

for i in range(1, len(A_list)):
    cum_sum_A.append( cum_sum_A[i-1] + A_list[i] )

for i in range(1, len(B_list)):
    cum_sum_B.append( cum_sum_B[i-1] + B_list[i] )


max_num_book = 0

for i_a in range(len(cum_sum_A)):
    if cum_sum_A[i_a] > K:
        continue
    
    remain = K - cum_sum_A[i_a]
    i_b = bisect.bisect_right(cum_sum_B, remain)
    
    num_book = (i_a + 1) + i_b
    max_num_book = max(max_num_book, num_book)


print(max_num_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()))
a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
a.pop(0)
b.pop(0)
j=m-1
x=0
for i in range(n-1,-1,-1):
  if a[i]>k:
    continue
  while j>=0 and b[j]>k-a[i]:
    j-=1
  x=max(x,i+j+2)
print(x)

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,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
a.pop(0)
b.pop(0)
i=n-1
j=m-1
x=0
while i>=0:
  if a[i]>k:
    i-=1
    continue
  while j>=0:
    if b[j]<=k-a[i]:
      break
    j-=1
  x=max(x,i+j+2)
  i-=1
print(x)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,m,k = map(int, stdin.readline().rstrip().split())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))

A = [0]
B = [0]
ans,res = 0,0
for i in range(0, n):
    A.append(A[i]+a[i])
for i in range(0, m):
    B.append(B[i]+b[i])

def ans(A, B):
    ans= 0
    for i in range(0, n + 1):
        j = 0
        while A[i] + B[j + 1] <= k:
            j += 1
            if j == len(B) - 1:
                break

        ans = max(ans, i + j)
    return ans

if A[1] > k and B[1] > k:
    print(0)
else:
    res = ans(A, B)
    print(res)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
t=sum(b)
j=m-1
ans=0
for i in range(n+1):
  t+=a[i]
  while j>=0 and t>k:
    t-=b[j]
    j-=1
  ans=max(ans,j+i+1) 
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a = list(input().split())
a = [int(i) for i in a]
b = list(input().split())
b = [int(i) for i in b]
aa=a.copy()
aa.extend(b)
if sum(aa)<=k:
  print(n+m)
  exit()

#print(aa)
ai,bi=0,0
ans=0
for _ in range(n+m):
  #print(k, a[ai], b[bi], ai,bi)
  if k<a[ai] and k<b[bi]:
    print(ans)
    exit()
  
  if a[ai] <= b[bi]:
    k-=a[ai]
    ai+=1
    ans+=1
  else:
    k-=b[bi]
    bi+=1
    ans+=1
    
  if ai == len(a):
    a=[10**10]*200001
  if bi == len(b):
    b=[10**10]*200001
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a = list(input().split())
a = [int(i) for i in a]
b = list(input().split())
b = [int(i) for i in b]
aa=a.copy()
aa.extend(b)
if sum(aa)<=k:
  print(n+m)
  exit()

#print(aa)
ai,bi=0,0
ans=0
for _ in range(n+m):
  #print(k, a[ai], b[bi], ai,bi)
  if k<= a[ai] and k<= b[bi]:
    if k<0:
      print(ans-1)
    else:
      print(ans)
    exit()
  
  if a[ai] <= b[bi]:
    k-=a[ai]
    ai+=1
    ans+=1
  else:
    k-=b[bi]
    bi+=1
    ans+=1
    
  if ai == len(a):
    a=[10**10]*200001
  if bi == len(b):
    b=[10**10]*200001
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a = list(input().split())
a = [int(i) for i in a]
b = list(input().split())
b = [int(i) for i in b]
aa=a.copy()
aa.extend(b)
if sum(aa)<=k:
  print(n+m)
  exit()

#print(aa)
ai,bi=0,0
ans=0
for _ in range(n+m):
  #print(k, a[ai], b[bi], ai,bi)
  if k<= a[ai] and k<= b[bi]:
    print(ans)
    exit()
    
  if a[ai] <= b[bi]:
    k-=a[ai]
    ai+=1
    ans+=1
  else:
    k-=b[bi]
    bi+=1
    ans+=1
    
  if ai == len(a):
    a=[10**10]*200001
  if bi == len(b):
    b=[10**10]*200001
    
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()]

sum_AB = 0
cnt = 0
idx_A = -1
idx_B = -1
for i,a in enumerate(A):
  if sum_AB + a > K:
    break
  else:
    sum_AB += a
    cnt += 1
    idx_A = i
for i,b in enumerate(B):
  if sum_AB + b > K:
    break
  else:
    sum_AB += b
    cnt += 1
    idx_B = i
ans = cnt
A = A[0:idx_A+1][::-1]
B = B[idx_B+1:]
for a in A:
  sum_AB -= a
  cnt -= 1
  for b in B:
    if sum_AB + b > K:
      break
    else:
      sum_AB += b
      cnt += 1
  ans = max(cnt,ans)
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=i=j=0
while 1:
  if i>=n and j>=m:
    break
  if j>=m:
    t+=a[i]
    if t>k:
      break
    i+=1
  elif i>=n:
    t+=b[j]
    if t>k:
      break
    j+=1
  elif a[i]<=b[j]:
    t+=a[i]
    if t>k:
      break
    i+=1
  else:
    t+=b[j]
    if t>k:
      break
    j+=1
print(i+j)

Submission status: Wrong Answer

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

t = 0
count = 0
while True:
    if not A and not B:
        break

    a = A.pop()
    b = B.pop()
    c = min(a, b)

    if a == b:
        if a == 10 ** 9 + 1:
            break
        elif A[-1] > B[-1]:
            A.append(a)
            c = b
    elif a > b:
        A.append(a)
    else:
        B.append(b)

    if t + c > K:
        break

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

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)

cnt = 0
book = 0
while cnt < K:
    if(len(a) > 0 and len(b) > 0):
        aa = a.popleft()
        bb = b.popleft()
        
        if(aa >= bb and cnt+bb <= K):
            cnt += bb
            a.appendleft(aa)
        elif(aa < bb and cnt+aa <= K):
            cnt += aa
            b.appendleft(bb)
        else:
            break
        book += 1
    else:
        if(len(a) < 1):
            bb = b.popleft()
            if(cnt+bb <= K):
                cnt += bb
                book += 1
                continue
        elif(len(b) < 1):
            aa = a.popleft()
            if(cnt+aa <= K):
                cnt += aa
                book += 1
                continue
        elif(len(a) < 1 and len(b) < 1):
            break
    
print(book)

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      #cnt(a,b,time)

cnt(a,b,0)
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()))

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      cnt(a,b,time)

#cnt(a,b,0)
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)

cnt = 0
book = 0
while cnt < K:
    if(len(a) > 0 and len(b) > 0):
        aa = a.popleft()
        bb = b.popleft()
        
        if(aa >= bb and cnt+bb <= K):
            cnt += bb
            a.appendleft(aa)
        elif(aa < bb and cnt+aa <= K):
            cnt += aa
            b.appendleft(bb)
        else:
            break
        book += 1
    else:
        if(len(a) < 1):
            bb = b.popleft()
            if(cnt+bb <= K):
                cnt += bb
                book += 1
                continue
            else:
                break
        elif(len(b) < 1):
            aa = a.popleft()
            if(cnt+aa <= K):
                cnt += aa
                book += 1
                continue
            else:
                break
    
print(book)

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

from collections import deque
a = deque([x for x in a])
b = deque([x for x in b])
a.append(10**9+1)
b.append(10**9+1)

Submission status: Wrong Answer

Solution code:
"""
// Author : snape_here - Susanta Mukherjee
     
 """
 
from __future__ import division, print_function
 
import os,sys
from io import BytesIO, IOBase
 
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
 
 
def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
 
 
def read():
    sys.stdin = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 

def isPrime(n):
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
    return True

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

mod=1000000007

from math import *

import bisect

from decimal import *

getcontext().prec = 50

abc="abcdefghijklmnopqrstuvwxyz"

pi=3.141592653589793238

def main():

    n,m,l=mi()
    a=li()
    b=li()
    c=0
    j=k=0
    ans=n+m
    for i in range(n+m):
        if j==n:
            c+=b[k]
            k+=1
        elif k==m:
            c+=a[j]
            j+=1
        elif a[j]<=b[k]:
            c+=a[j]
            j+=1 
        else:
            c+=b[k]
            k+=1 
        #print(c)
        if c>l:
            ans=i 
            break
    print(ans)


# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
 
 
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
 
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
 
if __name__ == "__main__":
    #read()
    main()

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)

cnt = 0
book = 0
while cnt < K:
    if(len(a) > 0 and len(b) > 0):
        aa = a.popleft()
        bb = b.popleft()
        
        if(aa >= bb and cnt+bb <= K):
            cnt += bb
            a.appendleft(aa)
        elif(aa < bb and cnt+aa <= K):
            cnt += aa
            b.appendleft(bb)
        else:
            break
        book += 1
    if(len(a) < 1):
        bb = b.popleft()
        if(cnt+bb <= K):
            cnt += bb
            book += 1
            continue
        else:
            break
    elif(len(b) < 1):
        aa = a.popleft()
        if(cnt+aa <= K):
            cnt += aa
            book += 1
            continue
        else:
            break
    
print(book)