Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

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

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

from collections import deque
d = deque()

buf_K = K
ans = 0
max_i = 0
for i in range(N):
    if buf_K >= A[i]:
        buf_K -= A[i]
        d.append(A[i])
        ans += 1
    else:
        break
max_num = ans

for j in range(M):
    if buf_K >= B[j]:
        buf_K -= B[j]
        ans += 1
        if ans > max_num:
            max_num = ans
    else:
        flag = True
        while d:
            buf_K -= d.popleft()
            ans -= 1
            if buf_K >= B[j]:
                buf_K -= B[j]
                ans += 1
                if ans > max_num:
                    max_num = ans
                flag = False
                break
        if flag:
            break

print(max_num)

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

i_a = 0
i_b = 0
all = []
while i_a < n and i_b < m:
  if a[i_a] < b[i_b]:
    all.append(a[i_a])
    i_a += 1
  else:
    all.append(b[i_b])
    i_b += 1

if i_a < n:
  all.extend(a[i_a:])
elif i_b < m:
  all.extend(b[i_b:])

res = 0
total = 0
for t in all:
  if total + t <= k:
    res += 1
    total += t
print(res)

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

i = 0
j = 0
T = 0
cnt = 0

while T <= K:
  cnt += 1
  if i == N and j == M:
    break
  elif i == N:
    T += Bs[j]
    j += 1
  elif j == M:
    T += As[i]
    i += 1
  else:
    if As[i] > Bs[j]:
      T += Bs[j]
      j += 1
    elif As[i] < Bs[j]:
      T += As[i]
      i += 1
    else:
      if i+1 == N:
        T += Bs[j]
        j += 1
      elif j+1 == M:
        T += As[i]
        i += 1
      elif As[i+1] >= Bs[j+1]:
        T += Bs[j]
        j += 1
      else:
        T += As[i]
        i += 1

print(cnt-1)

Submission status: Wrong Answer

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

dp = [[[0, 0, 0] for _ in range(2)] for _ in range(N+M+1)]

for i in range(N+M):
    # 1個前にBを選択
    if dp[i][0][0] + A[dp[i][0][1]] > dp[i][1][0] + A[dp[i][1][1]]:
        dp[i+1][0][0] = dp[i][1][0] + A[dp[i][1][1]]
        dp[i+1][0][1] = dp[i][1][1] + 1
        dp[i+1][0][2] = dp[i][1][2]
    else:
        dp[i+1][0][0] = dp[i][0][0] + A[dp[i][0][1]]
        dp[i+1][0][1] = dp[i][0][1] + 1
        dp[i+1][0][2] = dp[i][0][2]

    if dp[i][0][0] + B[dp[i][0][2]] > dp[i][1][0] + B[dp[i][1][2]]:
        dp[i+1][1][0] = dp[i][1][0] + B[dp[i][1][2]]
        dp[i+1][1][1] = dp[i][1][1]
        dp[i+1][1][2] = dp[i][1][2] + 1
    else:
        dp[i+1][1][0] = dp[i][0][0] + B[dp[i][0][2]]
        dp[i+1][1][1] = dp[i][0][1]
        dp[i+1][1][2] = dp[i][0][2] + 1

ans = 0
for i in range(1, N+M+1):
    if dp[i][0][0] > K and dp[i][1][0] > K:
        break
    ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq as he
N,M,V = list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
S=list(map(int,A+B))
he.heapify(S)
ans=0
time=0
if sum(S)<=V:
  print(N+M)
  exit()
else:
  for i in range(N+M):
    if S[0]+time<=V:
      time+=S[0]
      he.heappop(S)
      ans+=1
    else:
      print(ans)
      exit()

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()))
max_c = 0
t = 0
cnt = 0
flag = 0

for i in range(n):
  for j in range(m):
    t = sum(a[:i]) + sum(b[:j])
    if t > k:
      break
    else :
      if i+j > max_c:
        max_c = i+j
print(max_c+2)

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(10000000000000000)
B.append(10000000000000000)
a=0
b=0
cnt=0
for i in range(n+m+2):	
	if min(A[a],B[b])>k:
		break 
	elif A[a]>=B[b]:
		k-=B[b]
		b+=1
		cnt+=1
	else:
		k-=A[a]
		a+=1
		cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
inf = 2*10**9
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.append(inf)
b.append(inf)
cur_a = 0
cur_b = 0
total = 0
count = 0
while a[cur_a] != inf and b[cur_b] != inf:
    total += min(a[cur_a], b[cur_b])
    if total > k:
        break
    count += 1
    if a[cur_a] > b[cur_b]:
        cur_b += 1
    else:
        cur_a += 1
else:
    if a[cur_a] == inf:
        while total < k:
            total += b[cur_b]
            count += 1
            cur_b += 1
    else:
        while total < k:
            total += a[cur_a]
            count += 1
            cur_a += 1
    if total > k:
        count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
N,M,K = input().split()
N= int(N)
M=int(M)
K=int(K)
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
count = 0
ai = 0
bi = 0

while (time < K):
    if ai < N and bi < M:
        if A[ai] <= B[bi]:
            time += A[ai]
            count += 1
            ai += 1
            continue
        else :
            time += B[bi]
            count += 1
            bi += 1
            continue
    if ai == N and bi != M:
        time += B[bi]
        count+=1
        bi+=1
        continue
    if ai != N and bi == M:
        time += A[ai]
        count += 1
        ai += 1
        continue
    if ai == N and bi == M:
        break

if time <= K:
    print(count)

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

A = sorted(A)
B = sorted(B)

ans = 0
for i in range(200000):

    try:
        K = K - A[i]
        if K < 0:
            break
        ans = ans + 1
    except:
        pass

    try:
        K = K -B[i]
        if K < 0:
            break
        ans = ans + 1
    except:
        pass
    
    if K <= 0:
        break
print(ans)

Submission status: Wrong Answer

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

if min(A) > K or min(B) > K:
    print(0)
    exit()

tmp = [0] * max(N, M)*2
ans = 0
if N < M:
    for i in range(M-N):
        A.append('a')
else:
    for i in range(N-M):
        B.append('a')

for i in range(max(N,M)*2):
    if i%2 == 0:
        tmp[i] = A[i//2]
    else:
        tmp[i] = B[i//2]

tmp = [s for s in tmp if s != 'a']
# print(sum(tmp))

for i in range(len(tmp)):
    if K-tmp[i] >= 0:
        K -= tmp[i]
        ans += 1
    else:
        print(ans)
        exit()

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 = A[0]
if a <= K:
    max = 1
else:
    max = 0
for i in range(1,N):
    a += A[i]
    A[i] = a
    if a <= K:
        max = i+1
b = B[0]
if max >= 1:
    L = K-A[max-1]
else:
    L = K
if b <= L:
    m = 1
else:
    m = 0
for i in range(1,M):
    b += B[i]
    B[i] = b
    if b <= L:
        m = i+1
ans = max+m
if max == 0 and m == 0:
    print(0)
else:
    while(max > 0 and m<M):
        max -= 1
        L = K-A[max]
        while(m<M and B[m]<=L):
                m += 1
        if max + m > ans:
            ans = max+m
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import *

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

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


cum_A = list(accumulate([0] + A))
cum_B = list(accumulate([0] + B))

start = bisect_left(cum_A, K) - 1       # K を超えない最大のcum_Aの要素を導くindex = 和がK以下になるようなAの要素の個数
res = [start]
k = 0

for i in reversed(range(1,start+1)):
    while cum_A[i] + cum_B[k] <= K:
        if k == M:
            res.append(i + k)
            break
        k += 1
    res.append(i + k-1)


print(max(res))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i, j = 0, 0
    while K > 0:
        if i == N:
            if j != M:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                i = N
                j = M
                break

        elif j == M:
            if i != N:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
            else:
                i = N
                j = M
                break
        else:
            if A[i] >= B[j]:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
    print(i+j)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
counter = 0
ans = 0
a = A.popleft()
b = B.popleft()
while counter < K:
    ans += 1
    if a >= b:
        counter += b
        if not B:
            b = 0
            break
        b = B.popleft()
    else:
        counter += a
        if not A:
            a = 0
            break
        a = A.popleft()
if counter > K:
    print(ans - 1)
elif counter == K:
    print(ans)
else:
    if a == 0:
        A = B
        a = b
    while counter < K:
        ans += 1
        counter += a
        if not A:
            if counter <= K:
                ans += 1
            break
        a = A.popleft()
    if counter == K:
        print(ans)
    else:
        print(ans - 1)

Submission status: Wrong Answer

Solution code:
def A(x):
  return x + x**2 + x**3


def B(s, t):
  ans = 0
  for i in range(len(s)):
    if s[i] != t[i]:
      ans += 1
  return ans


def C(n, m, k, a, b):
  ans = 0
  while k > 0:
    if a and b:
      if a[0] < b[0]:
        k -= a[0]
        a.pop()
      elif b:
        k -= b[0]
        b.pop()
    elif a:
      k -= a[0]
      a.pop()
    elif b:
      k -= b[0]
      b.pop()
    else:
      break
    if k >= 0:
      ans += 1
  return ans


def main():
  n, m, k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  print(C(n, m, k, a, 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()))


def choice_small(a, b):
    ans = []
    a.reverse()
    b.reverse()
    total = 0
    while True:
        if len(a) == 0 or len(b) == 0:
            if len(a) != 0:
                remain = a
            else:
                remain = b
            while True:
                if total <= k:
                    break
                total += remain[-1]
                if total > k:
                    break
                ans.append(remain.pop())

            break

        if a[-1] < b[-1]:

            total += a[-1]
            if total > k:
                break
            ans.append(a.pop())
        else:
            total += b[-1]
            if total > k:
                break
            ans.append(b.pop())
    return len(ans)


def rem_big(a, b):
    total = sum(a)+sum(b)
    while True:
        if total <= k:
            break
        if len(a) == 0 or len(b) == 0:
            if len(a) != 0:
                remain = a
            else:
                remain = b
            while True:
                if total <= k:
                    break
                total -= remain[-1]
                remain.pop()

            break

        if a[-1] < b[-1]:
            total -= b[-1]
            b.pop()
        else:
            total -= a[-1]
            a.pop()

    return len(a)+len(b)


print(max(choice_small(_a.copy(), _b.copy()), rem_big(_a.copy(), _b.copy())))

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

read = 0
i, j = 0, 0
while(i<len(a) and j<len(b)):
    if a[i]<b[j]:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k<0:
        break
    read += 1

if k > 0 or k == 0:
    if i==len(a):
        while(j < len(b)):
            k -= b[j]
            j += 1
            if k<0:
                break
            read += 1
    elif j==len(b):
        while(i < len(a)):
            k -= a[i]
            i += 1
            if k<0:
                break
            read += 1

print(read)

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=list()
for i in range(min(N,M)):
  C.append(A[i])
  C.append(B[i])
if N>M:
  C.extend(A[N-M:N])
elif M>N:
  C.extend(B[N-M:M])
  
if min(C[0],C[1])>K:
  print('0')
  exit()
k=0
ans=0
for i in range(len(C)):
  key=min(C[0],C[1])
  k+=key
  ans+=1
  C.remove(key)
  if k>=K:
    break
  if len(C)==1:
    k+=C[0]
    ans+=1
    break

if k==K:
  print(ans)
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()))

ni = 0
mi = 0
ans = 0
cnt = 0

def calc (a,b):
  ma = len(a)
  mb = len(b)

  i = 0
  while ma > i and mb > i:
    if a[i] > b[i]:
      return 0
    elif a[i] < b[i]:
      return 1
    i += 1

  return 0

for i in range(n+m):
  if n == ni and m == mi:
    break
  elif n == ni:
    ans += b[mi]
    mi += 1
  elif m == mi:
    ans += a[ni]
    ni += 1
  elif a[ni] == b[mi]:
    x = calc(a[ni:] ,b[mi:])
    if x == 0:
      ans += b[mi]
      mi += 1
    elif x == 1:
      ans += a[ni]
      ni += 1

  elif a[ni] < b[mi]:
    ans += a[ni]
    ni += 1
  else:
    ans += b[mi]
    mi += 1

  if ans <= k:
    cnt += 1
  else :
    break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()


from collections import deque  #listよりdequeの方が両端へのアクセスは計算量が少ない
def main():
    n, m, k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    e = [2 * (10 ** 9)] * max(n, m)
    a = a + [2 * (10 ** 9)] * m
    b = b + [2 * (10 ** 9)] * n
    ti = 0
    c = 0
    while c <= n + m:
        if a[0] <= b[0]:
            ti += a[0]
            a.pop(0)
            if ti > k:
                break
            c += 1
        else:
            ti += b[0]
            b.pop(0)
            if ti > k:
                break
            c += 1
    print(c)



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()))
sum_k=0
listAB=A+B
listAB.sort()
n=0
for i in range(len(listAB)):
    if sum_k<=K:
        sum_k+=listAB[i]
        n+=1
    else:
        n-=1
        break
print(n)

Submission status: Wrong Answer

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

    while len(A) and len(B):
        if A[0] > B[0]:
            b = B.popleft()
            if b > K: return ans
            K -= b
            ans +=1
        else:
            a = A.popleft()
            if a > K: return ans
            K -=a
            ans +=1

    while len(A):
        a = A.popleft()
        if a > K: return ans
        K -= a
        ans += 1
    while len(B):
        b = B.popleft()
        if b > K: return ans
        K -= b
        ans += 1
    return ans


print(m())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())

alist = input().split()
blist = input().split()

print(alist)
print(blist)

work = k
acount = 0
while (acount < n) and (work >= int(alist[acount])):
    work -= int(alist[acount])
    acount += 1

maxCount = acount
bCount = 0
for num in range(0, acount):
    if (num > 1):
        work += int(alist[acount-num])

    while (bCount < m) and (work >= int(blist[bCount])):
        work -= int(blist[bCount])
        bCount += 1
    maxCount = max(maxCount, acount-num+bCount)




print(maxCount)

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
len_A, len_B = len(A), len(B)
time, count = 0, 0
while time <= k:
    if i == len_A and j == len_B:
        break

    if i < len_A and j < len_B:
        if A[i] < B[j]:
            time += A[i]
            i += 1
        else:
            time += B[j]
            j += 1
    else:
        if i == len_A:
            time += B[j]
            j += 1
        else:
            time += A[i]
            i += 1

    if time > k:
        break
    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()))
A = A[::-1]
B = B[::-1]
ans = 0
while (K > 0):
  if len(A) == 0:
    K-= B.pop()
    ans += 1
    continue
  if len(B) == 0:
    K-= A.pop()
    ans += 1
    continue
  if A[-1] >= B[-1] and K - B[-1] >= 0:
    ans += 1
    K -= B.pop()
    continue
  elif B[-1] >= A[-1] and K - A[-1] >= 0:
    ans += 1
    K -= A.pop()
    continue
  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=0
j=0
c=0
while True:
  if i<n and j<m:
    if a[i]<b[j]:
      if k-a[i]>=0:
        k-=a[i]
        #print("k==",k)
        c+=1
        i+=1
      else:
        break
    else:
      if k-b[j]>=0:
        k-=b[j]
        #print("k==",k)
        c+=1
        j+=1
      else:
        break
  else:
      while i<n:
        if k-a[i]>=0:
            k-=a[i]
            c+=1
            i+=1
        else:
            break
    
      while j<m:
        if k-b[j]>=0:
            k-=b[j]
            c+=1
            j+=1
        else:
            break
      break
        
        
        
print(c)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate 

n,m,k=map(int,input().split())
alst=list(accumulate(list(map(int,input().split()))))
blst=list(accumulate(list(map(int,input().split()))))
#print(alst)
#print(blst)

mx=0
for i in range(len(blst)-1,-1,-1):
    if blst[i]<=k : mx=i+1;break

for i in range(len(alst)):
#    print(i,mx)
    work=k-alst[i]
    if work<0 : break
    if i+1>=mx :
        for j in range(len(blst)):
            if blst[j]>work : mx=i+1+j;break
    else:
        if work<=blst[mx-i-2]: continue
        for j in range(mx-i-1,len(blst)):
            if blst[j]>work : mx=i+1+j;break
        else : mx=i+1+len(blst)

print(mx)

Submission status: Wrong Answer

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

a_count = 0
b_count = 0
ans = 0
time = 0
flag = True
while flag:
    ans+=1
    if a_count < n and b_count < m:
        if a[a_count] < b[b_count]:
            time += a[a_count]
            a_count+=1

        else:

            time += b[b_count]
            b_count+=1

    elif a_count < n and b_count >= m:
        time += a[a_count]
        a_count+=1
    elif a_count >= n and b_count <m:
        time += b[b_count]
        b_count += 1
    else:
        flag = False    
    if time>k:
        ans -= 1
        flag = False

print(ans)

Submission status: Wrong Answer

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

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

i_a = 0
i_b = 0
time = 0
cnt = 0

while i_a < len(A_list)  and  i_b < len(B_list):
    if A_list[i_a] <= B_list[i_b]:
        time += A_list[i_a]
        i_a += 1
        cnt += 1
    else:
        time += B_list[i_b]
        i_b += 1
        cnt += 1
    
    if time > K:
        print(cnt -1)
        sys.exit()


if i_a == len(A_list)  and  i_b < len(B_list):
    i_x = i_b
    X = B_list
elif i_a < len(A_list)  and  i_b == len(B_list):
    i_x = i_a
    X = A_list


while i_x < len(X):
    time += X[i_x]
    i_x += 1
    cnt += 1
    
    if time > K:
        print(cnt -1)
        sys.exit()


print(cnt)

Submission status: Wrong Answer

Solution code:

def main():
    time= list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    nokori=time[2]
    A.append(200001)
    B.append(200001)
    count=0
    while(True):
        if A[0]>nokori and B[0]>nokori:
            print(count)
            break
        if nokori<=0:
            print(count)
            break
        if B[0]==200001 and A[0]==200001:
            print(count)
            break
        if A[0]>B[0] and B[0]!=200001:
            nokori=nokori-B[0]
            del B[0]
            count=count+1
        elif A[0]<B[0] and A[0]!=200001:
            nokori=nokori-A[0]
            del A[0]
            count=count+1

if __name__ == '__main__':
    main()

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()))
C=A+B
d=0
C.sort()
if sum(C)<=K :
    print(len(C))
    sys.exit()
for i in range(len(C)) :
    d=d+C[i]
    if d>K :
        print(i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
M,N,K = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
B = [int(hoge) for hoge in input().split()]
S = 0
Abook = 0
Bbook = 0
curbook = 0
for a in A:
    if S + a <= K:
        Abook += 1
        curbook += 1
        S += a
nextB = 0
for n,b in enumerate(B):
    if S + b <= K:
        Bbook += 1
        curbook += 1
        S += b
    else:
        nextB = n
        break
ans = curbook

for i in range(Abook):
    Abook -= 1
    curbook -= 1
    S -= A[Abook]
    for b_index in range(nextB,len(B)):
        if S + B[b_index] <= K:
            Bbook += 1
            curbook += 1
            S += B[b_index]
        else:
            nextB = b_index
            break
    ans = max(ans,curbook)
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()))
ans = 0
time = 0
n = 0
m = 0
for i in range(N+M):
    if n < N and m < M:
        if A[n] <= B[m]:
            time += A[n]
            n += 1
        else:
            time += B[m]
            m += 1
    else:
        if n >= N and m >= M:
            break
        elif n == N -1 and m < M:
            time += B[m]
            m += 1
        elif m == M -1 and n < N:
            time += A[n]
            n += 1
    if time < K:
        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()))
A.append(10**10)
B.append(10**10)
i=0
j=0
total = 0
for k in range(N+M):
    a = A[i]
    b = B[j]
    if a < b and total+a<=K:
        total += a
        i += 1
    elif a > b and total+b<=K:
        total += b
        j += 1
    else:
        break
print(i+j)

Submission status: Wrong Answer

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

from itertools import accumulate
aa=list(accumulate(a))
bb=list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n):
    if k<aa[i]:
        break
    kk=k-aa[i]
    k2=bisect(bb,kk)
#    print(i,k2)
    kmax=max(kmax,k2+i+1)

print(kmax)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,L = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
cnt = 0
while True:
    if L < 0:
        cnt -= 1
        break
    else:
        if len(A) != 0 and len(B) != 0:
            if A[0] == B[0]:
                if len(A) >= 2 and len(B) >= 2:
                    if A[1] < B[1]:
                        tmp = A.popleft()
                    else:
                        tmp = B.popleft()
                elif len(A) >= 2 and len(B) < 2:
                    tmp = A.popleft()
                elif len(A) < 2 and len(B) >= 2:
                    tmp = B.popleft()
                else:
                    tmp = A.popleft()
            elif A[0] < B[0]:
                tmp = A.popleft()
            else:
                tmp = B.popleft()
        elif len(A) != 0 and len(B) == 0:
            tmp = A.popleft()
        elif len(A) == 0 and len(B) != 0:
            tmp = B.popleft()
        else:
            break
        L -= tmp
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i, j = 0, 0
    while K > 0:
        print(i,j)
        if i == N:
            if j != M:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                i = N
                j = M
                break

        elif j == M:
            if i != N:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
            else:
                i = N
                j = M
                break
        else:
            if A[i] >= B[j]:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
    print(i+j)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
pa = abs(N-M) + 1
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
while K >= A[0] or K >= B[0]:
    if A[0] < B[0]:
        K -= A.pop(0)
    else:
        K -= B.pop(0)
    c += 1
    if len(A) == 0:
        A = A + [1000000010]
    if len(B) == 0:
        B = B + [1000000010]
print(c)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]

    a.append(10**9+1)
    b.append(10**9+1)
    cnt_a = 0
    cnt_b = 0
    cumsum = 0

    while cumsum <= k:
        if a[cnt_a] > b[cnt_b]:
            cumsum += b[cnt_b]
            if cumsum > k:
                break
            cnt_b += 1
        else:
            cumsum += a[cnt_a]
            if cumsum > k:
                break
            cnt_a += 1
    print(cnt_a + cnt_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()))
counter = 0

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left, bisect_right
import sys

input = sys.stdin.buffer.readline
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AA = list(accumulate([0] + A))
BB = list(accumulate([0] + B))
apos = bisect_right(A, k)

# bpos = bisect_right(B, k)
# j = 0
ans = 0
for i in range(apos, -1, -1):
    temp_a = AA[i]
    remain = k - temp_a
    pos = bisect_left(BB, remain)
    if pos == m + 1:
        pass
    else:
        if BB[pos] == remain:
            pos += 1
    pos = max(pos - 1, 0)
    ans = max(ans, i + pos)
    # while j <= bpos:
    #     if remain >= BB[j]:
    #         j += 1
    #     else:
    #         break
    # ans = max(ans, i + j - 1)
    # print(i, pos)
print(ans)