Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')

#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m,k=mii()
arra=[0]+limii()
arrb=[0]+limii()

cuma=np.cumsum(arra)
cumb=np.cumsum(arrb)
ans=0
cnt=0
tmp=0
placea=0
for i in cuma:
    if i<=k:
        tmp=i
        placea+=1
        ans+=1
        cnt+=1
    else:
        continue
#print(cnt,tmp,ans,placea)
placeb=0
for i in arrb:
    #print(i)
    if tmp+i<=k:
        tmp+=i
        cnt+=1
        #print(1111111)
    else:
        while i+cuma[placea-1]>k:
            placea-=1
            cnt-=1
            
            if placea<1:
                break
        #print(1111)
    ans=max(ans,cnt)
    if placea<1:
        break
print(ans-2)

Submission status: Wrong Answer

Solution code:
###############################################
#                                             #
#   author: raghav_0901 (Raghav Dalmia)       #
#   updated on: 27-06-2020,  6:32:14 pm IST   #
#                                             #
###############################################

from math import *

inf = 10**10


def _in():
    return [int(x) for x in input().split(' ')]


if __name__ == "__main__":
    n, m, k = _in()

    a = _in()
    b = _in()

    cnt, time = 0, 0
    i, j = 0, 0
    while(time <= k and cnt < n + m):
        if(i == n):
            time = time + b[j]
            cnt = cnt + 1
            j = j + 1
        elif(j == m):
            time = time + a[i]
            cnt = cnt + 1
            i = i + 1
        elif(a[i] < b[j]):
            time = time + a[i]
            cnt = cnt + 1
            i = i + 1
        else:
            time = time + b[j]
            cnt = cnt + 1
            j = j + 1
    if(time > k):
        cnt = cnt - 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int, input().split())
    alis = list(map(int, input().split()))
    blis = list(map(int, input().split()))
    adic = {}
    bdic = {}
    for i in range(len(alis)):
        adic[i+1] = alis[i]
    for i in range(len(blis)):
        bdic[i+1] = blis[i]

    time = 0
    ans = 0
    a = 1
    b = 1
    while time< k:
        #print(alis, blis, len(alis), k, time)
        if a > len(adic) and b > len(bdic):
            break
        elif a > len(adic) and bdic[b] <= k-time:
            time += bdic[b]
            b += 1
            ans += 1
        elif b > len(bdic) and adic[a] <= k-time:
            time += adic[a]
            a += 1
            ans += 1
        elif a > len(adic) and bdic[b] > k-time:
            break
        elif b > len(bdic) and adic[a] > k-time:
            break
        
        else:
            #print(alis, blis)
            if adic[a] <= bdic[b] and time + adic[a] <= k:
                #print(time, alis[0], blis[0])
                time += adic[a]
                a += 1
                ans += 1
            elif adic[a] > bdic[b] and time + bdic[b] <= k:
                #print(time)
                time += bdic[b]
                b += 1
                ans += 1
            else:
                break


    print(ans)

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

ai =0
bi=0
st =0
c = 0
while True:
  if ai == N:
    if bi == M:
      break
    else:
      st += b[bi]
      if st > K:
        break
      bi += 1
      c +=1
  elif bi == M:
    if ai == N:
      break
    else:
      st += a[ai]
      if st > K:
        break
      ai += 1
      c += 1
  elif a[ai] > b[bi]:
    st += b[bi]
    if st > K:
      break
    bi +=1
    c +=1
  elif a[ai] < b[bi]:
    st += a[ai]
    if st > K:
      break
    ai +=1
    c +=1
  elif a[ai] == b[bi]:
    tmpst = st
    tmpc =0
    tmpai = ai
    tmpbi = bi
    while True:
      tmpst +=a[tmpai]
      if tmpai < N-1:
        tmpai+=1
      if tmpbi < M-1:
        tmpbi+=1
      if tmpst > K:
        st += a[ai]
        if st > K:
          print(c)
          exit()
        ai +=1
        c +=1
        #print(c+tmpc,'ja')
        #exit()
      if a[tmpai] > b[tmpbi]:
          st += b[bi]
          if st > K:
              print(c)
              exit()
          bi += 1
          c += 1
          break
      elif a[tmpai] < b[tmpbi]:
          st += a[ai]
          if st > K:
              print(c)
              exit()
          ai += 1
          c += 1
          break
      if tmpai == N-1 and tmpbi == M-1:
          print(N+M)
          exit()
      #print(tmpst)
      tmpc += 1
      #print(tmpai, tmpbi)
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

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

    k -= int(temp)
    if k >= 0:
        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()))
dp = [[0] * (M + 1) for _ in range(N + 1)]
dp[0][0] = 0
MN = 0
a, b = 0, 0
L = max(N, M)
for i in range(1, L + 1):
    if i <= N and i <= M:
        dp[i][i - 1] = dp[i - 1][i - 1] + A[i - 1]
        if K >= dp[i][i - 1] >= MN:
            MN = dp[i][i - 1]
            if 2 * i - 1 > a + b:
                a, b = i, i - 1
        dp[i - 1][i] = dp[i - 1][i - 1] + B[i - 1]
        if K >= dp[i - 1][i] >= MN:
            MN = dp[i - 1][i]
            if 2 * i - 1 > a + b:
                a, b = i, i - 1
        dp[i][i] = dp[i - 1][i - 1] + A[i - 1] + B[i - 1]
        if K >= dp[i][i] >= MN:
            MN = dp[i][i]
            if 2 * i > a + b:
                a, b = i, i
    elif i <= M:
        dp[N][i] = dp[N][i - 1] + B[i - 1]
        if K >= dp[N][i] >= MN:
            MN = dp[N][i]
            if N + i > a + b:
                a, b = N, i
    else:
        dp[i][M] = dp[i - 1][M] + A[i - 1]
        if K >= dp[i][M] >= MN:
            MN = dp[i][M]
            if i + M > a + b:
                a, b = i, M
print(a + b)

Submission status: Wrong Answer

Solution code:
nmk=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
k=nmk[2]
time=0
cnt=0
while time<=k:
  if len(b)==0:
    time+=a[-1]
    _=a.pop(-1)
    cnt+=1
  elif len(a)==0:
    time+=b[-1]
    _=b.pop(-1)
    cnt+=1
  elif a[-1]<=b[-1]:
    time+=a[-1]
    _=a.pop(-1)
    cnt+=1
  elif a[-1]>b[-1]:
    time+=b[-1]
    _=b.pop(-1)
    cnt+=1
#  print(a,b,time)
  if time>k:
    cnt-=1
  if len(a)==0 and len(b)==0:
    break
print(cnt)

Submission status: Wrong Answer

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

a = list(map(int , input().split()))

b = list(map(int , input().split()))

s = 0
c = 0
x = 0
mod = 10**9 + 7
while True:
    if len(a)!=0 and len(b) != 0:
        if a[0] < b[0]:
            x = a[0]
            a.pop(0)
        else:
            x = b[0]
            b.pop(0)

    elif len(a)!= 0:
        x = a[0]
        a.pop(0)
    
    elif len(b)!= 0:
        x = b[0]
        b.pop(0)

    s = (s%mod + x%mod)%mod

    if s<=k :
        c += 1
    else:
        s -= x 
        break 

# print(s)
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()))
cnt=0
time=0
lst=[]

for i in range(n+m+1):
    if not a and not b:
        pass
    elif not a:
        lst.extend(b)
        b.clear()
        pass
    elif not b:
        lst.extend(a)
        a.clear()
        pass
    else:
        book_min=min(a[0],b[0])
        if book_min==a[0]:
            lst.append(a[0])
            a.pop(0)
        elif book_min==b[0]:
            lst.append(b[0])
            b.pop(0)

for j in range(len(lst)):
    t=lst[j]
    if t+time>k:
        break
    else:
        cnt+=1
        time+=t

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
i = 0
j = 0
while k > 0:
    read = min(a[i],b[j])
    if read == a[i]:
        i += 1
        count += 1
        k -= read
        if i == n:
            a.append(10**10)
    else:
        j += 1
        count += 1
        k -= read
        if j == m:
            b.append(10**10)
if k < 0:
    count -= 1
print(count)

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

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, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# a = int(input())
# w = list(map(int, input().split()))
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
total = 0
ai = 0
bi = 0
count = 0

while total < p:
    if ai < n and bi < m:
        if a[ai] < b[bi]:
            total += a[ai]
            ai += 1
        elif a[ai] > b[bi]:
            total += b[bi]
            bi += 1
        else:
            aa = a[ai]
            bb = b[bi]
            pa = a[ai]
            pb = b[bi]
            aid = ai
            bid = bi
            k = 0
            afind = False
            bfind = False
            while aa == bb and (aid < n or bid < m):
                for i in range(aid, n):
                    if pa != a[i]:
                        aa = a[i]
                        aid = i
                        afind = True
                        break
                for i in range(bid, m):
                    if pb != b[i]:
                        bb = b[i]
                        bid = i
                        bfind = True
                        break
                if aa < bb:
                    total += a[ai]
                    ai += 1
                elif aa > bb:
                    total += b[bi]
                    bi += 1
                else:
                    pa = aa
                    pb = bb
                if afind == False and bfind == False:
                    total += a[ai]
                    ai += 1
                    break

                #print(aid, end=" ")
                # print(bid)

    elif ai >= n and bi < m:
        total += b[bi]
        bi += 1
    elif ai < n and bi >= m:
        total += a[ai]
        ai += 1
    elif ai >= n and bi >= m:
        break

    #print("total = " + str(total))
    #print("ai = " + str(ai), end=" ")
    #print("bi = " + str(bi))
    #print("k = ", p)
    if total <= p:
        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()))
o = n + m
if sum(a+b) <= k:
    print(n+m)
    exit()
a_l = int(len(a))
b_l = int(len(b))
if a_l < b_l:
    c = b_l - a_l
    a = a + [10 ** 10 for i in range(c)]
elif b_l < a_l:
    c = a_l - b_l
    b = b + [10 ** 10 for i in range(c)]
t = 0
#print(a,b)
for i in range(o):
    #print(a)
    if a[0] < b[0]:
        t += a[0]
        a = a[1:]
    else:
        t += b[0]
        b = b[1:]
    #print(a[0],b[0])
    #print(t)
    if t == k:
        print(i+1)
        exit()
    elif t > k:
        print(i)
        exit()
#print(n+m)

Submission status: Wrong Answer

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

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

c=0
while(True):
    a = A[0]
    b = B[0]
    if a < b:
        K = K-a
        A = A[1:] 
        c = c+1
    else:
        K = K - b
        B = B[1:]
        c = c+1
    if K<0:
        c=c-1
        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()))
ruisekiA = [0] * (N + 1)
for i in range(N):
    ruisekiA[i + 1] = ruisekiA[i] + A[i]
ruisekiB = [0] * (M + 1)
for i in range(M):
    ruisekiB[i + 1] = ruisekiB[i] + B[i]
ans = 0
for i in range(N + 1):
    if ruisekiA[i] > K: break
    else:
        time = K - ruisekiA[i]
        lb = -1
        ub = M + 1
        while ub - lb > 1:
            mid = (ub + lb) // 2
            if ruisekiB[mid] <= time: lb = mid
            else: ub = mid
        if i != 0 and ub != 0: ans = max(ans,i + lb)
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,j=0,0
for l in range(n+m):
    if i==n:
        c=b[j]
        j+=1
    elif j==m:
        c=a[i]
        i+=1
    else:
        if a[i]<b[j]:
            c=a[i]
            i+=1
        else:
            c=b[j]
            j+=1
    if k-c<0:
        print(l)
        exit()
    else:
        k-=c
print(n+m)

Submission status: Wrong Answer

Solution code:
import sys
N,M,K = map(int,input().split())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
total = 0
a = 0
b = 0
c = 0

for i in range(1000000000):
    if a + b == len(A_list) + len(B_list):
        print(c)
        sys.exit()
    elif a >= len(A_list):
        total = total + B_list[b]
        if total > K:
            print(c)
            sys.exit()
        else:
            b = b + 1
            c = c + 1
    elif b >= len(B_list):
        total = total + A_list[a]
        if total > K:
            print(c)
            sys.exit()
        else:
            a = a + 1
            c = c + 1
    else:
        if A_list[a] <= B_list[b]:
            total = total + A_list[a]
            if total > K:
                print(c)
                sys.exit()
            else:
                a = a + 1
                c = c + 1
            
        else:
            total = total + B_list[b]
            if total > K:
                print(c)
                sys.exit()
            else:
                b = b + 1
                c = c + 1

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
books = sorted(A + B)

ans = 0
guard = 10 ** 9 + 1
while True:
  if len(A) == 0 and len(B) == 0:
    break
  A_top = A.popleft() if len(A) else guard
  B_top = B.popleft() if len(B) else guard
  if A_top == B_top:
    A_sec = A.popleft() if len(A) else guard
    B_sec = B.popleft() if len(B) else guard
    min_top = B_top if B_sec < A_sec else A_top
    A.appendleft(A_sec)
    B.appendleft(B_sec)
  elif A_top < B_top:
    min_top = A_top
    B.appendleft(B_top)
  else:
    min_top = B_top
    A.appendleft(A_top)
  if K < min_top:
    break
  else:
    ans += 1
    K -= min_top

print(ans)

Submission status: Wrong Answer

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

bs = len(a) + len(b)
ls = []
while len(ls) < bs:
  if len(a) == 0:
    if len(b) == 0:
      break
    else:
      ls += b
      break
  elif len(b) == 0:
    ls += a
    break
    
  if a[0] < b[0]:
    ls.append(a.pop(0))
  elif b[0] < a[0]:
    ls.append(b.pop(0))

time = k; read = 0
for b in ls:
  if time - b < 0:
    ans = read
    break
  else:
    time -= b
    read += 1

ans = read
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
from bisect import *
def solve():
    ans = 0
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))+[float('inf')]
    B = list(map(int, input().split()))+[float('inf')]
    cumA = [0]*(N+1)
    cumB = [0]*(M+1)
    for i in range(N):
        cumA[i+1] = cumA[i]+A[i]
    for i in range(M):
        cumB[i+1] = cumB[i]+B[i]
    for i in range(N+1):
        rest = K-cumA[i]
        ind = bisect_right(cumB,rest)
        if ind>1:
            ans = max(ans,i+ind-1)
    return ans
print(solve())

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_i = 0
B_i = 0
n = N + M
    
count = 0

for i in range(n):
    if len(A) != A_i  and len(B) != B_i:
        if A[A_i] < B[B_i]:
            if A[A_i] <= K:
                K = K - A[A_i]
                count += 1
                A_i += 1
            else:
                break
        else:
            if B[B_i] <= K:
                K = K - B[B_i]
                count += 1
                B_i += 1
            else:
                break
                
    elif len(A) != A_i:
        if A[A_i] <= K:
            K = K - A[A_i]
            count += 1
            A_i += 1
        else:
            break
    
    else:
        if B[B_i] <= K:
            K = K - B[B_i]
            count += 1
            B_i += 1
        else:
            break
        
    
print(count)

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

a=0
b=0
tmp=0
count=0

while tmp <= K:
    if A_list[int(a)] <= B_list[int(b)]:#Aの机にある本のほうが短い時間で読めるとき
        tmp+=A_list[int(a)]
        a+=1
    else:#Bの机にある本のほうが短い時間で読めるとき
        tmp+=B_list[int(b)]
        b+=1
    count+=1
    if a >= len(A_list):#リストが空だったら
        A_list.append(10**9+1)
    if b >= len(B_list):#リストが空だったら
        B_list.append(10**9+1)

print(count-1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]



    acc_A = list(accumulate(A))
    acc_B = list(accumulate(B))

    ans = 0
    for i, a in enumerate(acc_A):
        tmp = i + 1
        rest = K - a
        if rest < 0:
            ans = max(ans, bisect_right(acc_B, K))
            break
        b_ind = bisect_right(acc_B, rest)
        tmp += b_ind

        ans = max(ans, tmp)

    print(ans)
       


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()))
count = 0

for i in range(200000):
    if i < len(A) and i < len(B):
        if A[i] < B[i]:
            if K > A[i]:
                K = K - A[i]
                count = count +1
        elif A[i] > B[i]:
            if K > B[i]:
                K = K - B[i]
                count = count +1
    elif i > len(A) and i < len(B):
        if K > B[i]:
                K = K - B[i]
                count = count +1
    elif i < len(A) and i > len(B):
        if K > A[i]:
            K = K - A[i]
            count = count +1
                

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

N , M , K = map(int, input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
time = 0
ans = 0

while time <= K:
    
    if len(A) == 0 and len(B) == 0:
        break
    
    if len(A) == 0:
        if B[0] > K:
            break
        
    if len(B) == 0:
        if A[0] > K:
            break
    
    if len(A) == 0:
        time+=B[0]
        B.pop()
        ans+=1
        
    elif len(B) == 0 :
        time+=A[0]
        A.pop()
        ans+=1
        
    elif A[0] <= B[0] :
        time += A[0]
        A.pop()
        ans+=1
        
    elif B[0] <= A[0] :
        time+=B[0]
        B.pop()
        ans+=1
        
if time > K:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
info = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

N = list()
M = list()
N.append(A[0])
for i in range(1, info[0]):
  N.append(N[i-1]+A[i])
M.append(B[0])
for i in range(1, info[1]):
  M.append(M[i-1]+B[i])

ans = 0
for i in range(info[0]-1, -1, -1):
  if N[i] > info[2] :
    continue
  if i+info[1]+2 <= ans:
    break
  for j in range(info[1]-1, -1, -1):
    if M[j] > info[2]:
      continue
    if i+j+2 <= ans:
      break
    if N[i]+M[j] <= info[2]:
      ans = i+j+2
      break
    
print(ans)

Submission status: Wrong Answer

Solution code:
# your code goes here
n,m,k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans=0
b = b[::-1]
a = a[::-1]
sum=0
lower = 900
upper = 1000

#print("Prime numbers between", lower, "and", upper, "are:")

for num in range(lower, upper + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
       		num-=1
         #  print(num)
while(len(a)>0 and len(b)>0):
    sum+=min(a[-1],b[-1])
    if sum>k:
        break
    else:
        ans+=1
        if(a[-1] < b[-1]):
            a.pop()
        else:
            b.pop()
for num in range(lower, upper + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
       		num-=1
         #  print(num)
if(sum<k and len(a)!=0):
    for i in range(len(a)):
        sum+=a[-1]
        if sum>k:
            break
        else:
            ans+=1
            a.pop()
if(sum<k and len(b) !=0):
    for i in range(len(b)):
        sum+=b[-1]
        if sum>k:
            break
        else:
            ans+=1
            b.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
m,n,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
len_a = len(a)
len_b = len(b)
i_a = 0
i_b = 0
sum_time = []

while sum(sum_time) <= k:
    if len_a <= i_a and len_b <= i_b:
        break
    elif len_a <= i_a:
        sum_time.append(b[i_b])
        i_b += 1
    elif len_b <= i_b:
        sum_time.append(a[i_a])
        i_a += 1
    elif a[i_a] <= b[i_b]:
        sum_time.append(a[i_a])
        i_a += 1
    else:
        sum_time.append(b[i_b])
        i_b += 1

if sum(sum_time) > k:
    sum_time.pop()

print(len(sum_time))

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()))
ans1=0
ans2=0
k2=k
a2=a
b2=b
for _ in range(4*10**5):
  if a[0] < b[0]:
    if k-a[0] >= 0:
      ans1+=1
      k-=a[0]
      a=a[1:]
      if len(a)==0:
        a.append(10**10)
    else:
      break
  elif a[0] > b[0]:
    if k-b[0] >= 0:
      ans1+=1
      k-=b[0]
      b=b[1:]
      if len(b)==0:
        b.append(10**10)
    else:
      break
  else:
    if k-a[0] >= 0:
      ans1+=1
      k-=a[0]
      a=a[1:]
      if len(a)==0:
        a.append(10**10)
    else:
      break
while k2 > 0:
  if a2[0] < b2[0]:
    if k2-a2[0] >= 0:
      ans2+=1
      k2-=a2[0]
      a2=a2[1:]
      if len(a2)==0:
        a2.append(10**10)
    else:
      break
  elif a2[0] > b2[0]:
    if k2-b2[0] >= 0:
      ans2+=1
      k2-=b2[0]
      b2=b2[1:]
      if len(b2)==0:
        b2.append(10**10)
    else:
      break
  else:
    if k2-b2[0] >= 0:
      ans2+=1
      k2-=b2[0]
      b2=b2[1:]
      if len(b2)==0:
        b2.append(10**10)
    else:
      break
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m, k = i_map()
    a_list = i_list()
    b_list = i_list()

    a_ruisekiwa = list(accumulate(a_list))
    b_ruisekiwa = list(accumulate(b_list))

    # print(a_ruisekiwa)
    # print(b_ruisekiwa)

    max_count = 0

    for i in range(n):
        if k < a_ruisekiwa[i]:
            if i == 0:
                max_count = bisect_right(b_ruisekiwa, k)
            break
        insert_num = k - a_ruisekiwa[i]
        insert_index = bisect_right(b_ruisekiwa, insert_num)
        max_count = max(max_count, i + insert_index +1)

    print(max_count)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
K = int(a[2])
Ai = input().split(" ")
Bi = input().split(" ")
Ai = [int(s) for s in Ai]
Bi = [int(s) for s in Bi]
time_ = int(K)
time = 0
acount = 0
bcount = 0

for i in range(10000000000000000):
    try:
        time += Ai[i]
        if time > time_:
            time -= Ai[i]
            break
        acount += 1
    except IndexError:
        break
atime = time
time = 0
for i in range(10000000000000000):
    try:
        time += Bi[i]
        if time > time_:
            time -= Bi[i]
            break
        bcount += 1
    except IndexError:
        break
btime = time
allc = bcount
if bcount > acount:
    hic = bcount
else:
    hic = acount
# AiからBiに移す
cip = 0
for i in range(acount):
    ci = i + cip
    try:
        while time + Ai[ci] <= time_:
            time += Ai[ci]
            allc += 1
            ci += 1
            cip += 1
        if hic < allc:
            hic = allc
    except IndexError:
        continue
    try:
        time -= Bi[bcount - 1]
        bcount -= 1
        allc -= 1
    except IndexError:
        pass
    try:
        while time + Ai[ci] <= time_:
            time += Ai[ci]
            allc += 1
            ci += 1
            cip += 1
        if hic < allc:
            hic = allc
    except IndexError:
        break

print(hic)