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

t_a = 0
a_a= []
for i in range(n):
    if t_a + a[i] <= k:
        t_a += a[i]
        a_a.append(t_a)
    else:
        break

t_b = 0
a_b = []
for j in range(m):
    if t_b + b[j] <= k:
        t_b += b[j]
        a_b.append(t_b)
    else:
        break

t = [0]
for i in range(len(a_a)):
    for j in range(len(a_b)):
        if a_a[i] + a_b[j] <= k:
            t.append(i+j+2)

print(max(t))

Submission status: Wrong Answer

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

a_cusum = list(itertools.accumulate(a))
#print(a_cusum)
ok = len(a_cusum)
ng = 0
while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    #print(mid,ok,ng,a_cusum[mid])
    if a_cusum[mid] > k:
        ok = mid
    else:
        ng = mid
a_max=ok

b_cusum = list(itertools.accumulate(b))
#print(b_cusum)
ok = len(b_cusum)
ng = 0
while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    #print(mid,ok,ng,b_cusum[mid])
    if b_cusum[mid] > k:
        ok = mid
    else:
        ng = mid
b_max=ok


for i in range(0,a_max):
    for j in range(b_max-1,-1,-1):
        if a_cusum[i] + b_cusum[j] <= k:
            if result < i + j + 2:
                #print(i,j,a_cusum[i], b_cusum[j] )
                result = i + j + 2
print(result)

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]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

if sum(list_)<=k:
  print(len(list_))
else:
  left = 0
  right = len(list_)+1
  while abs(left-right)>1:
    mid = (left+right) // 2
    if sum(list_[:mid])<k:
      left = mid
    else:
      right = mid

  print(left)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=map(int,input().split())
A=list(A)
B=map(int,input().split())
B=list(B)
time=int(0)
book=int(0)
ia=0 #iaは1~N冊
jb=0 #jbは1~M冊
while time<K and ia<N and jb<M:
    if A[ia]<=B[jb]:
        time += A[ia]
        book += 1
        ia+=1
        if ia==N:
            break
    else:
        time += B[jb]
        book +=1
        jb +=1
        if jb==M:
            break
if time<K and ia==N:
    while time<=K and jb<M:
        time+=B[jb]
        book+=1
        jb+=1
        if jb==M:
            break
elif time<K and jb==M:
    while time<K and ia<N:
        time+=A[ia]
        book+=1
        ia+=1
        if ia==N:
            break
if time<=K:
    print(book)
else:
    print(book-1)

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

if (N>10**7) | (M>10**7) |(K>10**7):
    print(0)
else:
    time=0
    a_idx=0
    b_idx=0
    count=0
    while time<K:
        count+=1
        try:
            if a_idx+1==N:
                time+=b[b_idx]
                b_idx+=1
                if time>K:
                    count-=1
                continue
            elif b_idx+1==M:
                time+=a[b_idx]
                a_idx+=1
                if time>K:
                    count-=1
                continue    

            if a[a_idx]<b[b_idx]:
                time+=a[a_idx]
                a_idx+=1

            elif a[a_idx]>b[b_idx]:
                time+=b[b_idx]
                b_idx+=1
            else:
                try:
                    a_com=a_idx
                    b_com=b_idx
                    while True:
                        if a[a_com]>b[b_com]:
                            time+=a[a_idx]
                            a_idx+=1
                            break
                        elif a[a_com]<b[b_com]:
                            time+=b[b_idx]
                            b_idx+=1
                            break
                        a_com+=1
                        b_com+=1
                except:
                    time+=a[a_idx]
                    a_idx+=1
            if time>K:
                count-=1            
        except:
            break
    print(count)

Submission status: Wrong Answer

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

first = input()
firstlist = first.split()

second = input()
secondlist = second.split()

third = firstlist + secondlist

third.sort()
sum = 0
count = 0
while int(K) > sum:
    if int(K) > int(third[0]):
        for i in range(len(third)):
            if int(K) > sum:
                sum = sum + int(third[i])
                count = count + 1
            elif int(K) < sum:
                break
    else:
        count = 0
        break

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate

n, m, k = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]

goukei = 0
kaisu = 0
new = []
for i in range(n + m):
  if goukei <= k:
    if len(a) == 0:
      goukei += b[0]
      b.pop(0)
      kaisu += 1
    elif len(b) == 0:
      goukei += a[0]
      a.pop(0)
      kaisu += 1
    elif a[0] <= b[0]:
      goukei += a[0]
      a.pop(0)
      kaisu += 1
    elif a[0] > b[0]:
      goukei += b[0]
      b.pop(0)
      kaisu += 1
  else:
    break;
print(kaisu)
"""
new = list(accumulate(new))
for x in range(len(new)):
  if new[x] <= k:
    goukei += 1

print(goukei)
"""

Submission status: Wrong Answer

Solution code:
def resolve():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split())) 
    B = list(map(int, input().split()))
    
    ans = 0
    total = 0
    i = 0
    j = 0
    for _ in range(n+m):
        if i < n:
            a = A[i]
        else:
            a = 10**9 + 1
        if j < m:
            b = B[j]
        else:
            b = 10**9 + 1
        total += min(a, b)
        if min(a, b) == a:
            i += 1
        else:
            j += 1
        if total > k:
            break
        else:
            ans += 1
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    weightA = 0
    tmp_A = N
    for idx, a in enumerate(A):
        if weightA + a > K:
            tmp_A = idx
            break
        else:
            weightA += a
    max_count = current_count = tmp_A
    len_A = tmp_A

    weightB = 0
    terminated = False
    for b in B:
        if terminated == True and weightA + weightB > K:
            break

        if len_A==0 and weightA + weightB + b > K:
            break

        if weightA + weightB + b <= K:
            weightB += b
            current_count += 1

        elif terminated==False:
            while weightA + weightB + b > K:
                if len_A>0:
                    weightA -= A[len_A-1]
                    len_A -= 1
                    current_count -= 1
                else:
                    terminated=True

            if weightA + weightB + b <= K:
                weightB += b
                current_count += 1
        if current_count < max_count:
            break
        max_count = max(max_count, current_count)

    print(max_count)
    return


def solve_old(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    weightA = 0
    tmp_A = N
    for idx, a in enumerate(A):
        if weightA + a > K:
            tmp_A = idx
            break
        else:
            weightA += a
    max_count = current_count = tmp_A
    len_A = tmp_A

    weightB = 0
    terminated = False
    for b in B:
        if terminated == True and weightA + weightB > K:
            break

        if len_A==0 and weightA + weightB + b > K:
            break

        if weightA + weightB + b <= K:
            weightB += b
            current_count += 1

        elif terminated==False:
            while weightA + weightB + b > K:
                if len_A>0:
                    weightA -= A[len_A-1]
                    len_A -= 1
                    current_count -= 1
                else:
                    terminated=True

            if weightA + weightB + b <= K:
                weightB += b
                current_count += 1
        max_count = max(max_count, current_count)

    print(max_count)
    return

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

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()))
from collections import deque

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

t=0
ans=0

while t<=k:
  if a:
    a_c=a[0]
  else:
    a_c=10**18
  if b:
    b_c=b[0]
  else:
    b_c=10**18

  if a_c<=b_c:
    ans+=1
    t+=a_c
    if a:
      a.popleft()
  else:
    ans+=1
    t+=b_c
    if b:
      b.popleft()

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()))
a = 0
b = 0
t_sum = 0
cnt = 0
flag = True

for _ in range(N+M):
  if A[a] <= B[b]:
    t_sum += A[a]
    cnt += 1
    a += 1
  elif A[a] > B[b]:
    t_sum += B[b]
    cnt += 1
    b += 1
  if t_sum > K:
    cnt -= 1
    break
  if a == N:
    for _ in range(M+1):
      if b == M:
        flag = False
        break
      t_sum += B[b]
      cnt += 1
      b += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if b == M:
    for _ in range(N+1):
      if a == N:
        flag = False
        break
      t_sum += A[a]
      cnt += 1
      a += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
print(cnt)

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]
count = time = sel = 0
while time <= K:
  if len(A) == len(B) == 0:
    break
  if len(B) == 0:
    if K >= time + A[-1]:
      count += 1
      time += A[-1]
      A.pop()
      continue
    else:
      break
  if len(A) == 0:
    if K >= time + B[-1]:
      count += 1
      time += B[-1]
      B.pop()
      continue
    else:
      break 
  if A[-1] <= B[-1]:
    if K >= time + A[-1]:
      count += 1
      time += A[-1]
      A.pop()
    else:
      break
  else:
    if K >= time + B[-1]:
      count += 1
      time += B[-1]
      B.pop()
    else:
      break
print(count)

Submission status: Wrong Answer

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

N,M,K=(int(x) for x in input().rstrip('\n').split())
As=[int(x) for x in input().rstrip('\n').split()]
Bs=[int(x) for x in input().rstrip('\n').split()]
res = 0
now = 0
now_a = 0
now_b = 0
for i in range(N+M):
  if now_a==len(As):
    c=0
    if now_b==len(Bs):
      break
    else:
      c=0
  elif now_b==len(Bs):
    c=1
  elif As[now_a]!=Bs[now_b]:
    if As[now_a]<Bs[now_b]:
      c=1
    else:
      c=0
  else:
    nex_a=now_a+1
    nex_b=now_b+1
    if all(x==y for x,y in zip(As[now_a:],Bs[now_b:])):
      c=1
    else:
      while 5572>573:
        if nex_a==len(As):
          c=0
          break
        elif nex_b==len(Bs):
          c=1
          break
        else:
          if As[nex_a]<Bs[nex_b]:
            c=1
            break
          elif As[nex_a]>Bs[nex_b]:
            c=0
            break
          else:
            nex_a+=1
            nex_b+=1
  if c == 1:
    now += As[now_a]
    now_a += 1
  else:
    now += Bs[now_b]
    now_b += 1
  if now>K:
    break
  res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    
    n,m,k = map(int, input().split())
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    i,j,count = 0,0,0

    while(k>0):

        
        if count == n+m:
            break

        if i < n and j < m:

            if n_list[i] < m_list[j]:
                k -= n_list[i]
                count += 1
                i += 1
            else:
                k -= m_list[j]
                count += 1
                j += 1
            
            if k < 0:
                count -= 1
                break

        else:
            if i >= n:
                if j >= m:
                    break
                k -= m_list[j]
                count += 1
                j += 1

            elif j >= m:
                if i >= n:
                    break
                k -= n_list[i]
                count += 1
                i += 1

            if k < 0:
                count -= 1
                break

    print(count)



            

if __name__ == "__main__":
    main()

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 = 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:
    k -= a.pop(0) if a[0] > b[0] else b.pop(0)
  c += 1
  
print(c)

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

import numpy as np

a =[]
flag = True
while flag:
    if not A and not B:
        flag = False
    elif not A:
        if B[0] >= K:
            break
        else:
            a.append(B[0])
            B = B[1:]
    elif not B:
        if A[0] >= K:
            break
        else:
            a.append(A[0])
            A = A[1:]
    elif A[0] >= K or B[0] >= K:
        flag = False
    elif A[0] <= B[0]:
        a.append(A[0])
        A = A[1:]
    else:
        a.append(B[0])
        B = B[1:]

res = np.cumsum(a)
r = list(res)

cnt = 0
for i in r:
    if i <= K:
        cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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 LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

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

    i, j, ans, cum = 0, 0, 0, 0

    while True:
        if (i < N) and (j < M):
            if (cum + A[i] <= K) and (cum + B[j] <= K):
                if A[i] <= B[j]:
                    cum += A[i]
                    i += 1
                else:
                    cum += B[j]
                    j += 1
            elif cum + A[i] <= K:
                cum += A[i]
                i += 1
            elif cum + B[j] <= K:
                cum += B[j]
                j += 1
            else:
                break
            ans += 1
        elif i < N:
            if cum + A[i] <= K:
                cum += A[i]
                i += 1
                ans += 1
            else:
                break
        elif j < M:
            if cum + B[j] <= K:
                cum += B[j]
                j += 1
                ans += 1
            else:
                break
        else:
            break

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

readline = sys.stdin.readline

n, m , k = map(int, readline().split())
a = deque(map(int, readline().split()))
b = deque(map(int, readline().split()))
ans = 0
while True:
    if not a and not b:
        print(ans)
        sys.exit()
    elif not a:
        x = b.popleft()
        if k < x:
            print(ans)
            sys.exit()
        else:
            k -= x
            ans += 1
    elif not b:
        x = a.popleft()
        if k < x:
            print(ans)
            sys.exit()
        else:
            k -= x
            ans += 1
    elif a[0] < b[0]:
        x = a.popleft()
        if k < x:
            print(ans)
            sys.exit()
        else:
            k -= x
            ans += 1
    else:
        x = b.popleft()
        if k < x:
            print(ans)
            sys.exit()
        else:
            k -= x
            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()))

c = 0
time = 0

while True:
    if len(a) == 0:
        time += b[0]
        c += 1
        del b[0]
    
    elif len(b) == 0:
        time += a[0]
        c += 1
        del a[0]
    
    elif a[0] > b[0]:
        time += b[0]
        c += 1
        del b[0]
    
    elif a[0] < b[0]:
        time += a[0]
        c += 1
        del a[0]
    
    elif a[0] == b[0]:
        if len(a) == 1:
            time += b[0]
            c += 1
            del b[0]
        
        elif len(b) == 1:
            time += a[0]
            c += 1
            del a[0]
        
        elif a[1] > b[1]:
            time += b[0]
            c += 1
            del b[0]
        
        elif b[1] > a[1]:
            time += a[0]
            c += 1
            del a[0]
        
        elif b[1] == a[1]:
            time += a[0]
            c += 1
            del a[0]
    
    if time > k:
        c -= 1
        break
    
    if c == n+m:
        break
    
print(c)

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(K + 1)
B.append(K + 1)
ia, ib = 0, 0
time = 0
flag = True
while flag:
    flag = False
    if A[ia] <= B[ib] and time + A[ia] <= K:
        time += A[ia]
        ia += 1
        flag = True
    if B[ib] < A[ia] and time + B[ib] <= K:
        time += B[ib]
        ib += 1
        flag = True
print(ia + ib)

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

flag = True
que = list()

while True:
    a = b = val = -1
    if len(A) > 0:
        a = A[0]
    if len(B) > 0:
        b = B[0]

    if a < 0 and b < 0:
        break
    elif a > 0 and b > 0:
        if a < b:
            val = A.pop(0)
        else:
            val = B.pop(0)
    elif a < 0 and b > 0:
        val = B.pop(0)
    elif a > 0 and b < 0:
        val = A.pop(0)

    if sum(que) + val <= K:
        que.append(val)
    else:
        break

print(len(que))

Submission status: Wrong Answer

Solution code:
#create date: 2020-06-27 22:08

import sys
stdin = sys.stdin
from itertools import accumulate
from bisect import bisect_left, bisect_right

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, k = na()
    a = na()
    b = na()
    i1, i2 = 0, 0
    c = list()
    for i in range(n+m-1):
        if i1 == n:
            c.append(b[i2])
            i2 += 1
        elif i2 == m:
            c.append(a[i1])
            i1 += 1
        elif a[i1] <= b[i2]:
            c.append(a[i1])
            i1 += 1
        else:
            c.append(b[i2])
            i2 += 1
        #print(i1, i2, c)
    if i1 == n:
        c.append(b[i2])
    else:
        c.append(a[i1])
    #print(c)
    cum = list(accumulate(c))
    #print(cum)

    print(bisect_right(cum, k))

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

while c<=K:
    if not A and not B:
        d+=1
        break
    elif not A:
        d+=1
        c+=B.pop(0)
    elif not B:
        d+=1
        c+=A.pop(0)
    else:
        if A[0]<=B[0]:
            d+=1
            c+=A.pop(0)
        else:
            d+=1
            c+=B.pop(0)
print((d-1))

Submission status: Wrong Answer

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

A.append(10**10)
B.append(10**10)

#print(A)
#print(B)
time = 0
ans = 0

i, j = 0, 0
if int(A[0]+0.5)>int(K+0.5) and int(B[0]+0.5)>int(K+0.5):
    print(0)
    sys.exit()
else:
    for _ in range(len(A)+len(B)-2):
        if int(A[i]+0.5) <= int(B[j]+0.5):
            time += A[i]
            if int(time+0.5) <= int(K+0.5):
                ans += 1
                i += 1
            else:
                break
        elif int(A[i]+0.5) > int(B[j]+0.5):
            time += B[j]
            if int(time+0.5) <= int(K+0.5):
                ans += 1
                j += 1
            else:
                break
        #print(i,j,time)
print(ans)

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
import numpy as np

def binary_search(lis, item):
    low = 0
    high = len(lis) - 1
    inRange = high

    while low <= high:
        mid = (low + high) //2
        guess1 = lis[mid]
        if mid < inRange:
            guess2 = lis[mid+1]
        else:
            if lis[mid] <= item:
                return len(lis)
            else:
                return len(lis)-1
        if guess1 <= item < guess2:
            return mid+1
        if guess1 > item:
            high = mid-1
        else:
            low = mid
    return 0

n,m,k = iim()
a = iil()
cuma = []
if a[0] <= k:
    cuma.append(a[0])
    for i in range(n-1):
        num = cuma[-1]+a[i+1]
        if num > k:
            break
        else:
            cuma.append(num)
b = iil()
cumb = []
if b[0] <= k:
    cumb.append(b[0])
    for i in range(m-1):
        num = cumb[-1]+b[i+1]
        if num > k:
            break
        else:
            cumb.append(num)
if len(cuma) > 0:
    cnt = len(cuma)
    ans = cnt+binary_search(cumb,k-cuma[-1])
    #print(k-cuma[-1],binary_search(cumb,k-cuma[-1]))
    for i,item in enumerate(cuma[::-1]):
        tmp = cnt-i
        res = k-item
        plus = binary_search(cumb,res)
        ans = max(ans,tmp+plus)
else:
    ans = binary_search(cumb,k)
print(ans)

#print(binary_search([1,2,3,4,5,6,7,8,9,10],8))

Submission status: Wrong Answer

Solution code:
def main():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    
    A_sum = 0
    A_max = N
    tmp_sum = 0
    for i in range(N):
        tmp_sum += A[i]
        if tmp_sum > K:
            A_max = i
            break
        else:
            A_sum = tmp_sum
        
    ans = A_max
    tmp_ans = ans
    #B_sum = 0
    B_i = 0
    time = K - A_sum
    count = 0
    for i in range(-1,A_max):
        if i != -1:
            A_i = A_max -1 -i
            time += A[A_i]
            count = -1
        tmp_time = time
        next_B_i = B_i
        for j in range(B_i,M):
            tmp_time -= B[j]
            if tmp_time >= 0:
                next_B_i += 1
                count += 1
                time = tmp_time
            else:
                break
                
        B_i = next_B_i
        tmp_ans += count
        if count > 0:
            ans = tmp_ans
        #print(tmp_ans)
            
    print(ans)
    
if __name__ == '__main__':
    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()))

c=deque()
d=deque()
c.extend(a)
d.extend(b)

sum=0
ans=0
while(sum<=k):
    if len(c)==0 and len(d)>0:
        sum+=d.popleft()
        ans+=1
    elif len(d)==0 and len(c)>0:
        sum+=c.popleft()
        ans+=1

    elif len(d)>0 and len(c)>0:
        if c[0]<=d[0]:
            sum+=c.popleft()
            ans+=1
        else:
            sum+=d.popleft()
            ans+=1
    else:
        break
if sum>k:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = input().split()
np_a=np.array(a, dtype='int64')
b = input().split()
np_b=np.array(b, dtype='int64')

ia=0
ib=0
time=0
hon=n+m
for i in range(0,n+m):
  if (ia == n): 
    time+=np_b[ib]
    ib+=1
  elif (ib == m): 
    time+=np_a[ia] 
    ia+=1
  elif (): 
    if (np_a[ia] <= np_b[ib]):
      time+=np_a[ia]
      ia+=1
    else:
      time+=np_b[ib]
      ib=+1

  if (time > k): 
    hon=i
    break

print (hon)

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
f,t=0,0
x.sort()
y.sort()
for i in range(n):
    if i<n and cost<k and cost+x[i]<=k and f==0:
        cost+=x[i]
        c+=1
    else:f=1
    if i<m and  cost<k and cost+y[i]<=k and t==0:
        cost+=y[i]
        c+=1
    else:t=1
i+=1
if m>n and t==0:
    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:
N,M,K = map(int,input().split())
Ali = list(map(int,input().split()))
Bli = list(map(int,input().split()))

ans=0

if (sum(Ali)+sum(Bli))==K: 
    print(N+M)
    exit()
if (sum(Ali)+sum(Bli))>K:
    print(0)
    exit()
while K>0 or (Ali!=[] and Bli!=[]) :

    if Ali[0]<Bli[0] and Ali != []:
        a=Ali.pop(0)
    elif Bli!=[]:
        a=Bli.pop(0)
    K -= a
    ans+=1

print(ans-1)

Submission status: Wrong Answer

Solution code:
N,M,K = input().split()
n = int(N)
m = int(M)
k = int(K)

listA = [int(x) for x in input().split()]
listB = [int(y) for y in input().split()]

a = 0
b = 0
total = 0
counter = 0

while k >= total:
    if a == len(listA) and b != len(listB):
        total = total + listB[b]
        b = b + 1
        counter = counter + 1

    elif b == len(listB) and a != len(listA):
        total = total + listA[a]
        a = a + 1
        counter = counter + 1

    elif a == len(listA) and b == len(listB):
        counter = counter + 1
        break

    else:
        if listA[a] >= listB[b]:
            total = total + listB[b]
            b = b + 1
            counter = counter + 1
                
        elif listA[a] <= listB[b]:
            total = total + listA[a]
            a = a + 1
            counter = counter + 1

counter = counter - 1

Submission status: Wrong Answer

Solution code:
n , m , k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
x = 0
num = 0
for i in range(n+m):
    if x <= k :
        num += 1
        if len(a_list) == 0:
            y = b_list.pop(0)
            x += y
        elif len(b_list) == 0:
            y = a_list.pop(0)
            x += y
        else :
            if a_list[0] <= b_list[0]:
                y = a_list.pop(0)
                x += y
            else :
                y = b_list.pop(0)
                x += y
print(num)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import deque

def main():
    n, m, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    b_lst = list(map(int, input().split()))
    if n < m:
        a_lst, b_lst = b_lst, a_lst
        n, m = m, n

    a_time = [0]
    b_time = []

    t = 0
    for a in a_lst:
        t += a
        if t > k:
            break
        a_time.append(t)
    t = 0
    for b in b_lst:
        t += b
        if t > k:
            break
        b_time.append(t)

    a_que = deque(a_time)
    b_que = deque(b_time)
    cnt = len(a_que)
    c_max = cnt - 1
    if b_que:
        b = b_que.popleft()
        while c_max <= cnt and a_que:
            cnt -= 1
            a = a_que.pop()
            while a + b <= k:
                cnt += 1
                c_max = cnt
                if b_que:
                    b = b_que.popleft()
                else:
                    break
            else:
                continue
            break

    print(c_max)


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()))
ans=0
while 1:
  if len(a)==0 or len(b)==0:
    if len(a)==0:
      while len(b)!=0 and k>=b[0]:
        k-=b.pop(0)
        ans+=1
    else:
      while k>=a[0]:
        k-=a.pop(0)
        ans+=1
    break
  if a[0]>b[0]:
    read=b.pop(0)
  else:
    read=a.pop(0)
  if read<=k:
    k-=read
    ans+=1
  else:
    break
print(ans)