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()))
ni = 0
mi = 0
now = 0
cnt= 0
while True:
    if ni < n and mi < m:
        if a[ni] <= b[mi] and now + a[ni] <= k:
            now += a[ni]
            ni += 1
            cnt += 1
        elif a[ni] >= b[mi] and now + b[mi] <= k:
            now += b[mi]
            mi += 1
            cnt += 1
        else:
            break
    elif ni < n:
        if now + a[ni] <= k:
            now += a[ni]
            ni += 1
            cnt += 1
        else:
            break
    elif mi < m:
        if now + b[mi] <= k:
            now += b[mi]
            mi += 1
            cnt += 1
        else:
            break
    else:
        break
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()))

read = 0

i = 0
j = 0

while K - A[i] >= 0 or K - B[j] >= 0:
    if N > 0 and M > 0:
        if A[i] <= B[j]:
            N -= 1
            read += 1
            K -= A[i]
        else:
            M -= 1
            read += 1
            K -= B[i]
    elif N <= 0 and M > 0:
        M -= 1
        read += 1
        K -= B[i]
    elif N > 0 and M <= 0:
        N -= 1
        read += 1
        K -= A[i]
    else:
        break

print(read)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a = deque(a)
b = deque(b)

t = 0
cnt = 0

while t < k:
    if a and b:
        if a[0] <= b[0]:
            t += a.popleft()
        else:
            t += b.popleft()
        cnt += 1
    elif a:
        t += a.popleft()
        cnt += 1
    elif b:
        t += b.popleft()
        cnt += 1
    else:
        break

if t > k:
    cnt -= 1

print(cnt)

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_top = 0
B_top = 0
time = 0
while time < K:
    if A[0] > K and B[0] > K:
        break

    if A_top >= len(A) and B_top < len(B) and time + B[B_top] <= K:
        time += B[B_top]
        B_top += 1
        continue
    elif A_top >= len(A) and time + B[B_top] > K:
        break
    

    
    if B_top >= len(B) and A_top < len(A) and time + A[A_top] <= K:
        time += A[A_top]  
        A_top += 1
        continue
    elif B_top >= len(B) and time + A[A_top] > K:
        break


    if A[A_top] < B[B_top] and time + A[A_top] <= K:
        
        time += A[A_top]
        A_top += 1
        continue
    if A[A_top] > B[B_top] and time + B[B_top] <= K:
        
        time += B[B_top]
        B_top += 1
        continue
    
    break

result = A_top + B_top
# if time > K and result > 0:
#     result -= 1

print(result)

Submission status: Wrong Answer

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

while AB > K:
    if A[a]<B[b]:
        AB -= B[b]
        x -= 1
    else:
        AB -= A[a]
        x -= 1

print(x)

Submission status: Wrong Answer

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

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0

arAll = arA + arB
arAll.sort()

for idx in range(n+m):
    readTime += arAll[idx]
    if readTime > k:
        break
    readBooks += 1

print(readBooks)

Submission status: Wrong Answer

Solution code:
NMK = list(map(int, input().split()))

Asum = []
Bsum = []

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

sum = 0
for i in range(NMK[0]):
    sum += A[i]
    Asum.append(sum)

sum = 0
for i in range(NMK[1]):
    sum += B[i]
    Bsum.append(sum)

cutA = 0
max = NMK[2]
indexA = 0
while(True):
    cutA = Asum[indexA]
    if (max < cutA):
        break
    indexA += 1
    if (indexA == NMK[0]):
        break
if (indexA == 0):
    maxA = 0
else:
    maxA = Asum[indexA - 1]

cutB = 0
indexB = 0
while(True):
    cutB = Bsum[indexB]
    if (max < cutB):
        break
    indexB += 1
    if (indexB == NMK[1]):
        break
if (indexB == 0):
    maxB = 0
else:
    maxB = Bsum[indexB - 1]

answer = 0
remain = 0
index = 0
if (indexA > indexB):
    answer = indexA
    remain = NMK[2] - maxA
    while(index < NMK[1] and remain >= Bsum[index]):
        answer += 1
        index += 1
elif (indexB > indexA):
    answer = indexB
    remain = NMK[2] - maxB
    while(index < NMK[0] and remain >= Asum[index]):
        answer += 1
        index += 1
else:
    if (maxA < maxB):
        answer = indexA
        remain = NMK[2] - maxA
        while (index < NMK[1] and remain >= Bsum[index]):
            answer += 1
            index += 1
    elif (maxA > maxB):
        answer = indexB
        remain = NMK[2] - maxB
        while (index < NMK[0] and remain >= Asum[index]):
            answer += 1
            index += 1
    else:
        if (maxA != 0):
            answer = indexA
            remain = NMK[2] - maxA
            while (index < NMK[1] and remain >= Bsum[index]):
                answer += 1
                index += 1

print(answer)

Submission status: Wrong Answer

Solution code:
from collections import deque

def take_judge(A,B):
    n = min(len(A),len(B))
    for i in range(n):
        if A[i]<B[i]:
            return len(A)
        elif B[i]<A[i]:
            return len(B)
        else:
            return n

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

time = 0
cnt = 0

while time <= K:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        if B[0]+time <= K:
            time += B[0]
            cnt += 1
            B.popleft()
        else:
            break
    elif len(B) == 0:
        if A[0]+time <= K:
            time += A[0]
            cnt += 1
            A.popleft()
        else:
            break
    else:
        if B[0]+time <= K or A[0]+time <= K:
            if A[0] < B[0]:
                time += A[0]
                cnt += 1
                A.popleft()
            elif A[0] > B[0]:
                time += B[0]
                cnt += 1
                B.popleft()
            else:
                if take_judge(A,B) == len(A):
                    time += A[0]
                    cnt += 1
                    A.popleft()
                else:
                   time += B[0]
                   cnt += 1
                   B.popleft() 
        else:
            break
        
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()))

sum_a = sum(A)
sum_b = sum(B)
time = sum_a + sum_b
ans = n+m

a = [0 for i in range(n)]
count = A[0]
a[0] = count
for i in range(1,n):
    count += A[i]
    a[i] = count

b = [0 for i in range(m)]
count = B[0]
b[0] = count
for i in range(1,m):
    count += B[i]
    b[i] = count

while time > k:
    if n != 0 and m != 0:
        if a[n-1] >= b[m-1]:
            ans -= 1
            time -= B[m-1]
            n -= 1
        else:
            ans -= 1
            time -= A[n-1]
            m -= 1
    elif n == 0 and m != 0:
        ans -= 1
        time -= B[m-1]
        m -= 1
    elif n != 0 and m== 0:
        ans -= 1
        time -= A[n-1]
        n -= 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
a = deque()
b = deque()

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

for i in input().split():
    a.append(int(i))
for j in input().split():
    b.append(int(j))


su = 0
cnt = 0
while su <= k :
    if len(a)==0 and len(b)==0:
        break
    elif len(a)==0:
        tmpb = b.popleft()
        if su+tmpb <= k:
            su = su + tmpb
            cnt +=1
        else:
            break
    elif len(b)==0:
        tmpa = a.popleft()
        if su+tmpa <= k:
            su = su + tmpa
            cnt += 1
        else:
            break
    else:
        tmpa = a.popleft()
        tmpb = b.popleft()
        if tmpa <= tmpb and su+tmpa <=k:
            su = su+tmpa
            cnt += 1
            b.appendleft(tmpb)
        elif tmpa > tmpb and su+tmpb <=k:
            su = su+tmpb
            cnt += 1
            a.appendleft(tmpa)
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M, K = MAP()
A = LIST()
B = LIST()

a = list(accumulate(A))
b = list(accumulate(B))

ans = 0
for i in range(N):
	if a[i] <= K:
		ans = max(ans, i +1 + bisect(b, K-a[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys #追加
sys.setrecursionlimit(500*500)

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

time = 0
cnt = 0
ans = 0
b = []

for i in B:
    if i+time>K:
        break
    time += i
    cnt += 1
    b.append(i)

b.reverse()
# print(b)
# print(cnt)
bi = 0
for i in range(N):
    if time+A[i] <= K:
        cnt += 1
        time += A[i]
    else:
        if len(b)-1 >= bi:
            if A[i] <= b[bi]:
                time -= b[bi]-A[i]
                bi += 1
        else:
            break
            # print("a")
            # print(time+A[i])
       
    # print(time)


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

A.append(-1)
B.append(-1)

ans = 0
ai = 0
bi = 0
time = k
while True:
  if A[ai] != -1 and B[bi] != -1:
    if A[ai] < B[bi] and time > A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    elif A[ai] > B[bi] and time > B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  elif A[ai] != -1:
    if time > A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    else:
      break
  elif B[bi] != -1:
    if time > B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  else:
    break

print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
from bisect import bisect

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

A = [int(y) for y in input().split()]
B = [int(y) for y in input().split()]

A_time = [0] * N
B_time = [0] * M

rui = 0
k = 0
flag = True

for i in range(N):
    rui += A[i]
    A_time[i] = rui
    if(rui > K and flag):
        k = i
        flag = False

if k == 0:
    k = N
    

rui = 0

for i in range(M):
    rui += B[i]
    B_time[i] = rui

T = 0
po = 0
num = 0

for i in range(k):
    
    T = K - A_time[i]
    
    if T < 0:
        continue
    
    po = bisect(B_time,T)
    
    num = max(num, po + i + 1)

print("{}".format(num))

Submission status: Wrong Answer

Solution code:
n,m,K = map(int,input().split())
A = list(map(int,input().split())) #using a
B = list(map(int,input().split())) #using b

a=0
b=0
ans = 0

while K>0:
    if (a == len(A) and b == len(B)):
        break
    elif  (a == len(A)):
        K-=B[b]
        b+=1
        ans+=1
    elif(b == len(B)):
        K-=A[a]
        a+=1
        ans+=1
    else:
        if A[a]<=B[b]:
            K-=A[a]
            a+=1
            ans+=1
        else:
            K-= B[b]
            b+=1
            ans+=1
if (K<0):
    ans-=1
print(ans)

Submission status: Wrong Answer

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

n_time = list(map(int, input().split()))
m_time = list(map(int, input().split()))

time = n_time + m_time

result = 0
count = 0

for i in range(len(time)):
    if(result > 1000000000):
        count = 0
        break
    if(result > max_time and count < 1):
        break
    elif(result > max_time and count > 1):
        count -= 1
        break
    else:
        result += min(time)
        time.remove(min(time))
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(99999)
B.append(99999)
Sum = 0
i = 0
j = 0
while Sum < K:
  if A[i] <= B[j]:
    Sum += A[i]
    i += 1
  else:
    Sum += B[j]
    j += 1
if Sum >= 1000000000:
  print(0)
else:
  print(i + j)

Submission status: Wrong Answer

Solution code:
import sys

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

N, M, K = map(int, readline().split())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

INF = 1 << 60
A.append(INF)
B.append(INF)

p, q = 0, 0
while True:
    if A[p] > B[q]:
        A, B = B, A
        p, q = q, p
    x = A[p]
    p += 1
    if K >= x:
        K -= x
    else:
        break

print(p + q - 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

A.reverse()
B.reverse()

while (True):
    a = len(A) - 1
    b = len(B) - 1
    if a >= 0 and b >= 0:
        if A[a] <= B[b] and A[a] <= K:
            K -= A.pop(a)
            c += 1

        elif B[b] <= K:
            K -= B.pop(b)
            c += 1

        else:
            break

    elif a >= 0:
        if A[a] <= K:
            K -= A.pop(a)
            c += 1

        else:
            break
    
    elif b >= 0:
        if B[b] <= K:
            K -= B.pop(b)
            c += 1

        else:
            break
        
    else:
        break

print(c)

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()))
import numpy
import sys
a_x = numpy.cumsum(a)
b_x = numpy.cumsum(b)

ans = 0
a_count = [x for x in a_x if x <=k]
b_count = [x for x in b_x if x <=k]

if len(a_count)== 0 and len(b_count)==0:
    print("0")
    sys.exit()
elif len(a_count) == 0:
    print(len(b_count))
    sys.exit()
elif len(b_count) == 0:
    print(len(a_count))
    sys.exit()


if len(a_count) == len(b_count):#どちらからとった方が良い
    if a_count[-1] < b_count[-1]:
        a_rest = [k-x for x in a_x]
        for i in range(len(a_rest)):
            count = len([1 for x in b_x if x <= a_rest[i]])
            if ans < i+1+count:
                ans = i+1+count
    else:
        b_rest = [k-x for x in b_x]
        for i in range(len(b_rest)):
            count = len([1 for x in a_x if x <= b_rest[i]])
            if ans < i+1+count:
                ans = i+1+count
                
elif len(a_count) > len(b_count):
    a_rest = [k-x for x in a_x]
    for i in range(len(a_rest)):
        count = len([1 for x in b_x if x <= a_rest[i]])
        if ans < i+1+count:
            ans = i+1+count
else:
    b_rest = [k-x for x in b_x]
    for i in range(len(b_rest)):
        count = len([1 for x in a_x if x <= b_rest[i]])
        if ans < i+1+count:
            ans = i+1+count
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()))

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

from bisect import bisect_left,bisect

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

print(kmax)

Submission status: Wrong Answer

Solution code:
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()))

for i in range(n+m+2):
    if not a and not b:
        print(i)
        sys.exit()
    elif not a:
        x = b.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
    elif not b:
        x = a.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
    elif a[0] < b[0]:
        x = a.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
    else:
        x = b.popleft()
        if k < x:
            print(i)
            sys.exit()
        else:
            k -= x
print(n+m)

Submission status: Wrong Answer

Solution code:
import numpy as np 

import itertools

# A = [100,150, 200,300]
# B = [200, 50, 100,]

# T = 400

N,M,T = input().split()
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

T = int(T)

ca = np.cumsum(A)
ca = ca[ca<T]
cb = np.cumsum(B)
cb = cb[cb<T]

 
lst = np.array(list(itertools.product([[i+1,c] for i, c in enumerate(ca)], [[i+1,c] for i, c in enumerate(cb)])))

max_num = 0

for l in lst:
#     print(l)
    t = l[0][1]+l[1][1]
#     print(t)
    num = l[0][0] + l[1][0]
    if t <= T and num > max_num:
#         print(t,"ok")
        max_num = num

print(max_num)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from itertools import accumulate


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, M, K = zz()
A = zz()
B = zz()
# 累積和を見てみる
A_sum = list(accumulate(A))
B_sum = list(accumulate(B))
a_idx = 0
b_idx = 0
# a_idx + b_idx を最大化
# K >= A_sum[a_idx+1] + B_sum[b_idx+1]
a_idx = bisect.bisect(A_sum, K) - 1
# a_read = a_idx
a_time = A_sum[a_idx-1]
ans = a_idx+1
if (a_idx == -1):
    b_idx = bisect.bisect(B_sum, K)
    print(b_idx)
    exit()
else:
    for b_idx in range(M):
        # print(B_sum[b_idx] + A_sum[a_idx], a_idx, b_idx)
        while (B_sum[b_idx] + A_sum[a_idx] > K):
            a_idx -= 1
            if (a_idx < 0):
                print(max(ans, 0))
                exit()
        ans = max(ans, a_idx+b_idx+2)
# print('<', a_idx)
print(max(ans, 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()))
count = 0
time = 0
i = j = 0
while i < len(A) and j < len(B):
    if A[i] < B[j]:
        time += A[i]
        i += 1
    else:
        time += B[j]
        j += 1
    if time < 0 or time > K:
        break
    count += 1
while i < len(A):
    time += A[i]
    i += 1
    if time < 0 or time > K:
        break
    count += 1
while j < len(B):
    time += B[j]
    j += 1
    if time < 0 or time > K:
        break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
cnt = 0
while True:
    if a and b:
        if a[0] < b[0]:
            time += a.pop(0)
            if time > k:
                break
            cnt += 1
        else:
            time += b.pop(0)
            if time > k:
                break
            cnt += 1
    elif a:
        time += a.pop(0)
        if time > k:
            break
        cnt += 1
    elif b:
        time += b.pop(0)
        if time > k:
            break
        cnt += 1
    else:
        break

print(cnt)

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]"):
    if A[0] > K and B[0] > K:
        print(0)
        return

    candidateA = []
    weightA = 0
    tmp_A = N
    for idx, a in enumerate(A):
        if weightA + a > K:
            tmp_A = idx
            break
        else:
            weightA += a
    candidateA = A[:tmp_A]
    max_count = current_count = len(candidateA)

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

        if len(candidateA)==0:
            break

        if weightA + weightB + b <= K:
            weightB += b
            candidateB.append(b)
            current_count += 1

        elif terminated==False:
            while weightA + weightB + b > K:
                if len(candidateA)>0:
                    weightA -= candidateA.pop()
                    current_count -= 1
                else:
                    terminated=True

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

    print(max_count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

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())))
p = A.popleft()
q = B.popleft()
SK = 0
Ans = 0
while SK < K or SK == K:
    if p <= q:
        SK += p
        Ans += 1
        if A != deque([]):
            p = A.popleft()
        else:
            p = 10**10
    else:
        SK += q
        Ans += 1
        if B != deque([]):
            q = B.popleft()
        else:
            q = 10**10
print(Ans-1)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
a,b=l1[0],l2[0];c=0;x,y=0,0
while(k>=0):
  if x<len(l1) and y<len(l2) and min(l1[x],l2[y])<=k:
    k=k-min(l1[x],l2[y]);
    if l1[x]<l2[y]:
      x+=1;
    else:
      y+=1;
  elif x<len(l1) and l1[x]<=k:
    k=k-l1[x];
    x=x+1;
  elif y<len(l2) and l2[y]<=k:
    k=k-l2[y];
    y=y+1;
  else:
    break;
  c=c+1;
print(c)

Submission status: Wrong Answer

Solution code:
# import io
# import sys

# _INPUT = """\
# 1 4 100
# 60
# 80 150 80 150
# """
# sys.stdin = io.StringIO(_INPUT)


N,M,K = map(int, input().split())
A = [int(i) for i in input().split()] + [K+1]
B = [int(i) for i in input().split()] + [K+1]

a = b = k = ans = 0

while True:

  if A[a] < B[b]:
    k += A[a]
    a += 1
  else:
    k += B[b]
    b += 1

  if k > K: break
  ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

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

csumA = []
csumB = []

s = 0
for i in A:
    s += i
    csumA.append(s)
s = 0
for i in B:
    s += i
    csumB.append(s)

ans = 0
for i in range(N):
    if K - csumA[i] >= 0:
        ans = max(ans,i+1+bisect(csumB,max(0,K-csumA[i])))

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()))
o = n + m

t = 0
for i in range(o):
    #print(a)
    if not a:
        t += b[0]
        b = b[1:]
    elif not b:
        t += a[0]
        a = a[1:]
    elif 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:
from collections import deque
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))


arr1=deque(arr1)
arr2=deque(arr2)

# print(arr1)
# print(arr2)
ans=0
# print(arr1,arr2,k)
while True:
    val1=arr1[0]
    val2=arr2[0]
    if val1<=val2:
        if k-val1>=0:
            ans+=1
            k-=val1
            arr1.popleft()
        else:
            break
    else:
        if k-val2>=0:
            ans+=1
            k-=val2
            arr2.popleft()
        else:
            break
    # print(arr1,arr2,k)
    if len(arr1)==0 or len(arr2)==0:
        break
    
if len(arr1)==0 and len(arr2)!=0:
    for i in arr2:
        if k-i>=0:
            ans+=1
            k-=i
        else:
            break
# print(k)
if len(arr1)!=0 and len(arr2)==0:
    for i in arr1:
        if k-i>=0:
            ans+=1
            k-=i
        else:
            break
# print(k)    
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=(int(i) for i in input().split())
l1=[int(i) for i in input().split()]
l2=[int(i) for i in input().split()]
c=0
minu=0
i=0
j=0
while(minu<=k):
    if(i<n and j<m):
        k1=min(l1[i],l2[j])
        if(minu+k1<=k):
            minu+=k1
            c+=1
            if(k1==l1[i]):
                i+=1
            else:
                j+=1
        else:
            break
    elif(i<n):
        if(minu+l1[i]<=k):
            minu+=l1[i]
            c+=1
            i+=1
        else:
            break
    elif(j<m):
        if(minu+l2[j]<=k):
            minu+=l2[j]
            c+=1
            j+=1
        else:
            break
    else:
        break
s1,s2,c1,c2=0,0,0,0
for i in range(n):
    if(s1+l1[i]<=k):
        s1+=l1[i]
        c1+=1
    else:
        break
for i in range(m):
    if(s2+l2[i]<=k):
        s2+=l2[i]
        c2+=1
    else:
        break
k2=max(c1,c2)
if(k2==c1):
    for i in range(c2):
        if(s1+l2[i]<=k):
            s1+=l2[i]
            k2+=1
        else:
            break
else:
    for i in range(c1):
        if(s2+l1[i]<=k):
            s2+=l1[i]
            k2+=1
        else:
            break
print(max(k2,c))

Submission status: Wrong Answer

Solution code:
N, M, KK = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

max = N + M
  #print(max)
sum = 0

for i in range(max):

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

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()))
cnta=0
cntb=0
time=0
while time<=k:
    if cntb==len(B) or cnta!=len(A) and A[cnta]<B[cntb]:
        time+=A[cnta]
        cnta+=1
    elif cnta==len(A) or cntb!=len(B) and A[cnta]>=B[cntb]:
        time+=B[cntb]
        cntb+=1
    if cnta+cntb == len(A)+len(B):
        break
if cnta+cntb == len(A)+len(B):
    print(cnta+cntb)
else:
    print(cnta+cntb-1)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
A=list(map(int,input().split()))+[10**10]
B=list(map(int,input().split()))+[10**10]
cnt=0
temp=0
Ai=0
Bi=0
for i in range(n+m):
  if Ai==n and Bi==m:
    break;
  elif Ai==n and Bi<m:
    if temp+B[Bi]<=k:
      temp+=B[Bi]
      cnt+=1
      Bi+=1
    else:
      break;
  elif Bi==m and Ai<n:
    if temp+A[Ai]<=k:
      temp+=A[Ai]
      cnt+=1
      Ai+=1
    else:
      break;
  elif Ai<n and Bi<m:
    if A[Ai]<=B[Bi]:
      if temp+A[Ai]<=k:
        temp+=A[Ai]
        cnt+=1
        Ai+=1
      else:
        break;
    elif A[Ai]>B[Bi]:
      if temp+B[Bi]<=k:
        temp+=B[Bi]
        cnt+=1
        Bi+=1
      else:
        break;
      
print(cnt)