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

N, M, K =[3,4,730]
A =[60,90,120]
B =[80,150,80,150]
#N, M, K =[5,4,1]
#A=[1000000000,1000000000,1000000000,1000000000,1000000000]
#B=[1000000000,1000000000,1000000000,1000000000]

A = [0] +A

Bsum =[0]*M
sum =0

for i in range(len(B)):
    Bsum[i] = B[i]+sum
    sum = Bsum[i]
    
#print(Bsum)

def binary_search_find_closest(data, target):
    
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]
    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        #　中心の左右の値と目標との差を計算する。
        if imid + 1 < len(data):
            min_diff_right = abs(data[imid+1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid-1] - target)
        # 最初の差と最も最小に近い値を更新する。
        if min_diff_left < min_diff:
            min_diff = min_diff_left
            closest_num = data[imid-1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid+1]
        # 2分探索する。
        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid -1
        else:
            return data[imid]
    return closest_num

# 15が表示される。

Atotal=0
Btotal=0
Aid=-1
Bid=0
total =0
cnt=0

for i in range(N+1):
    if A[i] >= 1000000000:
        break
    Atotal += A[i]
    Aid +=1
    #print(Atotal)
    if K - Atotal >=0:
        Btotal =binary_search_find_closest(Bsum,K - Atotal) 
        Bid = Bsum.index(Btotal)+1
        if Btotal >=1000000000:
            break
        if Atotal + Btotal > K:
            Btotal = Bsum[Bsum.index(Btotal)-1]
            Bid -=1
        total = Atotal+Btotal
        cnt = Aid +Bid
        #print(Atotal,Btotal,Aid,Bid)


print(cnt)

Submission status: Wrong Answer

Solution code:
def bins(a, x):
    l = -1
    h = len(a)
    while (h-l) > 1:
        m = (l+h)//2
        if x >= a[m]:
            l = m
        else:
            h = m
    return l
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    bv = bins(pb, v) + 1
    m = max(m, bv+i)
        
print(m)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    result = solve(N, M, K, A, B)
    print(result)


def solve(N, M, K, A, B) -> int:
    A.reverse()
    B.reverse()
    result = 0
    while True:
        if not A and not B:
            break
        elif not A and B:
            K -= B.pop()
        elif A and not B:
            K -= A.pop()
        elif A[-1] >= B[-1]:
            K -= B.pop()
        else:
            K -= A.pop()

        if K <= 0:
            break
        else:
            result += 1
    return result



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

N,M,K=map(int,input().split())
A=deque(list(map(int,input().split())))
B=deque(list(map(int,input().split())))
c=0
while K:
    if A and B:
        if A[0]<B[0]:
            if A[0]<=K:
                K-=A.popleft()
                c+=1
                continue
            else:
                break
        else:
            if B[0]<=K:
                K-=B.popleft()
                c+=1
                continue
            else:
                break
    elif A:
        if A[0]<=K:
            K-=A.popleft()
            c+=1
            continue
        else:
            break
    elif B:
        if B[0]<=K:
            K-=B.popleft()
            c+=1
            continue
        else:
            break
    else:
        continue
print(c)

Submission status: Wrong Answer

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

a_idx = b_idx = 0
count = 0
time = 0

while time < k:
    if a_idx == n:
        time += B[b_idx]
        b_idx += 1
    elif b_idx == m:
        time += A[a_idx]
        a_idx += 1
    elif A[a_idx] < B[b_idx]:
        time += A[a_idx]
        a_idx += 1
    else:
        time += B[b_idx]
        b_idx += 1
        
    if time > k:
        break
    count += 1
    
    if a_idx+b_idx == n+m or time==k:
        break
    
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    cost = K
    count = 0

    sa = [0]
    tmp=0
    for a in A:
        tmp += a
        sa.append(tmp)

    sb = [0]
    tmp=0
    for b in B:
        tmp +=b
        sb.append(tmp)

    maxA = min(bisect_left(sa, cost), len(sa))
    maxB = min(bisect_left(sb, cost), len(sb))
    for a in range(maxA):
        for b in range(maxB):
            c = sa[a] + sb[b]
            if c <= cost:
                count = max(count, a+b)
            else:
                break
    
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a = list(map(int, input().strip().split()))[:n]
b = list(map(int, input().strip().split()))[:m]
  
all = []
all.extend(a)
all.extend(b)
print(*all)
counter = 0
am = 0
if(k - min(all) >= 0):
  while(k > 0):
    print(k)
    am = min(all)
    k-= am
    counter += 1
    all.remove(am)
    if(len(all) == 0):
        break
else:
  counter = 0
  
  
print(counter)

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()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    for j in range(len(pb)-1, -1, -1):
        if pb[j] < v:
            break
    m = max(m, i+j)
print(m)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)
j=1
while j<=m and b[j]+b[j-1]<=k:
  b[j]+=b[j-1]
  j+=1
  

j-=1
books=j
i=1
while i<n:
  while j>0 and a[i]+b[j]>k:
    j-=1
  if(j>=0) and a[i]+b[j]<=k:
    books=max(books,j+i)
    a[i]+=a[i-1]
    i+=1
  else:
    break
print(books)

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.insert(0,0)
b.insert(0,0)
j=1
while j<=m and b[j]+b[j-1]<=k:
  b[j]+=b[j-1]
  j+=1
  

j-=1
books=j
i=1
while i<n:
  while j>0 and a[i]+b[j]>k:
    j-=1
  if(j>=0) and a[i]+b[j]<=k:
    books=max(books,j+i)
    a[i]+=a[i-1]
  else:
    break
print(books)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    result = solve(N, M, K, A, B)
    print(result)


def solve(N, M, K, A, B) -> int:
    A.reverse()
    B.reverse()
    result = 0
    while True:
        if not A and not B:
            break
        elif not A and B:
            K -= B.pop()
        elif A and not B:
            K -= A.pop()
        elif A[-1] >= B[-1]:
            K -= B.pop()
        else:
            K -= A.pop()

        if K < 0:
            break
        else:
            result += 1
    return result



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


a_idx = b_idx = 0
count = 0
time = 0
a, b = A.pop(0), B.pop(0)

while time < k:
    if a < b:
        # print(a)
        time += a
        a = A.pop(0) if len(A)!=0 else float("inf")
    else:
        # print(b)
        time += b 
        b = B.pop(0) if len(B)!=0 else float("inf")
    
    if time > k:
        break
    count += 1
    
    if count == m + n:
        break
    
print(count)

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()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    for j in range(len(pb)-1, -1, -1):
        if pb[j] < v:
            break
    else:
        m = max(m, i+j)
print(m)

Submission status: Wrong Answer

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

lC = lA + lB
total_time = sum(lC)
if total_time <= k:
    print(len(lC))
else:
    for i in range(len(lC)):
        total_time -= lC[-(i+1)]
        if total_time <= k:
            break
    if i + 1 > len(lB):
        pA = len(lC) - i - 1
        pB = 0
        books = pA

    else:
        pA = len(lA)
        pB = len(lB) - i
        books = pA + pB

    max_books = books
    
    for j in range(len(lB)):
        pB += j
        books += 1
        if pB < len(lB):
            total_time += lB[pB]
        while pA >= 0 and total_time > k:
            pA -= 1
            #if pA > 0:
            total_time -= lA[pA]
            books -= 1
        if total_time <= k:
            max_books = max(books, max_books)
    print(max_books)

Submission status: Wrong Answer

Solution code:
def bins(a, x):
    l = -1
    h = len(a)
    while (h-l) > 1:
        m = (l+h)//2
        if x >= a[m]:
            l = m
        else:
            h = m
    return l
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    bv = bins(pb, v)
    if bv:
        m = max(m, bv+i)
        
print(m)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_acc = []
B_acc = []
acc = 0
for a in A:
    acc += a
    A_acc.append(acc)
acc = 0
for b in B:
    acc += b
    B_acc.append(acc)
ans = 0
for i in range(N):
    for j in range(M-1,-1,-1):
        if A_acc[i] + B_acc[j] <= K:
            ans = max(ans, i + j + 2)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def bins(a, x):
    l = -1
    h = len(a)
    while (h-l) > 1:
        m = (l+h)//2
        if x > a[m]:
            l = m
        else:
            h = m
    return l + 1
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    bv = bins(pb, v)
    if bv:
        m = max(m, bv+i)
        
print(m)

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()))
a_acc = [0]
b_acc = [0]
now = 0
for i in range(n):
  now += a[i]
  a_acc.append(now)

now = 0
for i in range(m):
  now += b[i]
  b_acc.append(now)

ans = 0
for i in range(n+1):
  t = k - a_acc[i]
  if t < 0:
    break
  ind = bisect.bisect_left(b_acc, t)
  ans = max(ans, i+ind)

print(ans)

Submission status: Wrong Answer

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

a_idx = b_idx = 0
count = 0
time = 0

while time < k:
    if a_idx >= n:
        time += B[b_idx]
        b_idx += 1
    elif b_idx >= m:
        time += A[a_idx]
        a_idx += 1
    elif A[a_idx] < B[b_idx]:
        # print(A[a_idx])
        time += A[a_idx]
        a_idx += 1
    else:
        # print(B[b_idx])
        time += B[b_idx]
        b_idx += 1
        
    if time > k:
        break
    count += 1
    
    if a_idx+b_idx == n+m:
        break

print(count)

Submission status: Wrong Answer

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

lC = lA + lB
total_time = sum(lC)
if total_time <= k:
    print(len(lC))
else:
    for i in range(len(lC)):
        total_time -= lC[-(i+1)]
        if total_time <= k:
            break
    if i + 1 > len(lB):
        pA = len(lC) - i - 1
        pB = -1
        books = pA

    else:
        pA = len(lA)
        pB = len(lB) - i - 1
        books = pA + pB

    max_books = books
    
    for j in range(len(lB) - pB - 1):
        pB += 1
        books += 1
        total_time += lB[pB]
        while pA >= 0 and total_time > k:
            pA -= 1
            #if pA > 0:
            total_time -= lA[pA]
            books -= 1
        if total_time <= k:
            max_books = max(books, max_books)
    print(max_books)

Submission status: Wrong Answer

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

lC = lA + lB
total_time = sum(lC)
if total_time <= k:
    print(len(lC))
else:
    for i in range(len(lC)):
        total_time -= lC[-(i+1)]
        if total_time <= k:
            break
    if i + 1 > len(lB):
        pA = len(lC) - i - 1
        pB = -1
        books = pA

    else:
        pA = len(lA)
        pB = len(lB) - i - 1
        books = pA + pB

    max_books = books
    
    for j in range(len(lB) - pB - 1):
        pB += 1
        books += 1
        total_time += lB[pB]
        while pA >= 0 and total_time > k:
            pA -= 1
            #if pA > 0:
            total_time -= lA[pA]
            books -= 1
            max_books = max(books, max_books)
    print(max_books)

Submission status: Wrong Answer

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


def cumsum(l):
    s = 0
    for v in l:
        s += v
        yield s


a = (0,) + tuple(cumsum(A))
b = (0,) + tuple(cumsum(B))
ans = 0
m = M
for i in range(N):
    if a[i] > K:
        continue
    for j in range(m, -1, -1):
        if a[i] + b[j] <= K:
            k = j
            break
        else:
            continue
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

def meguru(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok

def isOK(num): return bcum[num] <= tb

n,m,k = imap()
a,b = iarr(),iarr()
acum,bcum = np.array(a).cumsum(),np.array(b).cumsum()

anss = []
for i in range(n):
    ans = i + 1
    ta = acum[i]
    if ta > k: continue
    else: tb = k - ta
    #ok,ng = -1,m
    #ans += meguru(ok,ng) + 1 # OKなければansは-1+1で不変
    ans += bs.bisect_right(bcum, tb)
    anss.append(ans)
ans = max(anss) if anss else 0
print(ans)

Submission status: Wrong Answer

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

lC = lA + lB
total_time = sum(lC)
if total_time <= k:
    print(len(lC))
else:
    for i in range(len(lC)):
        total_time -= lC[-(i+1)]
        if total_time <= k:
            break
    if i + 1 > len(lB):
        pA = len(lC) - i - 1
        pB = -1
        books = pA

    else:
        pA = len(lA)
        pB = len(lB) - i - 1
        books = pA + pB

    max_books = books
    
    for j in range(len(lB) - pB - 1):
        pB += 1
        books += 1
        total_time += lB[pB]
        while pA >= 0 and total_time > k:
            pA -= 1
            if pA > 0:
                total_time -= lA[pA]
            books -= 1
            max_books = max(books, max_books)
    print(max_books)

Submission status: Wrong Answer

Solution code:
def bins(a, x):
    l = 0
    h = len(a)
    while l < h:
        m = (l+h)//2
        if x > a[m]:
            l = m+1
        else:
            h = m-1
    return l
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    bv = bins(pb, v)
    if bv:
        m = max(m, bv+i)
        
print(m)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
lA = [0] + list(map(int, input().split()))
lB = [0] + list(map(int, input().split()))

lC = lA + lB
total_time = sum(lC)
if total_time <= k:
    print(len(lC) - 2)
else:
    for i in range(len(lC)):
        total_time -= lC[-(i+1)]
        if total_time <= k:
            break
    if i + 2 > len(lB):
        pA = len(lC) - i - 2
        pB = 0
        books = pA + pB

    else:
        pA = len(lA) - 1
        pB = len(lB) - i - 1
        books = pA + pB - 1

    max_books = books
    
    for j in range(1, len(lB) - pB):
        pB += 1
        books += 1
        total_time += lB[pB]
        while pA >= 0 and total_time > k:
            pA -= 1
            if pA > 0:
                total_time -= lA[pA]
            books -= 1
            max_books = max(books, max_books)
    print(max_books)

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect

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

A.reverse()
A.append(0)
B.reverse()

A = np.array(A, dtype=np.int64)
B = np.array(B, dtype=np.int64)

SA = np.cumsum(A)
SB = np.cumsum(B)

ans = 0
for i in range(N):
    if(SA[i] > K): break
    ans = max(ans, i+1 + bisect.bisect_left(SB, K-SA[i])+1)

    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

def meguru(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok

def isOK(num): return bcum[num] <= tb

n,m,k = imap()
a,b = iarr(),iarr()
acum,bcum = np.array(a).cumsum(),np.array(b).cumsum()

anss = []
for i in range(n):
    ans = i + 1
    ta = acum[i]
    if ta > k: continue
    else: tb = k - ta
    ok,ng = 0,m
    ans += meguru(ok,ng) + 1
    anss.append(ans)
ans = max(anss) if anss else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

def meguru(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok

def isOK(num): return bcum[num] <= tb

n,m,k = imap()
a,b = iarr(),iarr()
acum,bcum = np.array(a).cumsum(),np.array(b).cumsum()

anss = []
for i in range(n):
    ans = i + 1
    ta = acum[i]
    if ta > k: continue
    else: tb = k - ta
    ok,ng = -1,m
    ans += meguru(ok,ng) + 1
    anss.append(ans)
ans = max(anss) if anss else 0
print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate
import bisect

sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_right(sum_b_list,time_rest)

    ans = max(ans, a_idx + b_idx)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect

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

A.reverse()
B.reverse()

A, B = np.array(A, dtype=np.int64), np.array(B, dtype=np.int64)

S = np.cumsum(B)

ans = 0
for i in range(N):
    sumA = sum(A[:i+1])
    if(sumA > K): continue
    ans = max(ans, i+1 + bisect.bisect_left(S, K-sumA)+1)
    
print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate
import bisect

sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_left(sum_b_list,time_rest)

    ans = max(ans, a_idx + b_idx - 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()))
time=0
ai=0
bi=0
for i in range(n+m):
    if bi<m:
        if ai<n:
            if a[ai]<b[bi]:
                if time+a[ai]<=k:
                    time+=a[ai]
                    ai+=1
                else:
                    break
            else:
                if time+b[bi]<=k:
                    time+=b[bi]
                    bi+=1
                else:
                    break
        else:
            if time+b[bi]<=k:
                time+=b[bi]
                bi+=1
            else:
                break
    else:
        if time+a[ai]<=k:
            time+=a[ai]
            ai+=1
        else:
            break
print(ai+bi)

Submission status: Wrong Answer

Solution code:
def bisect(x):
    l,r=-1,M+1
    while(r-l>1):
        mid=(l+r)//2
        if cumB[mid]>=x:
            r=mid
        else:
            l=mid
    return l

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cumB=[0]*(M+1)
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]
c=0
ans=0
for i in range(N):
    if c>K:
        break
    r=K-c
    b=bisect(r+1)
    ans=max(ans,i+b)
    c+=A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
def bisect(x):
    l,r=-1,M+1
    while(r-l>1):
        mid=(l+r)//2
        if cumB[mid]>=x:
            r=mid
        else:
            l=mid
    return l

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cumB=[0]*(M+1)
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]
c=0
ans=0
for i in range(N):
    c+=A[i]
    if c>K:
        break
    r=K-c
    b=bisect(r+1)
    ans=max(ans,i+1+b)
print(ans)

Submission status: Wrong Answer

Solution code:
def bisect(x):
    l,r=-1,M+1
    while(r-l>1):
        mid=(l+r)//2
        if cumB[mid]>=x:
            r=mid
        else:
            l=mid
    return l

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cumB=[0]*(M+1)
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]
c=0
ans=0
for i in range(N):
    c+=A[i]
    if c>K:
        break
    r=K-c
    b=bisect(r+1)
    ans=max(ans,i+1+b)
    print(b)
print(ans)

Submission status: Wrong Answer

Solution code:
def bisect(x):
    l,r=-1,M+1
    while(r-l>1):
        mid=(l+r)//2
        if cumB[mid]>x:
            r=mid
        else:
            l=mid
    return l

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cumB=[0]*(M+1)
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]
c=0
ans=0
for i in range(N):
    c+=A[i]
    if c>K:
        break
    b=bisect(K-c)
    ans=max(ans,i+1+b)
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()))

sumA = [0] * (N+1)
sumB = [0] * (M+1)
for i in range(N):
    sumA[i+1] = sumA[i] + A[i]
for i in range(M):
    sumB[i+1] = sumB[i] + B[i]

ans = 0
import bisect
for i in range(N+1):
    if K - sumA[i] > 0:
        idx = bisect.bisect_right(sumB,K-sumA[i])
        ans = max(ans,i + idx - 1)
#     print(idx)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    answer = 0
    is_changed = False
    if a[0] <= k or b[0] <= k:
        answer = 1
    elif a[0] + b[0] <= k:
        answer = 2
    for i in range(1, n):
        a[i] += a[i - 1]
        if k < a[i] and not is_changed:
            answer = i
            is_changed = True
    if a[-1] <= k:
        answer = n
    is_changed = False
    for i in range(1, m):
        b[i] += b[i - 1]
        if k < b[i] and not is_changed:
            answer = max(answer, i)
            is_changed = True
    if b[-1] <= k:
        answer = max(answer, m)
    if a[-1] + b[-1] <= k:
        answer = n + m
    else:
        for i in range(n):
            l = bisect_right(b, k - a[i])
            if l == 0 or (l == m and b[l - 1] + a[i] > k):
                continue
            answer = max(answer, i + 1 + l)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    answer = 0
    for i in range(1, n):
        a[i] += a[i - 1]
    for i in range(1, m):
        b[i] += b[i - 1]
    if a[-1] + b[-1] <= k:
        answer = n + m
    else:
        for i in range(n):
            l = bisect_right(b, k - a[i])
            if l == 0 or (l == m and b[l - 1] + a[i] > k):
                continue
            answer = max(answer, i + 1 + l)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
lA = [0] + list(map(int, input().split()))
lB = [0] + list(map(int, input().split()))

lC = lA + lB
total_time = sum(lC)
if total_time <= k:
    print(len(lC) - 2)
else:
    for i in range(len(lC)):
        total_time -= lC[-(i+1)]
        if total_time <= k:
            break
    if i+1  > len(lB):
        pA = len(lC) - i - 2
        pB = 0

    else:
        pA = len(lA) - 1
        pB = len(lB) - i - 1
        #print('test')
    books = pA + pB
    max_books = books
    #print(books, pA, pB)
    
    for j in range(1, len(lB) - pB):
        pB += 1
        books += 1
        total_time += lB[pB]
        while pA >= 0 and total_time > k:
            pA -= 1
            books -= 1
            if pA > 0:
                total_time -= lA[pA]
            max_books = max(books, max_books)
    print(max_books)