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:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,M,K = map(int, input().split())
Nnums = list(map(int, input().split()))
Mnums = list(map(int, input().split()))

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0

#Nのみの場合に何冊読めるか
for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1

#Mを組み入れて最大数を探す
for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    while chkSum > K:
      if Ncnt >= 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
      else:
        #chkSum -= Ml
        chkCnt -= 1
        AnsCnt -= 1
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
#  if (Ncnt < 0):
  if (chkSum > K):
    break
    
print(AnsCnt)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate
n,m,k=map(int,input().split())
a=list(accumulate(map(int,input().split())))
b=list(accumulate(map(int,input().split())))
ans=0
for i,x in enumerate(a):
    y=k-x
    if y>0:
        j=bisect.bisect_right(b,y)
        ans=max(ans,i+j+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()))

ans = 0

l = 0
r = 0
for i in range(m + 1):
    ll = b[0:i] + a
    # print(ll)
    
    r = ans
    while True:
        if r > len(ll):
            break
        if k <= sum(ll[0:r + 1]):
            break
        
        r += 1
        
        ans = max(ans, r)
        # print(f'* {ll[0:r]}')

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]
b=[0]

for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
j=M
ans=0
for i in range(N):#aは小さい方から
    if a[i]>K:    #a[0]=0なのでいきなりbreakすることはない
        break
    while b[j]>K-a[i] : #bは大きい方から
        j-=1            #j,ansの値は次のループに引き継がれる
    ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,t=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
s=0
c=0
l1.append(1000000000)
l2.append(1000000000)
left1,left2=0,0

while t>s:
    if l1[left1]>l2[left2]:
        s+=l2[left2]
        left2+=1
    else:
        s+=l1[left1]
        left1+=1
    c+=1
if s>t:
    print(c-1)
else:
    print(c)

Submission status: Wrong Answer

Solution code:
N, M, K =  [int(x) for x in input().split()]

stackA = [int(x) for x in input().split()]
stackB = [int(x) for x in input().split()]

books = 0

while True:
    if len(stackB) == 0:
        if len(stackA) == 0:
            break

        K -= stackA.pop(0)

    elif len(stackA) == 0:
        K -= stackB.pop(0)

    else:
        if stackA[0] > stackB[0]:
            K -= stackB.pop(0)

        else:
            K -= stackA.pop(0)        

    if K < 0:
        break

    else:
        books += 1


print(books)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

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

for i in range(1, len(A)):
  A[i] = A[i] + A[i - 1]
  
for i in range(1, len(B)):
  B[i] = B[i] + B[i - 1]
  
import bisect
ans = 0
for i in range(len(A)):
  rest = K - A[i]
  # あとrest分大丈夫
  ind = bisect.bisect_right(B, rest)
  if ind != 0:
    if (i + 1) + (ind) > ans:
      ans = (i + 1) + (ind)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

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

for i in range(1, len(A)):
  A[i] = A[i] + A[i - 1]
  
for i in range(1, len(B)):
  B[i] = B[i] + B[i - 1]
  
a_i = len(A) - 1
b_i = 0

ans = 0
while a_i >= 0 and b_i < len(B):
  if A[a_i] + B[b_i] <= K:
    if a_i + 1 + b_i + 1 > ans:
      ans = a_i + 1 + b_i + 1
  if A[a_i] + B[b_i] > K:
    a_i -= 1
    continue
  if A[a_i] + B[b_i] <= K:
    b_i += 1
    continue

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 bisect
A_sum=[0]
B_sum=[0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])

ans=0
for i in range(N+1):
    b_read=bisect.bisect_right(B_sum,K-A_sum[i])-1
    ans=max(ans,i+b_read)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = [0]
Bsum = [0]
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N+1):
    if Asum[t] > K:
        break
    if best < t:
        best=t
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+s+1:
                best=t+s+1
            Blast = s
            break
print(best)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = [0]
Bsum = [0]
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N+1):
    if Asum[t] > K:
        break
    if best < t+1:
        best=t+1
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+1+s+1:
                best=t+1+s+1
            Blast = s
            break
print(best)

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()))
i=0
kk=k
mx=0
while i<n and a[i]<=k:
    k-=a[i]
    i+=1
    mx+=1
j=0
while j<m and b[j]<=k:
    k-=b[j]
    j+=1
    mx+=1
cou=mx
if(i==n):
    i-=1
while i>=0 and j<m:
    k+=a[i]
    i-=1
    cou-=1
    while j<m and b[j]<=k:
        k-=b[j]
        cou+=1
        j+=1
    mx=max(cou,mx)
print(mx)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

A2 = []
B2 = []
temp = 0
for a in A:
    temp += a
    A2.append(temp)
temp = 0
for b in B:
    temp += b
    B2.append(temp)

ans = 0
j = M-1

for i in range(N):
    if A2[i] > K:
        break
    while j >= 0 and A2[i]+B2[j] > K:
        j -= 1
    ans = max(ans,i+j+2)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = []
Bsum = []
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N):
    if Asum[t] > K:
        break
    if best < t+1:
        best=t+1
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+1+s+1:
                best=t+1+s+1
            Blast = s
            break
print(best)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = []
Bsum = []
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N):
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+1+s+1:
                best=t+1+s+1
            Blast = s
            break
print(best)

Submission status: Wrong Answer

Solution code:
n, m, k = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
timeStudied = 0
booksRead = 0
if (k<arr1[0]) and (k<arr2[0]):
    z=0
else:
    while timeStudied < k:
        
        if (len(arr1)>0) and (len(arr2)>0):
            minn = min(arr1[0],arr2[0])
            if arr1[0] < arr2[0]:
                small = "1"
            else:
                small = "2"
                
        elif (len(arr1)>0) and (len(arr2)==0):
            minn = arr1[0]
            small = "1"
        elif (len(arr1)==0) and (len(arr2)>0):
            minn = arr2[0]
            small = "2"
        elif (len(arr1)==0) and (len(arr2)==0):
            break
        

        timeStudied += minn
        if timeStudied <= k:
            booksRead += 1
        if small == "1":
            arr1.pop(0)
        elif small == "2":
            arr2.pop(0)
print(booksRead)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,M,K = map(int, input().split())
Nnums = list(map(int, input().split()))
Mnums = list(map(int, input().split()))

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0

#Nのみの場合に何冊読めるか
for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1
  
#Mを組み入れて最大数を探す
for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    while chkSum > K:
      chkSum -= Nnums[Ncnt]
      chkCnt -= 1
      Ncnt -= 1
      if (Ncnt < 0):
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
  if (Ncnt < 0):
    break

print(AnsCnt)

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]
for i in range(n):
  A.append(a[i])
B=[0]
for i in range(m):
  B.append(b[i])
ans=0
j=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:
from bisect import bisect_right

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

AS = [0] * (N+1)
AS[0] = A[0]
BS = [0] * (M+1)
BS[0] = B[0]

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

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

AS[N] = 1e18
BS[M] = 1e18

ans = 0
for i in range(N):
    Z = K-AS[i]
    if Z < 0:
        break
    idx = bisect_right(BS, Z)
    if idx > 0:
        ans = max(ans, i+1+ idx)
    else:
        ans = max(ans, i+1)

print(ans)

Submission status: Wrong Answer

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

A = cumsum([0] + A)
B = cumsum([0] + B)
n_read = 0
b_tail = B[-1]
for i, a in enumerate(A):
    if a > k:
        break
    j = m
    if b_tail + a > k:
        for j, b in enumerate(B):
            if a + b > k:
                break
    n_read = max(n_read, i + j)
print(n_read)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
a,b = [0],[0]

a_apnd = a.append
b_apnd = b.append
for i in range(n):
  a_apnd(a[i]+A[i])
for i in range(m):
  b_apnd(b[i]+B[i])

count = 0
for i in range(n+1):
  res = k-a[i]
  if res<0:
    break
  if res<b[1]:
    count = max(count,i)
    break
  for t in range(m,-1,-1):
    if b[t] <= res:
      break
  count = max(count,i+t)

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

ans = 0
bb = 0
for i in range(len(a)-1):
    s = sum(a[0:len(a)-i])
    if s <= k:
        if ans < len(a)-i:
            ans = len(a)-i
        sa = s
        bbb = bb

        lu = bbb
        ru = len(b)
        for j in range(bbb, len(b)):
            ce = int((lu+ru)/2)
            sab = sa + sum(b[0:ce+1])
            if sab <= k:
                if ans < len(a)-i+ce+1:
                    ans = len(a)-i+ce+1
                lu = ce
                bb = ce
            else:
                ru = ce
            if lu >= ru:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
#Aの上からi冊、Bの上からj冊をとりi+jを条件を満たしながら最大化したい
#累積和と二分探索の練習問題
#値を固定するという概念。iが決まればjが決まる
from bisect import bisect_left
from itertools import accumulate
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=list(accumulate(a))
B=list(accumulate(b))

ans=0
sup_i=bisect_left(A,k+1)
for i in range(sup_i):
  ans=max(ans,i+1+bisect_left(B,k-A[i]+1))
 
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l

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

r = m-1
s = sum(b)
num = m
best = 0
while s>k and r>=0:
    s -= b[r]
    r -= 1
    num -= 1
if r>=0:
    best = max(best, num)
for l in range(n):
    num += 1
    s += a[l]
    while s>k and r>=0:
        s -= b[r]
        r -= 1
        num -= 1
    if r>=0:
        best = max(best, num)
print(best)

Submission status: Wrong Answer

Solution code:
read = lambda:list(map(int, input().split()))
n, m, k = read()
a = read()
b = read()
mod = 1000000001
ans = 0
while k > 0:
    if len(a) < 1:
        min_a = mod
    else:
        min_a = a[0]
    if len(b) < 1:
        min_b = mod
    else:
        min_b = b[0]
    if min_a < min_b:
        if min_a <= k:
            k -= a.pop(0)
        else:
            break
    elif min_b != mod:
        if min_b <= k:
            k -= b.pop(0)
        else:
            break
    else:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l

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

r = m-1
s = sum(b)
num = m
best = 0
while s>k and r>=0:
    s -= b[r]
    r -= 1
    num -= 1
if r>=0:
    best = max(best, num)
for l in range(n):
    if r>=0:
        best = max(best, num)
    num += 1
    s += a[l]
    while s>k and r>=0:
        s -= b[r]
        r -= 1
        num -= 1
    if r>=0:
        best = max(best, num)
print(best)

Submission status: Wrong Answer

Solution code:
a = input()
n = input()
m = input()


first = a.split(" ")
N = n.split(" ")
M = m.split(" ")
overflow = 0
for i in N:
    if int(i) >= 10**9:
        overflow = 1
        break
        
for i in M:
    if int(i) >= 10**9:
        overflow = 1
        break
    
if int(first[0]) >= 200000 or int(first[1]) >= 200000:
    overflow = 1
if int(first[2]) >= 10**9:
    overflow = 1
         
if overflow == 0:
    totaltime = 0
    count = 0
    for i in range(int(first[1]) + int(first[0])):
      if len(N) == 0:
        totaltime += int(M[0])
        M.remove(M[0])
        count += 1
      elif len(M) == 0:
        totaltime += int(N[0])
        N.remove(N[0])
        count += 1
      elif int(N[0]) < int(M[0]):
        totaltime += int(N[0])
        N.remove(N[0])
        count += 1
      elif int(M[0]) < int(N[0]):
        totaltime += int(M[0])
        M.remove(M[0])
        count += 1
      if len(M) > 0 and len(N) > 0:
          if totaltime + min(int(N[0]),int(M[0])) > int(first[2]):
              break
      else:
          if totaltime > int(first[2]):
              break
    print(count)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l

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

r = m-1
s = sum(b)
num = m
best = 0
for l in range(n):
    while s>k and r>=0:
        s -= b[r]
        r -= 1
        num -= 1
    if r>=0:
        best = max(best, num)
    num += 1
    s += a[l]
while s>k and r>=0:
    s -= b[r]
    r -= 1
    num -= 1
if r>=0:
    best = max(best, num)
print(best)

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_sums = [sum(A[0:i+1]) for i in range(N)]
B_sums = [sum(B[0:i]) for i in range(M+1)]
best = 0
for i in range(M+1):
    if B_sums[-i-1] <= K:
        best = M-i
        result = best
        break

for i in range(N):
    for j in range(best):
        if A_sums[i] + B_sums[best-j] <= K:
            best = best - j
            if result < best+i+1:
                result = best+i+1
            break
print(result)

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

b_sum = sum(B)
for i in range(M - 1, -1, -1):
    b_sum -= B[i]
    if b_sum <= K:
        j = i
        break
else:
    j = -1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy


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

    a_cumsum = numpy.cumsum(a)
    b_cumsum = numpy.cumsum(b)

    a_i = len(a) - 1
    b_i = len(b) - 1
    while k <= a_cumsum[a_i] + b_cumsum[b_i]:
        if a_i == -1 and b_i == -1:
            a_i -= 1
            break
        elif a_i == -1:
            b_i -= 1
        elif b_i == -1:
            a_i -= 1
        elif a[a_i] < b[b_i]:
            b_i -= 1
        else:
            a_i -= 1

    print(a_i + b_i + 3)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#import 
#=input()
#=int(input())
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

la = [0]
lb = [0]
for i in range(n):
    la += [a[i]+la[i]]
for i in range(m):
    lb += [b[i]+lb[i]]
j = m
ans = 0
for i in range(n):
    if la[i] > k:
        break
    while lb[j] > k - la[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop
read = lambda:list(map(int, input().split()))
n, m, k = read()
a = read()
b = read()
heapify(a)
heapify(b)
mod = 1000000001
ans = 0
while k > 0:
    if len(a) < 1:
        min_a = mod
    else:
        min_a = a[0]
    if len(b) < 1:
        min_b = mod
    else:
        min_b = b[0]
    if min_a < min_b:
        if min_a <= k:
            k -= heappop(a)
        else:
            break
    elif min_b != mod:
        if min_b <= k:
            k -= heappop(b)
        else:
            break
    else:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
a,n,m = input(), input(), input()
first = a.split(" ")
N = n.split(" ")
M = m.split(" ")
overflow = 0
for i in N:
    if int(i) >= 10**9:
        overflow = 1
        break
        
for i in M:
    if int(i) >= 10**9:
        overflow = 1
        break
    
if int(first[0]) >= 200000 or int(first[1]) >= 200000:
    overflow = 1
if int(first[2]) >= 10**9:
    overflow = 1
         
if overflow == 0:
    totaltime = 0
    count = 0
    for i in range(int(first[1]) + int(first[0])):
      if len(N) == 0:
        totaltime += int(M[0])
        M.remove(M[0])
        count += 1
      elif len(M) == 0:
        totaltime += int(N[0])
        N.remove(N[0])
        count += 1
      elif int(N[0]) < int(M[0]):
        totaltime += int(N[0])
        N.remove(N[0])
        count += 1
      elif int(M[0]) < int(N[0]):
        totaltime += int(M[0])
        M.remove(M[0])
        count += 1
      if len(M) > 1 and len(N) > 1:
          if totaltime + min(int(N[0]),int(M[0])) > int(first[2]):
              break
      else:
          if totaltime > int(first[2]):
              break
    print(count)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#C
import itertools
import bisect

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

cA = [0] + list(itertools.accumulate(A))
cB = list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(n):
    tmp = cA[-(i+1)]
    if tmp < k:
        indb = bisect.bisect_right(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    elif tmp == k:
        ans = n - i
    
print(ans)

Submission status: Wrong Answer

Solution code:
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = tuple(accumulate(AB[:N])), tuple(accumulate(AB[N:]))
    candidates = []
    for i, a_time in enumerate(cum_A, 1):
        if a_time > K:
            candidates.append(0)
            break
        b_time = K - a_time
        candidates.append(i + bisect(cum_B, b_time))
    print(max(candidates))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#C
import itertools
import bisect

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

cA = [0] + list(itertools.accumulate(A))
cB = [0] + list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(n):
    tmp = cA[-(i+1)]
    if tmp < k:
        indb = bisect.bisect_right(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    elif tmp == k:
        ans = n - i
    
indb = bisect.bisect_right(cB,k)
ans = max(ans, indb)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
a,b = [0],[0]

a_apnd = a.append
b_apnd = b.append
for i in range(n):
  a_apnd(a[i]+A[i])
for i in range(m):
  b_apnd(b[i]+B[i])

count = 0
for i in range(n+1):
  res = k-a[i]
  if res<0:
    break
  for t in reversed(range(m+1)):
    if b[t] < res:
      break
  if count<(i+t):
    count = i+t

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np 
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# -------------------
n, m, k = map(int, readline().split())
print(n)
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
a = [0] + a
b = [0] + b
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

#acc = np.array(acc)
#print(acc)
#bcc = np.array(bcc)

ans = 0

for i, val in enumerate(acc):
  if (val > k):
    break
  else:
    rest = k - val
    #print(rest)
    for j, val2 in enumerate(bcc):
      if (val2 <= rest):
        ans = max(ans, j + i)
      else:
        break

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

max_n = 0

for i in range(n):
    if (sum(a[:i])> k):break
    for j in range(m):
        if (sum(a[:i])+sum(b[:j]) > k) :
            max_n =  max(i+j-1 ,max_n)
            break
    if (sum(a[:i])+sum(b) <= k) :
    	max_n =  max(i+j+1 ,max_n)
if (sum(a)+sum(b) <= k) :
    max_n =  max(i+j+2 ,max_n)
print(max_n)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect_right
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
for i in range(1,n):
    arr1[i]=arr1[i]+arr1[i-1]
for i in range(1,m):
    arr2[i]=arr2[i]+arr2[i-1]
ma=0
for i in range(n):
    if arr1[i]<=k:
        ma=max(ma,bisect_right(arr2,k-arr1[i])+i+1)
print(ma)

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_sum=[sum(A[:_+1]) for _ in range(len(A))]
B_sum=[sum(B[:_+1]) for _ in range(len(B))]
A_sum.insert(0,0)
B_sum.insert(0,0)

ans=0
j=M
for i in range(N):
	if A_sum[i]>K:
		break
	while A_sum[i]+B_sum[j]>K:
		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()))
count = 0
time = 0
while time <= k:
    if a[0] <= b[0]:
        time += a.pop(0)
        count += 1
        a.append(10 **10)
    else:
        time += b.pop(0)
        count += 1
        b.append(10**10)
print(count - 1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect_right
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
for i in range(1,n):
    arr1[i]=arr1[i]+arr1[i-1]
for i in range(1,m):
    arr2[i]=arr2[i]+arr2[i-1]
if arr1[0]>k and arr2[0]>k:
    print(0)
    quit()
ma=0
for i in range(n):
    c=k-arr1[i]
    ind=bisect_right(arr2,c)
    ma=max(ma,ind+i+1)
print(ma)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

acc = np.array(acc)
#print(acc)
bcc = np.array(bcc)

ans = 0

for i, val in enumerate(acc):
  if (val > k):
    break
  else:
    rest = k - val
    print(rest)
    for j, val2 in enumerate(bcc):
      if (val2 <= rest):
        ans = max(ans, j + i)
      else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
y = 0
cnt = 0
cnt2 = 0
sumlist_a = [0]
sumlist_b = []

for i in range(n):
    x += a[i]
    if x > k:
        break
    sumlist_a.append(x)
a_available = len(sumlist_a)

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

best = 0
for i in range(M, 0, -1):
    if sum(B[:i]) <= K:
        best = i
        break

for i in range(N):
    a = sum(A[:i])
    if a > K:
        break
    for j in range(best, 0, -1):
        if a + sum(B[:j]) <= K:
            best = i + j
            break

print(best)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline

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

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

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

ans = 0
k = M - 1

for i in range(N):
    for j in range(k, -1, -1):
        if K < A[i] + B[j]:
            k -= 1
            continue
        else:
            ans = max(ans, i + j + 2)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

acc = np.array(acc)
#print(acc)
bcc = np.array(bcc)

ans = 0

for i in acc:
  if (i > k):
    continue
  else:
    rest = k - i
    for j in bcc:
      if (j <= rest):
        ans = max(ans, j + i)
      else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline

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

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

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

ans = 0
j = M - 1

for i in range(N):
    for j in range(j, -1, -1):
        if K < A[i] + B[j]:
            j -= 1
            continue
        else:
            ans = max(ans, i + j + 2)
            break

print(ans)