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 bisect import bisect_right

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [a[0]]
B = [b[0]]
for i in range(1, n):
    A.append(A[-1] + a[i])
for j in range(1, m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n):
    time = A[i]
    b_index = 0
    if time > k:
        break
    if k  - time >= 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + 1 + b_index)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

t=0
cnt=0
while t<=K:
    if len(A)!=0 and len(B)!=0:
        if A[0]>=B[0]:
            t+=B.popleft()
            if t<=K:
                cnt+=1
        else:
            t+=A.popleft()
            if t<=K:
                cnt+=1
    elif len(A)==0 and len(B)==0:
        break
    elif len(A)==0:
        t+=B.popleft()
        if t<=K:
            cnt+=1
    else:
        t+=A.popleft()
        if t<=K:
            cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M,K = LI()
A = LI()
B = LI()

cusumA = [A[0]]*N
cusumB = [B[0]]*M

for i in range(1,N):
    cusumA[i] = cusumA[i-1]+A[i]

for i in range(1,M):
    cusumB[i] = cusumB[i-1]+B[i]

ans = 0
for i in range(N):
    left = K-cusumA[i]
    if left < 0:
        break
    p = bisect_right(cusumB,left)
    num = i+1+p
    if num > ans:
        ans = num

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,b=[0],[0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
print(a)
print(b)
ans,j=0,m
for i in range(n+1):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    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()))

a = [0]
aa = 0
for i in range(1,N+1):
    aa += A[i-1]
    a.append(aa)
    
b = [0]
bb = 0
for i in range(1,M+1):
    bb += B[i-1]
    b.append(bb)
    
time0 = 1
i = 0
j = 0

while(time0<=K):
    if i+1 > N and j+1 > M:
        break
    elif i+1 <= N and j+1 > M:
        if a[i+1] + b[j] <= time0:
            i += 1
    elif i+1 > N and j+1 <= M:
        if a[i] + b[j+1] <= time0:
            j += 1
    elif a[i+1] + b[j] <= time0 or a[i] + b[j+1] <= time0:
        if a[i] + b[j+1] > time0:
            i += 1
        elif a[i+1] + b[j] > time0:
            j += 1
        else:
            i += 1
    time0 += 1
    
            
print(i+j)

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))

B_sum = [0] * (M + 1)
for i in range(M):
    B_sum[i+1] = B_sum[i] + B[i] # B_sumのindexが冊数

result = 0
time_count = K
for i in A:
    time_count -= i
    if time_count < 0 or time_count < B_sum[1]:
        break
    else:
        tmp = bisect.bisect_right(B_sum, time_count) - 1 + A.index(i)
        result = max(result, tmp)

print(result)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M,K = LI()
A = LI()
B = LI()

A.append(float('inf'))
B.append(float('inf'))

A = list(reversed(A))
B = list(reversed(B))

now = 0
ans = 0
while len(A) or len(B):
    min_ = min(A[-1],B[-1])
    if now + min_ <= K:
        if A[-1] == min_:
            A.pop()
        else:
            B.pop()
        now += min_
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
def readinput():
    n,m,k=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    return n,m,k,a,b

def main(n,m,k,a,b):
    qa=deque(a)
    qb=deque(b)
    count=0
    res=k
    while(len(qa)>0 and len(qb)>0):
        if qa[0] < qb[0]:
            res-=qa[0]
            qa.popleft()
        else:
            res-=qb[0]
            qb.popleft()
        if res<0:
            return count
        count+=1
    else:
        if len(qa)==0:
            while(len(qb)>0):
                res-=qb[0]
                qb.popleft()
                if res<0:
                    return count
                count+=1
            return count
        else:
            while(len(qa)>0):
                res-=qa[0]
                qa.popleft()
                if res<0:
                    return count
                count+=1
            return count

import sys
INFTY=sys.maxsize
def find(t,s):
    '''
    単調増加配列sからs[i]がtを超えない最大のiを返す
    '''
    ss=s[:]
    ss.append(INFTY)
    left=0
    right=len(ss)
    while(left<right):
        middle=(left+right)//2
        #print(left,middle,right,t,ss)
        if ss[middle]==t:
            #print(middle, ss)
            return middle
        if t<ss[middle]:
            right=middle
        else:
            left=middle+1
    else:
        return left-1

def main2(n,m,k,a,b):
    sa=[0]
    for i in range(1,n+1):
        sa.append(sa[i-1]+a[i-1])
    sb=[0]
    for i in range(1,m+1):
        sb.append(sb[i-1]+b[i-1])
    maxab=0
    nb=m+1
    for na in range(0,n+1):
        res=k-sa[na]
        if res>=0:
            nb=find(res,sb[:nb+1])
            #print(na,nb,sa,sb)
            maxab=max(maxab,na+nb)
    return maxab

from bisect import bisect_left
def main3(n,m,k,a,b):
    sa=[0]
    for i in range(1,n+1):
        sa.append(sa[i-1]+a[i-1])
    sb=[0]
    for i in range(1,m+1):
        sb.append(sb[i-1]+b[i-1])
    maxab=0
    nb=m+1
    for na in range(0,n+1):
        res=k-sa[na]
        if res>=0:
            nb=bisect_left(sb[:nb+1],res)
            #print(na,nb,sa,sb)
            maxab=max(maxab,na+nb)
    return maxab

def main4(n,m,k,a,b):
    sa=[0]
    for i in range(1,n+1):
        sa.append(sa[i-1]+a[i-1])
    sb=[0]
    for i in range(1,m+1):
        sb.append(sb[i-1]+b[i-1])
    maxab=0
    nb=m
    for na in range(0,n+1):
        res=k-sa[na]
        while res<sb[nb] and nb>=0:
            nb-=1
        maxab=max(maxab,na+nb)
        #print(na,nb)
    return maxab

def readinput2():
    m=2*10**5
    n=2*10**5
    a=[10**9]*n
    b=[10**9]*m
    k=1
    return n,m,k,a,b

if __name__=='__main__':
    n,m,k,a,b=readinput()
    ans=main4(n,m,k,a,b)
    print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]


def search(arr, x):
    l, r = 0, len(arr)
    while abs(r - l) > 1:
        mid = (l + r) // 2
        if arr[mid] <= x:
            l = mid
        else:
            r = mid
    return l


ans = 0
for i in range(len(a)):
    rest = k - a[i]
    if rest < 0:
        break
    bidx = search(b, rest)
    if bidx == m:
        break
    ans = max(ans, i + bidx)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]


def search(arr, x):
    l, r = 0, len(arr)
    while abs(r - l) > 1:
        mid = (l + r) // 2
        print(l, r, mid)
        if arr[mid] <= x:
            l = mid
        else:
            r = mid
    return l


arrr = [0, 80, 230, 310, 460]
t = 90
ti = search(arrr, t)

ans = 0
for i in range(len(a)):
    rest = k - a[i]
    if rest < 0:
        break
    bidx = search(b, rest)
    if bidx == m:
        break
    ans = max(ans, i + bidx)
print(ans)

Submission status: Wrong Answer

Solution code:
#累積和を求めてbisect
# 初期入力
from itertools import accumulate
import bisect
import sys
input = sys.stdin.readline
N,M,K = (int(i) for i in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
acuum_A =list(accumulate(A))
acuum_B =list(accumulate(B))

#Aを優先に読む場合、Bは何冊読めるか⇒Aを減らしたらBが何冊読めるか
ans =[]
a =bisect.bisect_right(acuum_A,K)
remainder =K -acuum_A[a-1]
b =bisect.bisect_right(acuum_B,remainder)
ans.append(a+b)
for i in range(1,N):
    ai =a -i
    if ai -1 >=0:
        remainder =K -acuum_A[ai-1]
    else:
        remainder =K
    b =bisect.bisect_right(acuum_B,remainder)
    ans.append(ai+b)
    #print(ai,b,end=" ")
#print()
print(max(ans))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]


def search(arr, x):
    l, r = -1, len(arr)
    while abs(r - l) > 1:
        mid = (l + r) // 2
        print(l, r, mid)
        if arr[mid] <= x:
            l = mid
        else:
            r = mid
    return l


arrr = [0, 80, 230, 310, 460]
t = 90
ti = search(arrr, t)

ans = 0
for i in range(len(a)):
    rest = k - a[i]
    if rest < 0:
        break
    bidx = search(b, rest)
    ans = max(ans, i + bidx)
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()))

m = M+1
cost = []
for n in range(N + 1):
    print(n, m)
    if sum(A[:n]) > K:
        break
    while True:
        print(n, m)
        if sum(A[:n]) + sum(B[:m]) <= K:
            cost.append(n + m)
            break
        m -= 1

print(max(cost))

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.reverse()
B.reverse()

total_time, ans = 0, 0
while True:
    a, b = int(1e10), int(1e10)
    if len(A) != 0: a = A[-1]
    if len(B) != 0: b = B[-1]
    
    total_time += min(a,b)
    if total_time > K: break

    ans += 1
    if a == b:
        if len(A) == 1: B.pop()
        elif len(B) == 1: A.pop()
        elif (A[-2] < B[-2]): A.pop()
        else: B.pop() 
    elif a < b:
        A.pop()
    else:
        B.pop()

print(ans)

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()))
a,b = [0],[0]
for i in range(N):
  a.append(a[i]+A[i])
for j in range(M):
  b.append(b[j]+B[j])
ans = 0
#print(a,b,N+1)
for i in range(N+1):
  if a[i] > K:
    break
  j = 0
  while K - a[i] >= b[j]:
    if j >= M:
      break
    j = j+1
  j = j-1
  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()))

A.reverse()
B.reverse()

total_time, ans = 0, 0
while True:
    a, b = 1e10, 1e10
    if len(A) != 0: a = A[-1]
    if len(B) != 0: b = B[-1]
    
    total_time += min(a,b)
    if total_time > K: break

    ans += 1
    if a < b:
        A.pop()
    else:
        B.pop()

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

a_sum = [0]*(n+1)
b_sum = [0]*(m+1)

for i in range(n):
  a_sum[i+1] =  a_sum[i] + a[i+1]
for j in range(m):
  b_sum[j+1] =  b_sum[j] + b[j+1]

ans = 0
for i in range(n+1):
  j = bisect.bisect(b_sum, k - a_sum[i]) - 1
  tmp = i + j
  ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N, M , K = map(int, input().split())
X = [0] + list(map(int, input().split()))
Y = list(map(int, input().split()))
R,sY,j,t= 0,sum(Y),M,0
for i in range(N):
    t += X[i]
    if t > K: break
    while j and sY+t > K:
        j-=1
        sY -= Y[j]
    R = max(R, j+i)
print(R)

Submission status: Wrong Answer

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

import numpy as np
import bisect

ra=[0]+list(np.cumsum(a))
rb=[0]+list(np.cumsum(b))

ans=0
for i in range(n+1):    
    capa = k - ra[i]
    if ra[i]>0:
        break
    j=bisect.bisect_right(rb,capa)


    ans=max(ans,i-1+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()))

import numpy as np
import bisect

ra=[0]+list(np.cumsum(a))
rb=[0]+list(np.cumsum(b))

ans=0
for i in range(n+1):    
    capa = k - ra[i]
    if ra[i]>0:
        break
    j=bisect.bisect_right(rb,capa)


    ans=max(ans,i-1+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()))

A.reverse()
B.reverse()

total_time, ans = 0, 0
while True:
    if len(A) == 0 and len(B) == 0: break

    a, b = 1e10, 1e10
    if len(A) != 0: a = A[-1]
    if len(B) != 0: b = B[-1]
    
    if total_time + min(a,b) > K: break

    ans += 1
    if a < b:
        total_time += a
        A.pop()
    else:
        total_time += b
        B.pop()

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, m, k = nm()
    a = nl() + [k+1]
    b = nl() + [k+1]
    ai = bi = 0
    als = bs = 0
    while bs + b[bi] < k:
        bs += b[bi]
        bi += 1
    ans = bi
    for i in range(n+1):
        als += a[i]
        if als > k:
            break
        while bs + als > k:
            bi -= 1
            bs -= b[bi]
        ans = max(ans, i + bi + 1)
    print(ans)
    return

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

import numpy as np
import bisect

ra=[0]+list(np.cumsum(a))
rb=[0]+list(np.cumsum(b))

ans=0
for i in range(n+1):    
    capa = k - ra[i]
    if ra[i]<0:
        break
    j=bisect.bisect_right(rb,capa)


    ans=max(ans,i-1+j)
            
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, m, k = nm()
    a = nl() + [k+1]
    b = nl() + [k+1]
    ai = bi = 0
    als = bs = 0
    while bs + b[bi] < k:
        bs += b[bi]
        bi += 1
    ans = bi
    for i in range(n):
        als += a[i]
        if als > k:
            break
        while bs + als > k:
            bi -= 1
            bs -= b[bi]
        ans = max(ans, i + bi + 1)
    print(ans)
    return

solve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque


def _tsundoku(n, m, k, a, b):
    # print(f'{a=}')
    # print(f'{b=}')
    a_len = len(a)
    b_len = len(b)

    ans = [0, 0, 0]

    L = []
    d = deque()
    d.append((0, 0, 0))
    while d:
        # print(d, L)
        a_readed, b_readed, t = d.popleft()
        if not (a_len > a_readed and t + a[a_readed] <= k) and not (b_len > b_readed and t + b[b_readed] <= k):
            # print(a_readed, b_readed, t)
            L.append(a_readed + b_readed)
        else:
            if a_len > a_readed and t + a[a_readed] <= k:
                d.append((a_readed + 1, b_readed, t + a[a_readed]))
            if b_len > b_readed and t + b[b_readed] <= k:
                d.append((b_readed, b_readed + 1, t + b[b_readed]))
    ans = max(L)
    return ans

def tsundoku(f):
    readline = f.readline
    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)

def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
def readinput():
    n,m,k=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    return n,m,k,a,b

def main(n,m,k,a,b):
    qa=deque(a)
    qb=deque(b)
    count=0
    res=k
    while(len(qa)>0 and len(qb)>0):
        if qa[0] < qb[0]:
            res-=qa[0]
            qa.popleft()
        else:
            res-=qb[0]
            qb.popleft()
        if res<0:
            return count
        count+=1
    else:
        if len(qa)==0:
            while(len(qb)>0):
                res-=qb[0]
                qb.popleft()
                if res<0:
                    return count
                count+=1
            return count
        else:
            while(len(qa)>0):
                res-=qa[0]
                qa.popleft()
                if res<0:
                    return count
                count+=1
            return count

import sys
INFTY=sys.maxsize
def find(t,s):
    '''
    単調増加配列sからs[i]がtを超えない最大のiを返す
    '''
    ss=s[:]
    ss.append(INFTY)
    left=0
    right=len(ss)
    while(left<right):
        middle=(left+right)//2
        #print(left,middle,right,t,ss)
        if ss[middle]==t:
            #print(middle, ss)
            return middle
        if t<ss[middle]:
            right=middle
        else:
            left=middle+1
    else:
        return left-1

def main2(n,m,k,a,b):
    sa=[0]
    for i in range(1,n+1):
        sa.append(sa[i-1]+a[i-1])
    sb=[0]
    for i in range(1,m+1):
        sb.append(sb[i-1]+b[i-1])
    maxab=0
    nb=m+1
    for na in range(0,n+1):
        res=k-sa[na]
        if res>=0:
            nb=find(res,sb[:nb+1])
            #print(na,nb,sa,sb)
            maxab=max(maxab,na+nb)
    return maxab

from bisect import bisect_left
def main3(n,m,k,a,b):
    sa=[0]
    for i in range(1,n+1):
        sa.append(sa[i-1]+a[i-1])
    sb=[0]
    for i in range(1,m+1):
        sb.append(sb[i-1]+b[i-1])
    maxab=0
    nb=m+1
    for na in range(0,n+1):
        res=k-sa[na]
        if res>=0:
            nb=bisect_left(sb[:nb+1],res)
            #print(na,nb,sa,sb)
            maxab=max(maxab,na+nb)
    return maxab

def readinput2():
    m=2*10**5
    n=2*10**5
    a=[10**9]*n
    b=[10**9]*m
    k=1
    return n,m,k,a,b

if __name__=='__main__':
    n,m,k,a,b=readinput()
    ans=main3(n,m,k,a,b)
    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
while N > 0 and M > 0:
    C = min(A[0], B[0])
    if C > K:
        break
    K -= C
    if C == A[0]:
        A.pop(0)
        N -= 1
    else:
        B.pop(0)
        M -= 1
    ans += 1
while N > 0:
    if A[0] > K:
        break
    K -= A[0]
    A.pop(0)
    N -= 1
    ans += 1
while M > 0:
    if B[0] > K:
        break
    K -= B[0]
    B.pop(0)
    M -= 1
    ans += 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=A
B=B

P=[0]*(N+1)
Q=[0]*(M+1)

for i in range(1, N+1):
  P[i]=P[i-1]+A[i-1]
  
for i in range(1, M+1):
  Q[i]=Q[i-1]+B[i-1]
  
import bisect
ans=0
for i in range(N+1):
  t=K-P[i]
  if t>0:
    tmp=i+bisect.bisect_right(Q, t)-1
    ans=max(ans, tmp)
  
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()))

import numpy as np
import bisect

ra=list(np.cumsum(a))
rb=list(np.cumsum(b))

ans=0
for i in range(n):    
    capa = k - ra[i]
    if ra[i]>k:
        ans=max(ans,i)
        break
    index = bisect.bisect_right(rb,capa)

    ans=max(ans,i+1+index)
            
print(ans)

Submission status: Wrong Answer

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

import numpy as np

def binarySearch(lis,key):
    ng = -1
    ok = len(lis)
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOk(lis,mid,key): ok = mid
        else: ng = mid
    return ok

def isOk(lis,index,key):
    if lis[index] >= key: return True
    else: return False

n,m,k = iim()
a = iil()
cuma = np.cumsum(a)
b = iil()
cumb = np.cumsum(b)

ans = binarySearch(cumb,k)

for i,item in enumerate(cuma):
    if item > k:
        break

    res = k-item
    plus = binarySearch(cumb,res)
    ans = max(ans,i+1+plus)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
from itertools import accumulate
from bisect import bisect_right
A=list(accumulate(A))
B=list(accumulate(B))
ans=0
t=0
for a in range(n+1):
    t=k-A[a]
    b=bisect_right(B,t)-1
    if B[b]>k:continue
    ans=max(ans,a+b)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]+[10**9+1]
B=[int(x) for x in input().split()]+[10**9+1]

c,i,j=0,0,0
while (i<N or j<M) and K>=min(A[i],B[j]):
  c+=1
  if A[i]<B[j]:
    K-=A[i]
    i+=1
  elif B[j]<A[i]:
    K-=B[j]	
    j+=1
  else:
    if A[i+1]<=B[j+1]:
      K-=A[i]
      i+=1
    else:
      K-=B[j]
      j+=1

print(c)

Submission status: Wrong Answer

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

ruiseki_a=[]
prev=0
for i in range(n):
    ruiseki_a.append(a[i]+prev)
    prev=ruiseki_a[-1]

ruiseki_b=[]
prev=0
for j in range(m):
    ruiseki_b.append(b[j]+prev)
    prev=ruiseki_b[-1]


import bisect

ans=0
for i in range(n):
    ra=ruiseki_a[i]
    capa = k-ra

    if ra>k:
        break

    index = bisect.bisect_right(ruiseki_b,capa)
    ans=max(ans,i+1+index)
            
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()))

lst = [0]*(M+1)
for i in range(M+1):
    time = 0
    time = sum(A[0:i])
    if time > K:
        break
    else:
        for j in range(N):
            if time + B[j] <= K:
                time = time + B[j]
            else:
                lst[i] = i + j
                break

res = max(lst)
print(res)

Submission status: Wrong Answer

Solution code:
import bisect

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

B_sum = [0] * (M + 1)
for i in range(M):
    B_sum[i+1] = B_sum[i] + B[i] # B_sumのindexが冊数

result = 0
time_count = K
for i in A:
    time_count -= i
    if time_count < 0 or time_count < B_sum[1]:
        break
    else:
        tmp = bisect.bisect_right(B_sum, time_count) + A.index(i)
        result = max(result, tmp)

print(result)

Submission status: Wrong Answer

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

cum_A = [A[0]] * N
for i in range(1, N):
    cum_A[i] = cum_A[i - 1] + A[i]
cum_B = [B[0]] * M
for i in range(1, M):
    cum_B[i] = cum_B[i - 1] + B[i]

ans = 0
b_ub = M
for i in range(N):
    rest = K - cum_A[i]
    for j in range(b_ub)[::-1]:
        if cum_B[j] <= rest:
            ans = max(i + j + 2, ans)
            b_ub = j + 1
            break

print(ans)

Submission status: Wrong Answer

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

Atime=[0]
Btime=[0]
j=1
for i in Al:
    tmp = i + Atime[j-1]
    if tmp <= K: 
        Atime.append(i + Atime[j-1] )
        j +=1
    else:
        break

j=1
for i in Bl:
    tmp = i + Btime[j-1]
    if tmp <= K:
        Btime.append(i + Btime[j-1])
        j +=1
    else:
        break

res=0
j=len(Btime)-1
for i in reversed(range(len(Atime))):

    while(j>=0):
        if Atime[i]+Btime[j]<=K:
            res=max(res,i+j)
            break
        else:
            j-=1        

print(res)

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

ruiseki_a=[]
prev=0
for i in range(n):
    ruiseki_a.append(a[i]+prev)
    prev=ruiseki_a[-1]

ruiseki_b=[]
prev=0
for j in range(m):
    ruiseki_b.append(b[j]+prev)
    prev=ruiseki_b[-1]


import bisect

ans=0
for i in range(n):
    ra=ruiseki_a[i]
    capa = k-ra

    if ra>=k:
        break

    index = bisect.bisect_left(ruiseki_b,capa)
    if index<=m-1:
        if ruiseki_b[index]==capa:
            j=index+1
        else:
            j=index
    else:
        j=m

    ans=max(ans,i+1+j)
            
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]+[10**9]
B=[int(x) for x in input().split()]+[10**9]

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

print(c)

Submission status: Wrong Answer

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

ruiseki_a=[]
prev=0
for i in range(n):
    ruiseki_a.append(a[i]+prev)
    prev=ruiseki_a[-1]

ruiseki_b=[]
prev=0
for j in range(m):
    ruiseki_b.append(b[j]+prev)
    prev=ruiseki_b[-1]


import bisect

ans=0
for i in range(n):
    ra=ruiseki_a[i]
    capa = k-ra

    if ra>k:
        break

    index = bisect.bisect_left(ruiseki_b,capa)
    if index<=m-1:
        if ruiseki_b[index]==capa:
            j=index+1
        else:
            j=index
    else:
        j=m

    ans=max(ans,i+1+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()))
A=A+[10**10]
B=B+[10**10]

t=0
x=0
y=0
ans=0
while t<K:
  if A[x]<B[y]:
    if t+A[x]<=K:
      t+=A[x]
      x+=1
      ans+=1
    else:
      t=K
  else:
    if t+B[y]<=K:
      t+=B[y]
      y+=1
      ans+=1
    else:
      t=K
      
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()))

ruiseki_a=[]
prev=0
for i in range(n):
    ruiseki_a.append(a[i]+prev)
    prev=ruiseki_a[-1]

ruiseki_b=[]
prev=0
for j in range(m):
    ruiseki_b.append(b[j]+prev)
    prev=ruiseki_b[-1]
import bisect

ans=0
for i in range(n):
    ra=ruiseki_a[i]
    capa = k-ra

    if ra>k:
        break

    index = bisect.bisect_left(ruiseki_b,capa)
    if index<=m-1 and ruiseki_b[index]==capa:
        j=index+1
    else:
        j=index

    ans=max(ans,i+1+j)
            
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = N + M
cnt = 0
res = 0
A = deque(A)
B = deque(B)
for c in range(C):
    
    if A:
        a = A.popleft()
    else:
        a = 10**10
    if B:
        b = B.popleft()
    else:
        b = 10**10

    if a >= b:
        cnt += b
        A.appendleft(a)
    elif a < b:
        cnt += a
        B.appendleft(b)
    
    if cnt <= K:
        res += 1
    else:
        break
print(res)

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(float("inf"))
B.append(float("inf"))
ans = 0

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, m, k = geta(int)
    qa = list(geta(int))[::-1]
    qb = list(geta(int))[::-1]

    time_tot = 0
    ans = 0

    while (len(qa) > 0 or len(qb) > 0):

        if len(qa) == 0:
            time_tot += qb.pop()
        elif len(qb) == 0:
            time_tot += qa.pop()
        else:
            time_tot += qa.pop() if qa[-1] <= qb[-1] else qb.pop()

        if time_tot > k:
            break

        ans += 1

    print(ans)


if __name__ == "__main__":
    main()