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 collections import deque

l1 = str(input()).split()

N = int(l1[0])
M = int(l1[1])
K = int(l1[2])

aq = deque([int(v) for v in str(input()).split()])
bq = deque([int(v) for v in str(input()).split()])

t = 0
count = 0
while N > 0 or M > 0:
    t = 0
    if M == 0:
        t += aq.popleft()
        N -= 1
    elif N == 0:
        t += bq.popleft()
        M -= 1
    elif aq[0] < bq[0]:
        t += aq.popleft()
        N -= 1
    else:
        t += bq.popleft()
        M -= 1

    if (K - t) < 0:
        break

    K -= t
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import collections as cs

N, M, K = map(int, input().split())
A = cs.deque(map(int, input().split()))
B = cs.deque(map(int, input().split()))

A.append(K + 1)
B.append(K + 1)

count = -1
time = 0

while time <= K:
    count += 1
    if A[0] <= B[0]:
        time += A.popleft()
    else:
        time += B.popleft()

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()))
x = 0
y = 0
cnt = 0
cnt2 = 0
sumlist_a = []
sumlist_b = []
while x < k :
    x += a[cnt]
    if x > k:
        break
    cnt += 1
    sumlist_a.append(x)
    if cnt == n:
        break
ans = len(sumlist_a)
sumlist_a.reverse()
sumlist_a.append(0)
#ansがaから全部本をとってこれる最大個数
p=0
for i in sumlist_a:
    while y < k - i:
        y += b[cnt2]
        if y > k - i:
            break
        cnt2 += 1
        if cnt2 == m:
            break
    ans = max(ans, ans+cnt2-p)
    p += 1
    cnt2 = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

    dA = deque([0] + A)
    dB = deque([0] + B)

    sumA = sum(A)
    sumB = sum(B)
    sumall = sumA + sumB
    lenall = len(A) + len(B) 
    Atmp = [0,0]
    Btmp = [0,0]

    Atmp[1] = dA.pop()
    Btmp[1] = dB.pop()

    while sumall > K:
        if Atmp[0] == 0 and dA:
            Atmp[0] = dA.pop()
        if Btmp[0] == 0 and dB:
            Btmp[0] = dB.pop()
        if not dA and not dB:
            print(0)
            return
        if sumA >= sumB:
            sumall -= Atmp[1]
            sumA -= Atmp[1]
            lenall -= 1
            Atmp[1] = Atmp[0]
            Atmp[0] = 0 
        else:
            sumall -= Btmp[1]
            sumB -= Btmp[1]
            lenall -= 1
            Btmp[1] = Btmp[0]
            Btmp[0] = 0 
    print(lenall)
                 
solve()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,m,k = IL()
    a = list(IL())
    b = list(IL())
    a = list(accumulate(a))
    c = list(accumulate([1]*n))
    ans = 0
    for i,item in enumerate(a):
        if k<item:  break
        val = item
        count = c[i]
        for rep in b:
            if k<val+rep:
                break
            val += rep
            count += 1
        ans = max(ans,count)
    print(ans)
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=deque()
  mapA=map(int,input().strip("\n").split())
  for a in mapA:
    A.append(a)
  #print(A)
  #print(A.popleft())
  B=deque()
  mapB=map(int,input().strip("\n").split())
  for b in mapB:
    B.append(b)
  #A=list(map(int,input().strip("\n").split()))
  #B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  #def dfs(a,b,k,s):
  def dfs(A,B,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    ansA=s
    ansB=s
    if len(A)>0:
      tmp=A.popleft()
      ansA=dfs(A,B,k-tmp,s+1)
    #if a<n:
    #  ansA=dfs(a+1,b,k-A[a],s+1)
    #else:
    #  ansA=s
    if len(B)>0:
      tmp=B.popleft()
      ansB=dfs(A,B,k-tmp,s+1)
    #if b<m:
    #  ansB=dfs(a,b+1,k-B[b],s+1)
    #else:
    #  ansB=s
    return max(ansA,ansB)

  ans=dfs(A,B,k,0)
  #ans=max(dfs(1,0,k-A[0],1),dfs(0,1,k-B[0],1))
  print(ans)

Submission status: Wrong Answer

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

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

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, mn = map(int, input().split())
great = max(a,b)
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
res = 0
if lb[0] == mn or la[0] == mn :
    print(1)
    exit(0)
elif la[0] > mn and lb[0] > mn :
    print(0)
    exit(0)
else:
    while la and lb:
        if la[0] > lb[0]:
            mn -= la[0]
            res += 1
            del la[0]
        elif la[0] < lb[0]:
            mn -= lb[0]
            res += 1
            del lb[0]
        else:
            mn -= lb[0]
            res += 1
            del lb[0]
    while la:
        if la[0] <= mn:
            mn -= la[0]
            res += 1
            del la[0]
        else:
            break
    while lb:
        if lb[0] <= mn:
            mn -= lb[0]
            res += 1
            del lb[0]
        else:
            break

print(res)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

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

cnt = 0

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

i = c.popleft()
j = d.popleft()

while len(c) != 0 or len(d) != 0 or k >= 0:
    if i > j:
        k -= j
        if len(d) != 0:
            j = d.popleft()
    else:
        k -= i
        if len(c) != 0:
            i = c.popleft()

    if k < 0:
        break

    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:


def main3():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    time_sum = 0
    counter = 0
    ans = []

    if bb[0] >= aa[0]:
        if k < aa[0]:
            return counter
    if bb[0] <= aa[0]:
        if k < bb[0]:
            return counter

    if (sum(aa)+sum(bb)) <= k:
        return n+m

    for i in range(n+1):
        counter = i
        time_sum = sum(aa[:i])
        if time_sum > k:
            break
        elif time_sum == k:
            counter += 1
            ans.append(counter)
        else:
            for j in range(m):
                time_sum += bb[j]
                if time_sum < k:
                    counter += 1
                elif time_sum == k:
                    counter += 1
                    ans.append(counter)
                    break
                else:
                    ans.append(counter)
                    break

    if len(ans) == 1:
        return ans[0]
    else:
        return max(ans)


if __name__ == '__main__':
    ans = main3()
    print(ans)

Submission status: Wrong Answer

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

while True:
    if ans > k:
        print(result-1)
        break
    if a[0] + b[0] == 2 * (10 ** 9 + 1):
        print(result)
        break
    
    if a[0] > b[0]:
        ans += b.popleft()
        result += 1
    else:
        ans += a.popleft()
        result += 1
    if len(a) == 0 or len(b) == 0:
        a.append(10 ** 9 + 1)
        b.append(10 ** 9 + 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()))
ans = 0
#print(a, b)
time = k
for i in range(400010):
    if time > 0:
        if not a:
            if not(not b):
                time -= b[0]
                b.popleft()
                ans += 1
               # print(a, b, time)
            else:
               # print(a, b, time)
                break
        elif not b and not(not a):
            time -= a[0]
            a.popleft()
            ans += 1
            #print(a, b, time)
        else:
            if 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
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
    for a in ra:
        if a > K:
            na = na - 1
        else:
            break
    nb = M
    for b in rb:
        if b > K:
            nb = nb -1
        else:
            break
    # print(na, nb)
    if na == 0 and nb == 0:
        print(0)
        return
    # elif na == 0:
    #     print(nb)
    #     return
    # elif nb == 0:
    #     print(na)
    #     return

    if na != 0:
        ra = ra[-na:]
        ta = ra[0]
    else:
        ra = []
        ta = 0

    if nb != 0:
        rb = rb[-nb:]
        tb = rb[0]
    else:
        rb = []
        tb = 0

    # print(ra, na)
    # print(rb, nb)
    ia = 0
    ib = 0

    while ta + tb > K:
        # print(ta, tb)
        if ra[ia] > rb[ib]:
            ia = ia + 1
            na = na - 1
            if na == 0:
                ta = 0
            else:
                ta = ra[ia]
        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:
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
        else:
            low = mid+1
    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:
i = list(map(int, input().split()))
n=i[0]
m=i[1]
k=i[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a=b=0 #それぞれの読んだ数
cal=0 #読んだ時間
while True:
    if a!=n and b!=m:
        if A[a]<=B[b]:
            cal+=A[a]
            if cal>k:
                break
            a+=1
        elif B[b]<A[a]:
            cal+=B[b]
            if cal>k:
                break
            b+=1
    elif a==n and b==m:
        break
    elif a==n and b!=m:
        cal+=B[b]
        if cal>k:
            break
        b+=1
    elif a!=n and b==m:
        cal+=A[a]
        if cal>k:
            break
        a+=1
print(a+b)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
As= list(map(int,input().split()))
Bs= list(map(int,input().split()))
print(As)
print(Bs)
#----------
def ShouldReadAs4(As,Bs):
    if As==Bs:
        return True
    
    AsFirst= As+Bs
    BsFirst= Bs+As

    for i in range(1,len(AsFirst)+1):
        if sum(AsFirst[:i])<sum(BsFirst[:i]):
            return True
        elif sum(AsFirst[:i])>sum(BsFirst[:i]):
            return False
#----------
count=0

while (K>0):
    if ShouldReadAs4(As,Bs):
        K-=As.pop(0)
    else:
        K-=Bs.pop(0)
    count+=1
    
if len(As)>0 or len(Bs)>0:
    print(count-1)
else:
    print(count)

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()]
s = 0
ans = 0
ca = 0
for i in range(n):
  if k >= s + a[i]:
    s += a[i]
    ans += 1
    ca += 1
  else:
    break
cb = 0
for i in range(m):
  if k >= s + b[i]:
    s += b[i]
    ans += 1
    cb += 1
  else:
    break
if ans == n + m or ans == 0:
  print(ans)
else:
  l = []
  l.append(ans)
  while ca > 0:
    s - a[ca - 1]
    ca -= 1
    ans -= 1
    if k >= s + b[cb - 1]:
      s += b[cb - 1]
      cb += 1
      ans += 1
      l.append(ans)
  print(max(l))

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()))
if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
else:
    A = deque(A)
    B = deque(B)
    time = 0
    ans = 0
    while time <= K:
        if len(A) == 0:
            if B[0] <= time - K:
                time += B[0]
                ans += 1
                B.popleft()
            else:
                break
        elif len(B) == 0:
            if A[0] <= time - K:
                time += A[0]
                ans += 1
                A.popleft()
            else:
                break
        else:
            if min(A[0], B[0]) <= time - K:
                if A[0] <= B[0]:
                    time += A[0]
                    ans += 1
                    A.popleft()
                else:
                    time += B[0]
                    ans += 1
                    B.popleft()
            else:
                break
    print(ans)

Submission status: Wrong Answer

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

a=N
b=M
count =0

while K != "sf":
    
    if a >0 and b > 0:
        if A[N-a] < B[M-b]:
            count += 1
            K -= A[N-a]
            a -=1
            
        elif A[N-a] > B[M-b]:
            count += 1
            K -=  B[M-b]
            b -=1
            
        elif A[N-a] == B[M-b]:
            if a-1>=0 and b-1 >=0:
                if A[N-a] <= B[M-b]:
                    count += 1
                    K -= A[N-a]
                    a -=1
            
                elif A[N-a] > B[M-b]:
                    count += 1
                    K -=  B[M-b]
                    b -=1
            elif a-1 >=0 and b-1 <0:
                count += 1
                K -= A[N-a]
                a -=1
            elif b-1 >=0 and a-1 <0:
                count += 1
                K -= B[M-b]
                b -=1
            else:
                count += 1
                K -= A[N-a]
                a -=1
                
            
    elif a>0 and b ==0:
        count += 1
        K -= A[N-a]
        a -=1
        
    
    elif b>0 and a ==0:
        count += 1
        K -= B[M-b]
        b -=1
        
    else:
        break
    #print(count,K,N-a,M-b)
    
    if K < 0:
        count -= 1
        break
    
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()))

count=0
while(1):
  len_a = len(A)
  len_b = len(B)
  if len_a != 0 and len_b  != 0:
    if K - A[0] < 0 and K - B[0] < K:
      break
  elif len_a == 0 and len_b  != 0:
    if K - B[0] < 0:
      break
  elif len_a  != 0 and len_b == 0:
    if K - A[0] < 0:
      break
  elif len_a  == 0 and len_b == 0:
    break
  
  if len_a  != 0 and len_b != 0:
    if A[0]/(sum(A)/len_a) < B[0]/(sum(B)/len_b):
      K = K - A.pop(0)
      count=count+1
    elif A[0]/(sum(A)/len_a) > B[0]/(sum(B)/len_b):
      K = K - B.pop(0)
      count=count+1
  elif len_a == 0 and len_b != 0:
    K = K - B.pop(0)
    count=count+1
  elif len_a != 0 and len_b == 0:
    K = K - A.pop(0)
    count=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()]
a = [0]*N
b = [0]*M
a[0] = A[0]
b[0] = B[0]
ae = N-1
be = M-1
e = 0
for i in range(1, N):
    a[i] = a[i-1] + A[i]
    if(a[i] > K):
        ae = i-1
        break
for i in range(1, M):
    b[i] = b[i-1] + B[i]
    if(b[i] > K):
        be = i-1
        break
ans = 0
for i in range(ae, -1, -1):
    ans = max(ans, i+1)
    for j in range(e, be+1):
        if a[i] + b[j] > K:
            e = max(j-1, 0)
            break
        ans = max(ans, i+j+2)
print(ans)

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)
time0 = 0
acount = 0
bcount = 0

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

print(hic)

Submission status: Wrong Answer

Solution code:
k = [int(x) for x in input().split()][2]
ab = [int(x) for x in input().split()] + [int(x) for x in input().split()]
O = 0
ab.sort()
def calc(k, ab):
    return k - ab
for i in range(len(ab)):
    calc(k, ab[0])
    if k < 0:
        break
    ab.pop(0)
    O +=1
print(O)

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

Submission status: Wrong Answer

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

A_ind = 0
B_ind = 0
count = 0
ans = 0

for i in range(N+M): 
  if A_N[0] < B_M[0]:
    if count <= K - A_N[0]:
      count += A_N.pop(0)
      ans += 1
      if len(A_N) == 0:
        A_N.append(10000000000)
  else:
    if count <= K - B_M[0]:
      count += B_M.pop(0)
      ans += 1
      if len(B_M) == 0:
        B_M.append(10000000000)      
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()))


for c in range(abs(M - N) + 3):
    A.append(10000000001)
    B.append(10000000001)

a = 0
b = 0
k = 0
ans = 0

while k <= K:
    if A[a] >= B[b]: # Bのほうが小さい場合
        k += B[b]
        b += 1
    else: # Aのほうが小さい場合
        k += A[a]
        a += 1
    if k > K or N + M == ans:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = [input() for i in range(3)]
list1 = list(map(int, s[0].split()))
n = list1[0]
m = list1[1]
k = list1[2]

list2 = list(map(int, s[1].split()))
list3 = list(map(int, s[2].split()))

counter_l1 = 0
counter_l2 = 0

for i in range(n+m):
    print("i:",i,",counter_l1:",counter_l1,",counter_l2:",counter_l2)
    if counter_l1 < n and counter_l2 < m:
        print("list2[",counter_l1,"]:",list2[counter_l1])
        print("list3[",counter_l2,"]:",list3[counter_l2])
        if list2[counter_l1] < list3[counter_l2]:
            k = k - list2[counter_l1]
            print("k:",k)
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l1 +=1
            continue
        if list2[counter_l1] >= list3[counter_l2]:
            k = k - list3[counter_l2]
            print("k:",k)
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l2 +=1
    else:
        if counter_l1 >= n:
            print("list3[",counter_l2,"]:",list3[counter_l2])
            k = k - list3[counter_l2]
            print("k:",k)
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
            counter_l2 +=1
        if counter_l2 >= m:
            print("list2[",counter_l1,"]:",list2[counter_l1])
            k = k - list2[counter_l1]
            print("k:",k)
            if k < 0:
                break
            if k == 0:
                counter_l1 +=1
                break
print(counter_l1+counter_l2)

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
n ,m ,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a = list(itertools.accumulate(a))
b = list(itertools.accumulate(b))
A =bisect.bisect_left(a,k)
count=0

if A<n:
  if a[A]==k:
    A+=1
if b[0]>k:
  print(A)
  exit()
if a[0]>k:
  B =bisect.bisect_left(b,k)
  if B<m:
    if b[B]==k:
      B+=1
  print(B)
  exit()

for i in range(A,1,-1):
  ans=k-a[i-1]
  B =bisect.bisect_left(b,ans)
  if B<m:
    if b[B]==ans:
      B+=1
  count=max(count,i+B)
print(count)

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 and b_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

    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 (len(a)>0 or len(b)>0) and ((len(a)>0 and k>=a[0]) or (len(b)>0 and k>=b[0])):
    if len(a)>0 and len(b)>0 and k<a[0] and k<b[0]:
        break
    else:
        sum1 = 0
        sum2 = 0
        i1=0
        i2=0
        while i1<len(a) and sum1+a[i1]<=k:
            sum1+=a[i1]
            i1+=1
        while i2<len(b) and sum2+b[i2]<=k:
            sum2+=b[i2]
            i2+=1
        if i1==i2:
            if sum1<sum2:
                ans+=i1
                a=a[i1:]
                k-=sum1
            else:
                ans+=i2
                b=b[i2:]
                k-=sum2
                
        elif i1>i2:
            ans+=i1
            a=a[i1:]
            k-=sum1
        else:
            ans+=i2
            b=b[i2:]
            k-=sum2
        

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
end_a = False
end_b = False
if sum(a) + sum(b) <= k:
    print(len(a)+len(b))
    exit()
while(True):
    k -= min(a[0], b[0])
    if k >= 0:
        ans += 1
    else:
        break
    if a[0] > b[0]:
        del b[0]
    else:
        del a[0]
    if len(a) == 0:
        a = [1e9+1]
        end_a = True
    if len(b) == 0:
        b = [1e9+1]
        end_b = True
    if end_a and end_b:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
time = 0
book_a = 0
book_b = 0

for i in range(len(a)):
    if time > k:
        break
    bb = b[book_b:]
    for j in bb:
        if time > k:
            break
        elif a[i] < j:
            time = time + a[i]
            book_a = book_a + 1
            break
        else:
            time = time + j
            book_b = book_b + 1

bb = b[book_b:]
if time < k:
    for i in bb:
        if time > k:
            break
        else:
            time = time + i
            book_b = book_b + 1

if book_a + book_b == len(a) + len(b):
    print(book_a + book_b)
else:
    print(book_a + book_b -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]*N
b=[0]*M
a[0]=A[0]
b[0]=B[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i]
for i in range(M-1):
    b[i+1]=b[i]+B[i]
diff=2*10**9
count=0
for i in range(N):
    for j in range(M):
        if 0<=K-(a[i]+b[j])<=diff:
            diff=K-(a[i]+b[j])
            count=max(count,(i+1)+(j+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()))

suma = [ -1 for i in range(n) ]
sumb = [ -1 for i in range(m) ]
suma[0] = a[0]
sumb[0] = b[0]
nn = n
mm = m
for i in range(1,n):
  suma[i] = suma[i - 1] + a[i]
  if suma[i] > k:
    nn = i
    break
for i in range(1,m):
  sumb[i] = sumb[i - 1] + b[i]
  if sumb[i] > k:
    mm = i
    break

c = 0
t = 0
cc = 0
for i in range(nn):
  if suma[i] <= k:
    t = suma[i]
    c = i + 1
    cc = max(cc,c)
  for j in range(mm):
    tt = t + sumb[j]
    if tt <= k:
      cc = max(cc,c + j + 1)

print(cc)