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: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)+sum(b)<k:
    ans=m+n
else:
    numa=[0]
    numb=[0]
    for i in range(n):
        if numa[-1]+a[i]>k:
            break
        numa.append(numa[-1]+a[i])
    for j in range(m):
        if numb[-1]+b[i]>k:
            break
        numb.append(numb[-1]+b[i])
    n=len(numa)
    m=len(numb)-1
    ans=0
    for i in range(n):
        num1=k-numa[i]
        for j in range(m):
            if numb[m]<=num1:
                break
            m-=1
        ans=max(ans,i+m)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)+sum(b)<k:
    ans=m+n
else:
    numa=[0]
    numb=[0]
    for i in range(n):
        if numa[-1]+a[i]>k:
            break
        numa.append(numa[-1]+a[i])
    for j in range(m):
        if numb[-1]+b[i]>k:
            break
        numb.append(numb[-1]+b[i])
    n=len(numa)
    m=len(numb)-1
    ans=0
    for i in range(n):
        num1=k-numa[i]
        for j in range(m+1):
            if numb[m]<=num1:
                break
            m-=1
        ans=max(ans,i+m)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
numa=[0]
numb=[0]
for i in range(n):
    if numa[-1]+a[i]>k:
        break
    numa.append(numa[-1]+a[i])
for j in range(m):
    if numb[-1]+b[i]>k:
        break
    numb.append(numb[-1]+b[i])
n=len(numa)
m=len(numb)
ans=0
for i in range(n):
    num1=k-numa[i]
    for j in range(m):
        if numb[m-j-1]<=num1:
            break
        m-=1
    ans=max(ans,i+m-1)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(j) for j in 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]]

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: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n,m,k=map(int,input().split())

a=input().split()
b=input().split()
count=0
cnt=0
i=0
while cut<k:
    if a[i]>=b[i] and k >= cnt+int(a[i]):
        cnt +=int(a[i])
        del a[i]
        count +=1
    elif k >=cut+int(a[i]):
        cut +=int(b[i])
        del b[i]
        count +=1
    else:
        break
print(count)

Submission status: Runtime Error

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

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: Runtime Error

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

index_A = 0
index_B = 0
now = 0
count = 0

while True:
    if index_A > len(A) -1 and index_B > len(B) -1:
        break
    # Bが選ばれるとき
    if index_A > len(A)-1 or A[index_A] >= B[index_B]:
        if now + B[index_B] <= K:
            now += B[index_B]
            index_B += 1
            count += 1
        else:
            break
    # Aが選ばれるとき
    else:
        if now + A[index_A] <= K:
            now += A[index_A]
            index_A += 1
            count += 1
        else:
            break
print(count)

Submission status: Runtime Error

Solution code:
from sys import stdin
import random

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

index_A = 0
index_B = 0
now = 0
count = 0

while True:
    if index_A > len(A) -1 and index_B > len(B) -1:
        break
    # Bが選ばれるとき
    if index_A > len(A)-1 or A[index_A] >= B[index_B]:
        if now + B[index_B] <= K:
            now += B[index_B]
            index_B += 1
            count += 1
        else:
            break
    # Aが選ばれるとき
    else:
        if now + A[index_A] <= K:
            now += A[index_A]
            index_A += 1
            count += 1
        else:
            break
print(count)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            break;
    c = max(c, i+m+1)
print(c)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
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] + a[i]

for i in range(1, m + 1):
    b[i] = b[i - 1] + b[i]
ans = 0
t = 0
j = 0
for i in range(n + 1):
    while j < m + 1 and k - a[i] >= b[j]:
        j += 1
    j -= 1
    ans = max(ans, i + j)

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  d=K-A[i]
  if d>=0:
    for j in reversed(range(M)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        M=j+1
        break
    if d<B[0]:
      c=i+1
  else:
    for j in reverse(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
print(c)

Submission status: Runtime Error

Solution code:
# C-Tsundoku


#N冊、M冊、時間K
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

#Aの机の現在の1番上の本の時間とBの机の一番上の本の時間を比較して小さい本を選択して
#本、時間をそれぞれ累積していき、本を削除していく。
#これを繰り返して時間Kより大きい場合になったときに処理を終了させる
#この時、本はカウントしない

minbooks = min(len(a),len(b))
acon = 0
bcon = 0
time = 0
book = 0

#a,bのリストの長さが小さい値を基準に比較の処理
for i in range(minbooks):
	#a,bの机の現在の一番上の本の読み終わり時間の低いものを調査
	#リストの長さ以上の場合は即処理を終了
	if acon > len(a) or bcon > len(b):
		break
	#aがbと同じかbより時間が少ない場合の処理
	elif a[acon] <= b[bcon]:
		acon += 1
		time += a[acon]
		book += 1
	#aがbの時間より多い場合の処理
	elif a[acon] > b[bcon]:
		bcon += 1
		time += b[bcon]
		book += 1

if k <= time:
	print(book)
elif acon >= len(a):
	for i in range(bcon,len(b)):
		if k > time:
			bcon += 1
			time += b[bcon]
			book += 1
		else:
			print(book)
elif bcon >= len(b):
	for i in range(acon,len(a)):
		if k > time:
			acon += 1
			time += a[acon]
			book += 1
		else:
			print(book)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        break;
    while a[i]+b[m-1] > k:
        m -= 1
    c = max(c, i+m+1)
print(c)

Submission status: Runtime Error

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

cnt = 0
while K >= 0:
    if len(a)==0 or len(b)==0:
        if len(a)==0 and len(b)==0:
            cnt += 1
            break
        elif len(a) == 0:
            K -= b.pop(0)
        elif len(b) == 0:
            K -= a.pop(0)
    else:
        if a[0] >= b[0]:
            K -= b.pop(0)
        else:
            K -= a.pop(0)
    cnt += 1
print(cnt - 1)

Submission status: Runtime Error

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

for a in A:
  A[a]+=A[a+1]
  
for b in B:
  B[b]+=B[b+1]

ans=0
op=m
for i in range(n+1):
  if A[i]>k:
    break
  while A[i]+B[op]>k:
    op-=1
   
  ans=max(ans,i+op)
  
print(ans)

Submission status: Runtime Error

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

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

for i in range(1,n):
  a_list[i]=a_list[i-1]+a_list[i]
for i in range(1,n+1):
  b_list[i]=b_list[i-1]+b_list[i]

max_ = 0
for i in range(n):
  if k < a_list[n-i-1]:
    pass
  else:
    for j in range(m):
      if k-a_list[n-i-1] < b_list[m-j-1]:
        pass
      else:
        max_ = max(len(a_list[:n-i])+len(b_list[:m-j]), max_)
        break
print(max_)

Submission status: Runtime Error

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

for a in A:
  A[a]+=A[a+1]
  
for b in B:
  B[b]+=B[b+1]

ans=0
op=m
for i in range(n+1):
  while A[i]+B[op]>k:
    op-=1
   
  ans=max(ans,i+op)
  
print(ans)

Submission status: Runtime Error

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

from itertools import accumulate
A = [0] + list(accumulate(a))
B = [0] + list(accumulate(b))

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: Runtime Error

Solution code:
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = 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]

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

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import sys

input = sys.stdin.readline

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

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b[y] > k - a[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Submission status: Runtime Error

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

ans,j =0,M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=i
    ans =max(ans,i+j)
print(ans)

Submission status: Runtime Error

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

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = M

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        j -= 1
        
    ans = max(ans, i+j)
    
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import sys

input = sys.stdin.readline

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

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m
for x in range(len(a_cum) + 1):
    if a_cum[x] > k:
        break
    while b[y] > k - a[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Submission status: Runtime Error

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

def accumulate(l, X):
    acclist = [0]*(l+1)
    for i in range(1,l+1):
        acclist[i] = acclist[i-1] + X[i]
    return acclist

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

X = accumulate(N, A)
Y = accumulate(M, B)

maxbook = 0
j = M
for i in range(N+1):
    x = X[i]
    y = Y[j]
    while x + y > K:
        j -= 1 
        y = Y[j]
        if j <= 0:
            break
    maxbook = max(maxbook, i + j)

print(maxbook)

Submission status: Runtime Error

Solution code:
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]
    if a[i]>=k:
        ma=i+1
        break
    ma=i+1
for i in range(1,m):
    b[i]+=b[i-1]
    if b[i]>=k:
        mb=i+1
        break
    mb=i

ans, j = 0, mb
for i in range(ma):
    if a[i] >= k:
        break
    while b[j] > k - a[i]:
        j -= 1
        if j==-1:
            break
    ans = max(ans, i + j + 2)
if ans==0 and a[i]>=k:
    while b[j] >= k - a[i]:
        j -= 1
        if j==-1:
            break
    ans = max(ans,  j + 1)
print(ans)

Submission status: Runtime Error

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

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = mark_B

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        j -= 1
        
    ans = max(ans, i+j)
    
print(ans)

Submission status: Runtime Error

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

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: Runtime Error

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

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: Runtime Error

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 =0
j = M

for i in range(N+1):
    if a[i]>k:
        break
    
    while b[j]+a[i] > K :
        j -= 1
    ans = max(ans, i + j)

print(ans)

Submission status: Runtime Error

Solution code:
#n = int(input())
n,m,k = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
time = 0
i = j = 0
while (time<=k and i<n and j<m):
      #print(i,j,time)
      if (a[i]<b[j]):
            if (time+a[i]<=k):
                  time += a[i]
                  i+=1
            else:
                  break
      else:
            if (time+b[j]<=k):
                  time += b[j]
                  j+=1
            else:
                  break
while (i<n and time<=k):
      if (time+a[i]<=k):
                  time += a[i]
                  i+=1
      else:
            break
while (j<n and time<=k):
      if (time+b[j]<=k):
                  time += b[j]
                  j+=1
      else:
            break
print(i+j)

Submission status: Runtime Error

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
ans = 0
for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B

for k in range(N+1):
    if AA[k] <= K:
        for j in range(M, -1, -1):
            if  AA[k] + BB[j+1]> K >= AA[k] + BB[j]:
                ans = max(k+j, ans)
                break
            else:
                continue
        if K >= AA[k] + BB[M]:
            ans = max(k+M, ans)
    else:
        break
print(ans)

Submission status: Runtime Error

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

ans=0
j=m
for i in range(N+1):
    if x[i]>k:
        break
    while y[j]>k-x[i]:
        j-=1
    ans=max
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384

using namespace std;
using ll =long long;
using P = pair<int,int>;

#define MAX_N 200001
#define MAX_M 200001

int N, M;
int K = 0;
int res = 0;

int A[MAX_N];
int B[MAX_M];


int main(int argc, const char * argv[]) {

    cin >> N >> M >> K;
    
    rep(i, N){
        int a;
        cin >> a;
        if(i==0) A[i] = a;
        else A[i] = A[i-1] + a;
    }
    
    rep(i, M){
        int b;
        cin >> b;
        if(i==0) B[i] = b;
        else B[i] = B[i-1] + b;
    }
    
    int a=0;
    for(int i=0; i<N; i++){
        if(A[i]>K) continue;
        
        a=i+1;
    }
    int b=M;
    for(int j=M-1; j>=0; j--){
        if(B[j] <= K-A[a]){
            res = max(res, a+b);
            break;
        }
        b--;
    }
    
    cout << res << endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_left

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if b[j] == t:
        result = max(result, i + j + 1)
    else:
        result = max(result, i + j)
print(result)

Submission status: Runtime Error

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
ans = 0
for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B

for k in range(N+1):
    if AA[k] <= K:
        for j in range(M+1):
            if  AA[k] + BB[j+1]> K >= AA[k] + BB[j]:
                ans = max(k+j, ans)
                break
            else:
                continue
    else:
        break
print(ans)

Submission status: Runtime Error

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

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
    
for i,a in enumerate(sum_A):
    for j in range(mark_B, -1, -1):
        if a + sum_B[j] <= K:
            ans = max(ans, i+j)
            break
            
print(ans)

Submission status: Runtime Error

Solution code:
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]
    if a[i]>k:
        ma=i
        break
for i in range(1,m):
    b[i]+=b[i-1]
    if b[i]>k:
        mb=i
        break

ans, j = 0, mb
for i in range(ma):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j + 2)
if ans==0 and a[i]>k:
    while b[j] > k - a[i]:
        j -= 1
        if j==-1:
            break
    ans = max(ans,  j + 1)
print(ans)

Submission status: Runtime Error

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

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: Runtime Error

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

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
    
for i,a in enumerate(sum_A):
    for j in range(mark_B, -1, -1):
        if a + sum_B[j] > K:
            pass
        else:
            ans = max(ans, i+j)
            break
            
print(ans)

Submission status: Runtime Error

Solution code:
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]
    if a[i]>k:
        ma=i
        break
for i in range(1,m):
    b[i]+=b[i-1]
    if b[i]>k:
        mb=i
        break

ans, j = 0, mb
for i in range(ma):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j + 2)
if ans==0 and a[i]>k:
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans,  j + 1)
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

nss = [0]
for i, v in enumerate(ns): nss.append(nss[i] + ns[i])
mss = [0]
for i, v in enumerate(ms): mss.append(mss[i] + ms[i])

from bisect import bisect_left

mx = 0
for i in range(n + 1):
    if nss[i] > k:
        break

    v = k - nss[i]
    j = bisect_left(mss, v)
    print(i, nss, j, mss, k)
    if j < m and mss[j] != v:
        j -= 1

    mx = max(mx, i + j)

print(mx)

Submission status: Runtime Error

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 j in range(M):
    b.append(b[i] + 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(i + j, ans)

print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = [0]
b2 = [0]
for i in range(n):
    a2.append(a2[i]+a[i])
for i in range(n):
    b2.append(b2[i]+b[i])
ans = 0
for i in range(n):
    if a[i] > k:
        break
    cnt = m
    sm = 0
    while sm < k-a2[i]:
        sm = b2[cnt-1]
        cnt -= 1
    ans = max(cnt, ans)
print(ans)

Submission status: Runtime Error

Solution code:
#n = int(input())
n,m,k = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
time = 0
i = j = 0
while (time<=k and i<n and j<m):
      if (a[i]>b[j]):
            if (time+a[i]<=k):
                  time += a[i]
                  i+=1
            else:
                  break
      else:
            if (time+b[j]<=k):
                  time += b[j]
                  j+=1
            else:
                  break
while (i<n and time<=k):
      if (time+a[i]<=k):
                  time += a[i]
                  i+=1
      else:
            break
while (j<n and time<=k):
      if (time+b[j]<=k):
                  time += b[j]
                  j+=1
      else:
            break
print(i+j)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[0]*n
y=[0]*m
x[0]=a[0]
y[0]=b[0]
for i in range(0,n-1):
    x[i+1]=x[i]+a[i+1]
for i in range(0,m-1):
    y[i+1]=y[i]+b[i+1]
ans,j=0,m-1
for i in range(n):
    if x[i]>k:
        break
    while y[j]>k-x[i]:
        j-=1
    ans=max(i+2+j,ans)
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c = (int(i) for i in input().split())
N = list(map(int, input().split())) 
M = list(map(int, input().split())) 
n = 0
m = 0
e = 0
for i in range(a+b):
  if N[n] < M[m] and n < a:
    c -= N[n]
    e += 1
    print(c)
    n += 1
  elif N[n] > M[m] and m < a:
    c -= M[m]
    e += 1
    m += 1
    print(c)
  elif n == a:
    c -= M[m]
    e += 1
    n += 1
    print(c)
  elif m == a:
    c -= N[n]
    e += 1
    m += 1
    print(c)

  if c < 0:
    e -= 1
    break

print(e)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = [0]
b2 = [0]
for i in range(n):
    a2.append(a2[i]+a[i])
for i in range(n):
    b2.append(b2[i]+b[i])
for i in range(len(a)):
    if a[0] > k:
        break
    cnt = 0
    sm = 0
    while sm < k-a2[i]:
        sm = b2[cnt]
        cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

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

   ans = 0
   for a_num, v in enumerate(a):
      tmp = 0
      if k >= v:
         b_num = bisect.bisect_right(b, k - v) - 1
         tmp = a_num + b_num
      ans = max(ans, tmp)
   print(ans)

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

   # bの累積和
   b_sums = cumsum(b)
   ans = 0
   a = [0] + a

   j = len(b_sums) - 1
   a_sum = 0
   for i, v in enumerate(a):
      a_sum += v
      while a_sum + b_sums[j] > k:
         j -= 1
         if j < 0:
            break
      ans = max(ans, i + j)
   print(ans)


solve2()

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
now = b[0]
ans = 0
for i in range(len(a)+len(b)):
    if now >= k:
        break
    else:
        if len(a) == 0:
            ans += 1
            now += b[0]
            b.remove(b[0])
        elif len(b) == 0:
            ans += 1
            now += a[0]
            a.remove(a[0])
        else:
            if a[0] < now:
                ans += 1
                now += a[0]
                a.remove(a[0])
            else:
                now = b[1]
                ans += 1
                now += b[0]
                b.remove(b[0])
print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = [0]
b2 = [0]
for i in range(n):
    a2.append(a2[i]+a[i])
for i in range(n):
    b2.append(b2[i]+b[i])
ans = 0
for i in range(len(a)):
    cnt = 0
    sm = 0
    while sm < k-a2[i]:
        sm += b[cnt]
        cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Runtime Error

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

cnt = 0
time = 0

while  True:
    print(As,Bs)
    if As == [] or Bs == []:
        break
    time += int(min(As[0], Bs[0]))
    if k < time:
        break
    cnt += 1
    if As[0] >= Bs[0]:
        del Bs[0]

        if not Bs:
            while True:
                if not As:
                   break
                else:
                   time += int(As[0])
                   if k < time:
                       break
                   cnt += 1
                   del As[0]

    elif As[0] < Bs[0]:
        del As[0]
        if not As:
            while True:
                if not Bs:
                    break
                else:
                    time += int(Bs[0])
                    if k < time:
                        break
                    cnt += 1
                    del Bs[0]


print(cnt)