Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
from sys import stdin

A=list(map(int,stdin.readline().split()))
N=A[0]
M=A[1]
K=A[2]
B=list(map(int,stdin.readline().split()))  #N
C=list(map(int,stdin.readline().split()))  #M

Nlist=list()
Mlist=list()
sum=0

for u in B:
    sum+=u
    if sum>K:
        break
    Nlist.append(sum)


sum=0
O=0

for v in C:
    sum+=v
    if sum>K:
        break
    Mlist.append(sum)

if len(Mlist)==0 and len(Nlist)==0:
    print(0)
    O=1

if O==0:
    if len(Mlist)==0:
        print(len(Nlist))
        O=1
    if len(Nlist)==0:
        print(len(Mlist))
        O=1
    if Mlist[len(Mlist)-1]+Nlist[len(Nlist)-1]<=K:
        print(len(Mlist)+len(Nlist))
        O=1

MAX=2
mbegin=0
mend=len(Mlist)-1
archive=0
# print(Nlist)
# print(Mlist)



if O==0:

    for u in range(len(Nlist)-1,-1,-1):
        mend=len(Mlist)-1
        K=K-Nlist[u]
        #print(K)
        #binary search
        if Mlist[mbegin]<=K:
            UU=(mbegin+mend)//2

            while mbegin!=mend:
                if Mlist[UU]<=K:
                    K-=Mlist[UU]
                    mbegin=UU
                else:
                    mend=UU

            if mbegin==archive:
                if mbegin==0:
                    MAX=u+2
                break

            MAX=max(MAX,u+mbegin+2)
            archive=mbegin

if O==0:
   print(MAX)

Submission status: Wrong Answer

Solution code:

def solve():
    total = 0
    cnt = 0
    i = 0
    j = 0
    while cnt<N+M:
#        print(i,j)
        if i==N and j==M:
            break
        elif j == M:
            if total + A[i] <= K:
                total+=A[i]
                i += 1
            else:
                break
        elif i == N:
            if total + B[j] <= K:
                total+=B[j]
                j += 1
            else:
                break
        elif A[i] <= B[j]:
            if total + A[i] <= K:
                total+=A[i]
                i += 1
            else:
                break
        elif A[i] > B[j]:
            if total + B[j] <= K:
                total+=B[j]
                j += 1
            else:
                break
    print(i+j)

if __name__=="__main__":
    N,M,K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = A+B
    AB.sort()
#    print(AB)
    solve()

Submission status: Wrong Answer

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

l = []
for i in range(n + m):
  if len(a) == 0:
    l.append(b.pop(0))
  elif len(b) == 0:
    l.append(a.pop(0))
  
  else:
    if a[0] < b[0]:
      l.append(a.pop(0))
    elif a[0] > b[0]:
      l.append(b.pop(0))
    else:
      if len(a) > 1 and len(b) > 1:
        if a[1] < b[1]:
          l.append(a.pop(0))
        else:
          l.append(b.pop(0))
      else:
        l.append(a.pop(0))

total = 0
cnt = 0
for i in range(n+m):
  if total+l[i] > k:
    break
  total += l[i]
  cnt += 1
print(cnt)

Submission status: Wrong Answer

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

X=[float("inf")]*(n+m+6)
X[n+m]=sum(A)+sum(B)
a=-1 ; b=-1
for i in range(1,n+m+1):
    if a==-n-1:
        X[n+m-i]=X[n+m-i+1]-B[b]
    elif b==-m-1:
        X[n+m-i]=X[n+m-i+1]-A[a]
    elif A[a]<B[b]:
        X[n+m-i]=X[n+m-i+1]-B[b]
        b-=1
    else:
        X[n+m-i]=X[n+m-i+1]-A[a]
        a-=1
import bisect
#print(A,B)
#if bisect.bisect_left(X,k)==1:
#  print(0);exit()
#print(X)
if k<X[1]:
  print(0)
  exit()

print(bisect.bisect_left(X,k))

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
ans = 0

if sum(A) + sum(B) <= K:
    print(N + M)
    exit()

for i in range(N + 1):
    for j in range(M, -1, -1):
        TMP = i + j
        if sum(A[0:i]) + sum(B[0:j]) < K:
            ans = max(ans, TMP)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)


# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1


def II(): return int(input())


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


def MI1(): return map(int1, input().split())


def LI(): return list(map(int, input().split()))


def LI1(): return list(map(int1, input().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def MS(): return input().split()


def LS(): return list(input())


def LLS(rows_number): return [LS() for _ in range(rows_number)]


def printlist(lst, k=' '): print(k.join(list(map(str, lst))))


INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations


# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

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

    # print(list(accumulate(A)))
    # print(list(accumulate(B)))
    ra = list(accumulate(A))[::-1]
    rb = list(accumulate(B))[::-1]
    na = N
    nb = M

    ia = 0
    ib = 0

    ta = ra[0]
    tb = rb[0]

    while ta + tb > K:
        # print(ia, ib, na, nb, ta, tb)
        if na == 0 and nb == 0: break
        if ta > tb:
            ia = ia + 1
            na = na - 1
            if na == 0:
                ta = 0
            else:
                ta = ra[ia]
        elif ta == tb:
            if na > nb:
                while ta > K:
                    na -= 1
                    ia = ia + 1
                    if na == 0:
                        ta = 0
                    else:
                        ta = ra[ia]

            else:
                while tb > K:
                    ib = ib + 1
                    nb = nb - 1
                    if nb == 0:
                        tb = 0
                    else:
                        tb = rb[ib]
        else:
            ib = ib + 1
            nb = nb - 1
            if nb == 0:
                tb = 0
            else:
                tb = rb[ib]

    print(na + nb)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import random
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(" ")]

while True:
    if (N>10**8) | (M>10**8) |(K>10**8):
        if random.random()>0.7:
            print(0)
            break
    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)
    break

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
  A[i] = int(A[i])
for i in range(len(B)):
  B[i] = int(B[i])
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
max_j = 0
for i in range(M):
  if B_cumsum[i] <= K and max_count <= B_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] <= K and max_count <= A_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] > K:
    break
  elif A_cumsum[i] + B_cumsum[max_j] > K:
    for j in range(max_j):
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
        max_count = i + j + 2
        max_j=j
      else:
        break
  else:
    for j in range(max_j, M)[::-1]:
      if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
        max_count = i + j + 2
        max_j=j
      else:
        break
    
print(max_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()))
Acount = 0
Bcount = 0


for i in range(N+M):

    if N != 0 and M != 0:

        
        if A[0] <= B[0] and K >= A[0]:

            K = K - A[0]
            Acount = Acount + 1
            N = N-1
            A.pop(0)
            
        elif A[0] > B[0] and K >= B[0]:

                K = K - B[0]
                Bcount = Bcount +1
                M = M-1
                B.pop(0)
                
    elif N == 0 and M != 0 and K >= B[0]:

        K = K - B[0]
        Bcount = Bcount +1
        M = M-1
        B.pop(0)
                
    elif N != 0 and M == 0 and K >= A[0]:

        K = K - A[0]
        Acount = Acount +1
        N = N-1
        A.pop(0)   
                

print(Acount + Bcount)

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

for i in range(400000):
    
    if a[a_i] < b[b_i]:
        # aaaa
        # print(a_i,b_i,k,a[a_i]) 
        k -= a[a_i]
        if k == 0:
            print(a_i+b_i+1)
            exit()
        if k < 0:
            print(a_i+b_i)
            exit()
        a_i += 1
        if a_i == n:
            for j in range(200000):
                # aaaaa
                # print(a_i,b_i,k,b[b_i])
                k -= b[b_i]
                if k == 0:
                    print(a_i+b_i+1)
                    exit()
                if k < 0:
                    print(a_i+b_i)
                    exit()
                b_i += 1
                if b_i == m:
                    print(a_i+b_i)
                    exit()
    else:
        # aaaa
        # print(a_i,b_i,k,b[b_i])
        k -= b[b_i]
        if k == 0:
            print(a_i+b_i+1)
            exit()
        if k < 0:
            print(a_i+b_i)
            exit()
        b_i += 1
        if b_i == m:
            for j in range(200000):
                # aaaaa
                # print(a_i,b_i,k,a[a_i])
                k -= a[a_i]
                if k == 0:
                    print(a_i+b_i+1)
                    exit()
                if k < 0:
                    print(a_i+b_i)
                    exit()
                a_i += 1
                if a_i == n:
                    print(a_i+b_i)
                    exit()
# print(a_i+b_i)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)


def 関数(n, m, k, n_liste, m_liste):
    temps = 0
    i = j = 0
    satsu = 0
   
    n_liste += m_liste
    n_liste.sort()
    nlen = len(n_liste)

    if k < n_liste[i]:
        return satsu

    while(temps <= k):
        temps += n_liste[i]
        if(temps <= k):
            satsu += 1
        i += 1
        if(nlen == i):
            break

    return satsu

def çözmek():
    N, M, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int,sys.stdin.readline().split()))
    res = []
    res.append(関数(N, M, K, A, B))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()

Submission status: Wrong Answer

Solution code:


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

A = [i for i in map(int, input().split())]
B = [i for i in map(int, input().split())]
ans = 0
a = 0
b = 0
t = 0

while b != M or a != N:
    if b == M:
        if A[a]+t <= K:
            t += A[a]
            ans += 1
            a += 1
        else:
            break

    elif a == N:
        if B[b]+t <= K:
            t += B[b]
            ans += 1
            b += 1
        else:
            break
    elif B[b] >= A[a] and A[a]+t <= K:
        t += A[a]
        ans += 1
        a += 1
    elif B[b] < A[a] and B[b]+t <= K:
        t += B[b]
        ans += 1
        b += 1


print(ans)

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

c = 0

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

a = A.pop()
b = B.pop()

while True:
  if a < b:
    if K >= a:
      c += 1
      K -= a
      a = A.pop()
    else:
      break
  else:
    if K >= b:
      c += 1
      K -= b
      b = B.pop()
    else:
      break

print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
An, Bn, t = [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()]

idxA = idxB = cnt = 0

for i in range(An + Bn):
	if t < 0 : break



	if An > idxA :
		calc = t - A[idxA]
		if calc < 0 : 
			idxA += 1
			continue
		t -= A[idxA]
		cnt += 1
		idxA += 1


	if Bn > idxB :
		calc = t - B[idxB]
		if calc < 0 :
			idxB += 1
			continue
		t -= B[idxB]
		cnt += 1
		idxB += 1

print(cnt)

Submission status: Wrong Answer

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

a_time = []
for i in range(len(a)):
  if i == 0:
    a_time.append(a[i])
  else:
    if a_time[i-1] + a[i] > k:
      break
    else:
      a_time.append(a_time[i-1] + a[i])

b_time = []
for i in range(len(b)):
  if i == 0:
    b_time.append(b[i])
  else:
    if b_time[i-1] + b[i] > k:
      break
    else:
      b_time.append(b_time[i-1] + b[i])

cnt = 0
for i in range(len(a_time)):
  for j in range(len(b_time)):
    time = a_time[i] + b_time[j]
    if time < k:
      cnt = max(cnt, i+j+2)
    else:
      break

print(cnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
import numpy as np
from itertools import accumulate
AS = np.array([0] + list(accumulate(A)))
BS = np.array([0] + list(accumulate(B)))

ans = 0
for i in range(n+1):
    if AS[i] > k:
        break
    for j in range(ans-i-1, m+1):
        if AS[i] + BS[j] > k:
            break
        ans = max(ans, i+j)
        
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
cost = 0
b_i = 0
if not (a[0] >= k and b[0] >= k):
  while 1:
    if ans >= n:
      if ans-n>=m:
        break
      _next = b[b_i]
      b_i += 1
    else:
      _next = a[ans]
    if (cost + _next) <= k:
      ans += 1
      cost += _next
    else:
      b_i -= 1
      break
      
  max_ans = ans
  if b_i == 0 or b_i == -1:
    b_i = 0
    for i in range(ans-1,-1,-1): # 2から
      # 今のままで足せる？
      while 1:
        if b_i >= m:
          break
        _next = b[b_i]
        if cost + _next > k:
          break
        cost += _next
        ans += 1
        b_i  += 1
        max_ans = max(max_ans, ans)
      ans -= 1
      cost -= a[i]
      while 1:
        if b_i >= m:
          break
        _next = b[b_i]
        if cost + _next > k:
          break
        cost += _next
        ans += 1
        b_i  += 1
      max_ans = max(max_ans, ans)
  else:
    b_i += 1
    for i in range(n-1,-1,-1):
      ans -= 1
      cost -= a[i]
      while cost < k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)

  if a[0] <= k:
    print(max_ans)
  else:
    ans = 0
    cost = 0
    _next = 0
    while 1:
      if ans >= m:
        break
      _next = b[ans]
      if cost + _next > k:
        break
      cost += _next
      ans += 1
    print(ans)
else:
  print(0)

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()))
res=k
a_read=0
b_read=0
u=0
while res>=0:
  if (a_read==n and b_read==m):
    u=1
    break
  elif (a_read==n):
    res-=b[b_read]
    b_read+=1
  elif (b_read==m):
    res-=a[a_read]
    a_read+=1
  elif (a[a_read]<=b[b_read]):
    res-=a[a_read]
    a_read+=1
  else:
    res-=b[b_read]
    b_read+=1
if u==1:
  print(n+m)
else:
  print(a_read+b_read-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()))

count=0
total_k=0

while total_k<=k:
    if a==[] and b==[]:
        break
    elif a==[]:
        total_k+=b[0]
        del b[0]
        count+=1
    elif b==[]:
        total_k+=a[0]
        del a[0]
        count+=1        
    elif a[0]<=b[0] and a[0]<=k:
        total_k+=a[0]
        del a[0]
        count+=1
    elif a[0]>b[0] and b[0]<=k:
        total_k+=b[0]
        del b[0]
        count+=1
    else:
        break

if total_k>k:
    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()))
tt = 0
a = 0
b = 0
if (K >= (sum(A)+sum(B))):
    print(N+M)
elif (A[a]>K)and(B[b]>K):

    print(0)
else:
    while (tt <= K ):

        if (a < N)and (b < M):
            if A[a]>B[b]:
                tt += B[b]
                b += 1
                if tt > K:

                    break
            elif A[a]<B[b]:
                tt += A[a]
                a += 1
                if tt > K:

                    break
            elif (A[a]==B[b])and(a < N-1)and (b < M-1):
                if A[a+1]>B[b+1]:
                    tt += B[b]
                    b += 1
                    if tt > K:

                        break
            elif (A[a]==B[b])and(a == N-1)and (b < M-1):
                tt += B[b]
                b += 1
                if tt > K:

                    break
            else:
                tt += A[a]
                b += 1
                if tt > K:

                    break

        elif (a == N)and (b < M):
            tt += B[b]
            b += 1
            if tt > K:

                break
        elif (a < N)and (b == M):
            tt += A[a]
            a += 1
            if tt > K:

                break
        else:
            break
    print(a + b -1)

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 = deque(list(map(int, input().split())))
    B = deque(list(map(int, input().split())))
    ans = 0
    a_is_available = True
    b_is_available = True
    while K >= 0:
        lenA = len(A)
        lenB = len(B)
        if lenA == 0: a_is_available = False
        if lenB == 0: b_is_available = False
        if not a_is_available and not b_is_available:
            ans += 1
            break
        if a_is_available:a = A.popleft()
        if b_is_available:b = B.popleft()
        if a_is_available and not b_is_available:
            if a > K:
                break
            K -= a
        elif not a_is_available and b_is_available:
            if b > K:
                break
            K -= b
        elif a <= b:
            if a > K:
                break
            K -= a
            B.appendleft(b)
        else:
            if b > K:
                break
            K -= b
            A.appendleft(a)
        if K < 0:
            break
        ans += 1
    ans = min(N+M, ans)
    ans = max(0, ans)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#Nは机Aの冊数，Mは机Bの冊数，Kは読書の制限時間
N,M,K= map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
#A = A.append(1e11)
#B = B.append(1e11)

time = 0 #使った時間
book = 0 #読んだ冊数
Ai = 0 #机Aの上から何冊目か
Bi = 0 #机Bの上から何冊目か

#while Ai+1 <= N or Bi+1 <= M:
while K >= time:
  if Ai+1 <= N and Bi+1 <= M:
    if A[Ai] <= B[Bi]:
      time += A[Ai]
      Ai += 1
      book += 1
      #print(book)
    else:
      time += B[Bi]
      Bi += 1
      book += 1
  elif Ai+1 <= N and Bi+1 > M:
    time += A[Ai]
    Ai += 1
    book += 1
  elif Ai+1 > N and Bi+1 <= M:
    time += B[Bi]
    Bi += 1
    #print(Bi)
    book += 1
  else:
    break
    
#print(Bi)
print(book)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
AA = [0]
BB = [0]
r = 0
for i in A:
    r += i
    AA.append(r)
r = 0
for i in B:
    r += i
    BB.append(r)
ans = 0
a = N
b = 0
while AA[a]+BB[b] > K:
    a -= 1
ans = a+b

while a >= 0:
    while b < M:
        if AA[a]+BB[b+1] <= K:
            b += 1
        else:
            break
    print(a,b,AA[a]+BB[b])
    if ans < a+b:
        ans = a+b
    if b == M:
        break
    a -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(K + 1)
B.append(K + 1)
ia, ib = 0, 0
time = 0
flag = True
C = [A[0]] * len(A)
D = [B[0]] * len(B)
_c, _d = 0, 0
for i in range(1, len(A)):
    C[i] = C[i - 1] + A[i]
    if C[i] <= K:
        _c = i + 1
for i in range(1, len(B)):
    D[i] = D[i - 1] + B[i]
    if D[i] <= K:
        _d = i + 1
_max = max(_c, _d)
while flag:
    flag = False
    if A[ia] <= B[ib] and time + A[ia] <= K:
        time += A[ia]
        ia += 1
        flag = True
    elif B[ib] < A[ia] and time + B[ib] <= K:
        time += B[ib]
        ib += 1
        flag = True
print(max(ia + ib, _max))

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()))
ans = 0
#print(a, b)
time = k
for i in range(400010):
    if time > 0:
        if not a and not(not b):
            time -= b[0]
            b.popleft()
            ans += 1
               # print(a, b, time)
        elif not a and not b:
               # print(a, b, time)
                break
        elif not b and not(not a):
            time -= a[0]
            a.popleft()
            ans += 1
            #print(a, b, time)
        elif not(not a) and not(not b):
            if a[0] == b[0]:
                if len(a) <= len(b):
                    time -= b[0]
                    b.popleft()
                    ans += 1
                else:
                    time -= a[0]
                    a.popleft()
                    ans += 1
            elif a[0] < b[0]:
                time -= a[0]
                a.popleft()
                ans += 1
                #print(a, b, time)
            else:
                time -= b[0]
                b.popleft()
                ans += 1
                #print(a, b, time)
if time < 0:
    print(ans - 1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n,m,k=iia()
arr=iia()
ar=iia()
count=0
start=n-1
for i in range(n):
    if k>=arr[i]:
        count+=1
        k-=arr[i]
    else:
        start=i-1
        break
start2=0
ma=count
if k>=0:
    for j in range(m):
        if k>=ar[j]:
            count+=1
            ma=max(ma,count)
            k-=ar[j]
        else:
            start2=j
            break
for i in range(start2,m):
    while start>=0 and k<ar[i] :
        k+=arr[start]
        start-=1
        count-=1
        ma=max(count,ma)
    if k>=ar[i]:
        count+=1
        k-=ar[i]
        ma=max(count,ma)
print(ma)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a = deque(list(map(int,input().split())))
b = deque(list(map(int,input().split())))
cnt = 0
total = 0

if a[0]==True and b[0]==True:
    while total+a[0] < k or total+b[0] < k:
        if len(a) > 0 and len(b) > 0:
            picked = min(a[0],b[0])
            if picked == a[0]:
                total += a.popleft()
                cnt += 1
                print(total,cnt)
                if len(a)==0: 
                    break
            else:
                total += b.popleft()
                cnt += 1
                print(total,cnt)
                if len(b)==0:
                    break
elif a[0] and b[0]==False:
    while total + a[0] < k:
        total +=a.popleft()
        cnt += 1
        if len(a) == 0:
            break
else:
    while total + b[0] < k:
        total += b.popleft()
        cnt += 1
        if len(b)==0:
            break
    
print(cnt)

Submission status: Wrong Answer

Solution code:
#C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
count = 0
i = 0
A = 0
while i != n-1:
    i += 1
    A += a[i]
    if A > k:
        break
    j = 0
    B = 0
    while j != m-1:
        j += 1
        B += b[j]
        if A + B > k:
            break
    temp = (i+1) + (j+1) - 1
    if temp > count:
        count = temp
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(y) for y in input().split()]
a = 0
b = 0
hon = 0
C = []
D = []
x = M

for p in range(0,N):
    if p == 0:
        C += [int(A[0])]
    else:
        C += [int(A[p])+int(C[p-1])]
for q in range(0,M):
    if q == 0:
        D += [int(B[0])]
    else:
        D += [int(B[q])+int(D[q-1])]

for p in range(0,N):
    for q in reversed(range(0,x)):
        if C[p]+D[q] <= K:
            hon = max(p+q+2,hon)
            break
        else:
            x = q + 1
print(hon)





"""
while K >= A[a] or K >= B[b]:
    if K >= A[a] and A[a] <= B[b]:
        K -= A[a]
        a += 1
        hon += 1
    if K >= B[b] and B[b] <= A[a]:
        K -= B[b]
        b += 1
        hon += 1
print(hon)
"""