TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
n,m,k=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a,b=[0],[0]
for i in range(n):
  a.apppend(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)
 

           

n=list(map(int,input().split()))
m=list(map(int,input().split()))
t=list(map(int,input().split()))

li=m+t
i=0
count=0

while i< len(li):
  if li[i] + count <= n[2]:
    count +=1
  i+=1



print(count)




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

a=list(map(int,input().split()))

b=list(map(int,input().split()))

A,B=[0],[0]

for i in range(n):
    A.append(A[i] + a[i])

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


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    maxv = 0
    acum = [0] * (n + 1)
    bcum = [0] * (m + 1)
    for i in range(n):
        acum[i + 1] = acum[i] + a[i]
    for i in range(m):
        bcum[i + 1] = bcum[i] + b[i]

    for i in range(n + 1):
        if acum[i] > k:
            continue
        maxv = max(maxv, i + bisect_right(bcum, k - acum[i]) - 1)
    print(maxv)

if __name__ == '__main__':
    main()

from bisect import bisect_right
 
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
 
    maxv = 0
    acum = [0] * (n + 1)
    bcum = [0] * (m + 1)
    for i in range(n):
        acum[i + 1] = acum[i] + a[i]
    for i in range(m):
        bcum[i + 1] = bcum[i] + b[i]
 
    for i in range(n + 1):
        if acum[i] > k:
            break
        maxv = max(maxv, i + bisect_right(bcum, k - acum[i]) - 1)
    print(maxv)
 
if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m,k = map(int,input().split())
lsa = list(map(int,input().split()))
lsb = list(map(int,input().split()))
import numpy 
la = [0]+[e for e in numpy.cumsum(numpy.array(lsa)) if e <= k]
lb = [0]+[e for e in numpy.cumsum(numpy.array(lsb)) if e <= k]
print(la)
print(lb)
mx = 0
for i in range(len(la)):
    for j in range(len(lb)):
        a = la[i]+lb[j]
        if a <= k:
            if i+j > mx:
                mx = i+j
print(mx)

a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    la.append(la[i]+a[i])
for j in range(m):
    lb.append(lb[j]+b[j])
for l in range(len(la)):
    if la[l] > k:
        break
    cnt = l
    q = 0
    p = 0
    while la[l] + p <= k:
        q += 1
        if q == len(lb):
            cnt += len(lb)-1
            break
        p = lb[q] 
    if cnt == l:
        cnt += q - 1
    if cnt > mx:
        mx = cnt
print(mx)


n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    if la[i] + a[i] > k:
        break
    la.append(la[i]+a[i])
for j in range(m):
    if lb[j] + b[j] > k:
        break
    lb.append(lb[j]+b[j])
now = len(lb)-1
for l in range(len(la)):
    cnt = l
    q = now
    while la[l] + lb[q] > k:
        q -= 1
    now = q
    cnt += q
    if cnt > mx:
        mx = cnt
print(mx)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
while i >= 0:
    sum -= a_time[i]
    for j in range(M):
        sum += b_time[j]
        if sum > K:
            sum -= b_time[j]
            break
    print('result={} i={} j={}'.format(result, i, j))
    if result < i + j:
        result = i + j
    i -= 1

print(result)


#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
j = 0
while i >= 0:
    while sum < K and j < M:
        sum += b_time[j]
        j += 1
    if sum > K:
        j -= 1
        sum -= b_time[j]
    if result < i + j:
        result = i + j
    i -= 1
    sum -= a_time[i]

print(result)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import bisect

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

asum = [0]
for a in A:
    asum.append(asum[-1] + a)

bsum = [0]
for b in B:
    bsum.append(bsum[-1] + b)

ans = 0
for i, a in enumerate(asum):
    btime = K - a
    if btime > 0:
        break
    bindex = bisect.bisect_right(bsum, btime)
    ans = max(ans, i + (bindex-1))

print(ans)


import bisect

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

asum = [0]
for a in A:
    asum.append(asum[-1] + a)

bsum = [0]
for b in B:
    bsum.append(bsum[-1] + b)

ans = 0
for i, a in enumerate(asum):
    btime = K - a
    if btime < 0:
        break
    bindex = bisect.bisect_right(bsum, btime)
    ans = max(ans, i + (bindex-1))

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

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


abc172c_tsundoku()

def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

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


abc172c_tsundoku()

def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

    for i in range(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n + 1):
        j = max(ans - i, 0)
        if j > m or A[i] + B[j] > k: continue
        while j <= m:
            if A[i] + B[j] > k:
                j -= 1
                break
            j += 1
        j = min(m,j)
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
from bisect import bisect
for i in range(n+1):
    ALL = a[i]
    if ALL > k:
        continue
    else:idx = bisect(b,k-ALL)
    #print(i,ALL,idx)
        ans = max(ans,i+idx-1)
print(ans)

from collections import deque
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = deque(a)
b = deque(b)
#print(a,b)
num = 0
cnt = 0

L = []
while a and b:
    if a[0] <=b[0]:
        L.append(a[0])
        a.popleft()
    else:
        L.append(b[0])
        b.popleft()
if a:
    for i in range(len(a)):
        L.append(a[i])
if b:
    for i in range(len(b)):
        L.append(b[i])
#print(L,a,b)
for i in range(len(L)):
    num +=L[i]
    #print(num)
    if num >k:
        print(i)
    elif num == k:
        print(i+1)
        exit()

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

from itertools import accumulate

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

ans = 0
num = b
for i in range(a+1):
    if A[i] > k:
        continue
    while True :
        if A[i] + B[num] > k:
            num -=1
        else:
            ans = max(ans,i+num)
            break
print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
l=[0]*(n+1)
for i in range(1,n+1):

    for j in range(i,n+1,i):

        l[j]+=1
c=0
for i in range(1,n+1):
    c+=i*l[i]

print(c)


n=int(input())
l=[0 for i in range(n+1)]
for i in range(1,n+1):
 
    for j in range(i,n+1,i):
 
        l[j]+=1
c=0
for i in range(1,n+1):
    c+=i*l[i]
 
print(c)

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

ind_b = 0
max_b = 0
for i in range(1, N + 1):
    if cumsum_a[i] <= K:
        max_a = i
    else:
        break

for i in range(1, M + 1):
    if cumsum_b[i] <= K:
        max_b = i
    else:
        break

for i in range(max_a, -1, -1):
    for j in range(ind_b, max_b+1):
        if cumsum_b[j] + cumsum_a[i] <= K:
            # print("ok")
            num_book = max(i + j, num_book)
            ind_b = j
        else:
            break
print(num_book)

import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)

num_book = 0
max_a = 0
ind_b = 0
max_b = 0
for i in range(1, N + 1):
    if cumsum_a[i] <= K:
        max_a = i
    else:
        break

for i in range(1, M + 1):
    if cumsum_b[i] <= K:
        max_b = i
    else:
        break

for i in range(max_a, -1, -1):
    for j in range(ind_b, max_b+1):
        if cumsum_b[j] + cumsum_a[i] <= K:
            # print("ok")
            num_book = max(i + j, num_book)
            ind_b = j
        else:
            break
print(num_book)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = n
B = 0
if (a[0]>k):
    A = 0
for i in range(1,n):
    a[i] += a[i-1]
    if (a[i]>k):
        A = i
for i in range(1,m):
    b[i] += b[i-1]
if (a[0]>k):
    A = 0
ans = A
while True:
    if (A<0):
        break
    if (B>=m):
        break
    B += 1
    if (A==0):
        for i in range(m):
            if (b[i]>k):
                print(i)
                exit()
            print(len(b))
            exit()
    if (a[A-1]+b[B-1] >k):
        B -= 1
        A -= 1
    else:
        ans = max(ans,A+B)
print(ans)

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = n
B = 0
for i in range(1,n):
    a[i] += a[i-1]
    if (a[i]>k):
        A = i
        break
for i in range(1,m):
    b[i] += b[i-1]
ans = A
if (a[0]>k):
        for i in range(m):
            if (b[i]>k):
                print(i)
                exit()
        print(len(b))
        exit()
a = [0] + a
b = [0] + b
while True:
    if (A<0):
        break
    if (B>=m):
        break
    B += 1
    
    if (a[A]+b[B] >k):
        B -= 1
        A -= 1
    else:
        ans = max(ans,A+B)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#include <bits/stdc++.h>
using namespace std;

int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n+1];
	ll b[m+1];
	a[0]=0;
	b[0]=0;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]+=a[i-1];
	}
	for(ll i=1;i<=m;i++)
	{
		cin>>b[i];
		b[i]+=b[i-1];
	}
	ll j=m;
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]>k)break;
		while(j>=0 && a[i]+b[j]>k)
		{
			j--;
		}
		if(j>=0)
		ans=max(ans,i+j);
	}
	cout<<ans;
	return 0;
}

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)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
import sys
read = sys.stdin.buffer.read


N, M, K = map(int, input().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)

left = 0
for i, b in enumerate(B):
    if b > K:
        left = i - 1
        break

ans = 0
if A[-1] + B[-1] <= K:
    ans = N + M
else:
    for i in range(len(A)):
        if A[i] > K:
            break

        while A[i] + B[left] > K:
            left -= 1

        ans = max(ans, left + i)

print(ans)

import numpy as np
import sys
read = sys.stdin.buffer.read


N, M, K = map(int, input().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)

left = M
for i, b in enumerate(B):
    if b > K:
        left = i

ans = 0
for i in range(len(A)):
    if A[i] > K:
        break

    while A[i] + B[left] > K:
        left -= 1

    ans = max(ans, left + i)

print(ans)

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
 

N, M, K = map(int, readline().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)
 
ans = 0
left = M
for i in range(len(A)):
    if A[i] > K:
        break
 
    while A[i] + B[left] > K:
        left -= 1
 
    ans = max(ans, left + i)

print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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()]

indexB = 0
indexA = 0

books = 0
mostBooks = 0
time = 0

for x in stackB:
    if time + x > K:
        indexB -= 1
        break

    else:
        time += x
        indexB += 1
        books += 1

indexB -= 1

mostBooks = books

for x in stackA:
    time += x
    books += 1

    while time > K and indexB >= 0:
        time -= stackB[indexB]
        indexB -= 1
        books -= 1

    if indexB < 0 and time > K:
        break

    mostBooks = max(mostBooks, books)

print(mostBooks)

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

indexB = 0
indexA = 0

books = 0
mostBooks = 0
time = 0

for x in stackB:
    if time + x > K:
        break

    else:
        time += x
        indexB += 1
        books += 1

indexB -= 1

mostBooks = books

for x in stackA:
    time += x
    books += 1

    while time > K and indexB >= 0:
        time -= stackB[indexB]
        indexB -= 1
        books -= 1

    if indexB < 0 and time > K:
        break

    mostBooks = max(mostBooks, books)

print(mostBooks)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
ar = [0] * (N)
br = [0] * (M)

ar[0] = A[0]
for i, v in enumerate(A):
    ar[i+1] = ar[i] + v

br[0] = B[0]
for i, v in enumerate(B):
    br[i+1] = br[i] + v

max_read = 0
j = M
for i in range(N+1):
    rest = K - ar[i]
    if rest <= 0:
        break
    while br[j] > K - ar[i]:
        j -= 1

    max_read = max(max_read, i+j)

print(max_read)


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

count = 0
ar = [0] * (N + 1)
br = [0] * (M + 1)

for i, v in enumerate(A):
    ar[i+1] = ar[i] + v

for i, v in enumerate(B):
    br[i+1] = br[i] + v

max_read = 0
j = M
for i in range(N+1):
    if ar[i] > K:
        break
    while br[j] > K - ar[i]:
        j -= 1
    max_read = max(max_read, i+j)

print(max_read)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
from itertools import accumulate

N , M , K = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
a.insert(0,0)

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


import bisect
from itertools import accumulate

N , M , K = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
a.insert(0,0)

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import accumulate
from bisect import bisect_right
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
sum_a = list(accumulate(a))
b = list(map(int,input().split()))
sum_b = list(accumulate(b))
ma = 0
print(sum_a,sum_b)
for i in range(len(sum_a)):
    x = sum_a[i]
    if k<x:
      break
    k -= x
    index = bisect_right(sum_b,k)
    ma = max(i+1+index,ma)
    k += x
  #  print(x,k,index,ma)
print(ma)
    

from itertools import accumulate
from bisect import bisect_right
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
sum_a = [0]+list(accumulate(a))
b = list(map(int,input().split()))
sum_b = list(accumulate(b))
ma = 0
#print(sum_a,sum_b)
for i in range(len(sum_a)):
    x = sum_a[i]
    if k<x:
      index = bisect_right(sum_b,k)
      ma = max(index,ma)
    else:
      k -= x
      index = bisect_right(sum_b,k)
      ma = max(i+index,ma)
      k += x
    #  print(x,k,index,ma)
print(ma)
    

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M, K=map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
LA = [0]
LB = [0]
for i in range(N):
    C=LA[i]+A[i]
    if C>K:
        N=i
        break
    else:
        LA.append(C)
for j in range(M):
    C=LB[j]+B[j]
    if C>K:
        M=j
        break
    else:
        LB.append(C)
r=N
for i in range(N+1):
    u=0
    for j in range(r-N+i,M+1):
        if LA[N-i]+LB[j]>K:
            r=max(r,N-i+j-1) 
            u=1
            break
    if u==0:
        r=N-i+M
        break
print(r)


N, M, K=map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
LA = [0]
LB = [0]
for i in range(N):
    C=LA[i]+A[i]
    if C>K:
        N=i
        break
    else:
        LA.append(C)
for j in range(M):
    C=LB[j]+B[j]
    if C>K:
        M=j
        break
    else:
        LB.append(C)
r=N
for i in range(N+1):
    u=0
    for j in range(r-N+i,M+1):
        if LA[N-i]+LB[j]>K:
            r=max(r,N-i+j-1) 
            u=1
            break
    if u==0:
        r=max(r,N-i+M)
        break
print(r)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n, m, k = map(int, input().split())
a, b = [0], [0]
a += list(map(int, input().split())),
b += list(map(int, input().split())),
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))

n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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(n):
	a[i+1]+=a[i]
for i in range(m):
	b[i+1]+=b[i]
print(a,b)
from bisect import bisect_right
ans=0
for i in range(n+1):
	if k-a[i]>0:
		r=bisect_right(b,k-a[i])
		ans=max(r+i-1,ans)
	else:
		break
print(ans)

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(n):
	a[i+1]+=a[i]
for i in range(m):
	b[i+1]+=b[i]
from bisect import bisect_right
ans=0
for i in range(n+1):
	if k-a[i]>=0:
		r=bisect_right(b,k-a[i])
		ans=max(r+i-1,ans)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    accumA = [0,A.pop(0)]
    accumB = [0,B.pop(0)]
    for a in A:
        accumA.append(accumA[-1] + a)
    for b in B:
        accumB.append(accumB[-1] + 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)
    return ans

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

if __name__ == "__main__":
    main()






import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    accumA = [0,A.pop(0)]
    accumB = [0,B.pop(0)]
    for a in A:
        accumA.append(accumA[-1] + a)
    for b in B:
        accumB.append(accumB[-1] + b)
    ans = 0
    j = M
    for i in range(N + 1):
        if accumA[i] > K:
            break
        while accumB[j] > K - accumA[i]:
            j -= 1
        ans = max(ans,i + j)
    return ans

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

if __name__ == "__main__":
    main()




Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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]
print(A)
print(B)
ans, j = 0, M - 1
for i in range(N):
    if A[i] > K: break
    while B[j] > K - A[i]: j -= 1
    ans = max(ans, i + j + 2)
    j = M - 1
print(ans)


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

for i in range(1, N + 1): A[i] += A[i - 1]
for i in range(1, M + 1): B[i] += B[i - 1]
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)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0


mrest = sum(mlist)

mcount = m


for ncount in range(0, len(nlist) + 1):
  
  
  while mrest > 0 and mcount > 0 and mrest > k:
    mcount -= 1
    mrest -= mlist[mcount - 1]
  
  result = max(result, ncount + mcount)
  
  mrest -= nlist[ncount]
  
  if mrest <= 0:
    break
print(result)


n,m,k = map(int,input().split())
nlist = list(map(int,input().split()))
mlist = list(map(int,input().split()))
result = 0


mrest = k


mcount = m


mtime = sum(mlist)


ntime = 0


for ncount in range(len(nlist) + 1):
  
  if ncount > 0:
    mrest -= nlist[ncount - 1]
    ntime += nlist[ncount - 1]
  
  if ntime > k:
    break;
  
  
  while mcount > 0 and mtime > mrest:
    mcount -= 1
    mtime -= mlist[mcount]
  
  result = max(result, ncount + mcount)
  
  if ncount == n:
    break;
print(result)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**6)

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

from collections import deque

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

ans = 0
time = k

while time >= 0:
    if a and b:
        tmp_a = time-a[0]
        tmp_b = time-b[0]
        if tmp_a >= 0 and tmp_b >= 0 and a[0] <= b[0]:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_a >= 0 and tmp_b >= 0 and b[0] < a[0]:
            time -= b[0]
            b.popleft()
            ans += 1
        elif tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        elif tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    elif a:
        tmp_a = time-a[0]
        if tmp_a >= 0:
            time -= a[0]
            a.popleft()
            ans += 1
        else:
            break
    elif b:
        tmp_b = time-b[0]
        if tmp_b >= 0:
            time -= b[0]
            b.popleft()
            ans += 1
        else:
            break
    else:
        break
    print(a,b,ans)

print(ans)

import sys
sys.setrecursionlimit(10**6)

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

a, 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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
1 N, M, K = map(int, input().split())
2 A = list(map(int, input().split()))
3 B = list(map(int, input().split()))
4
5 a, b = [0], [0]
6 for i in range(N):
7 	a.append(a[i] + A[i])
8 for i in range(M):
9 	b.append(b[i] + B[i])
10
11 ans, j = 0, M
12 for i in range(N + 1):
13 　　if a[i] > K:
14 		　break
15 　while b[j] > K - a[i]:
16 　　j -= 1
17 　ans = max(ans, i + j)
18 print(ans)


1 N, M, K = map(int, input().split())
2 A = list(map(int, input().split()))
3 B = list(map(int, input().split()))
4
5 a, b = [0], [0]
6 for i in range(N):
7 　　a.append(a[i] + A[i])
8 for i in range(M):
9 　　b.append(b[i] + B[i])
10
11 ans, j = 0, M
12 for i in range(N + 1):
13 　　if a[i] > K:
14 　　　　break
15　　 while b[j] > K - a[i]:
16 　　　　j -= 1
17 　　ans = max(ans, i + j)
18 print(ans)


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)

def main():

    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)


if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[0]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[0]
    totalB.append(sumB)

iA = N
iB = 0
countMax = 0
while iA >= 0:
    if totalA[iA] + totalB[iB] > K:
        iA -= 1
    else:
        if iB < M:
            countMax = max(countMax, iA + iB)
            iB += 1
    elif iA == N and iB == M:
        countMax = max(countMax, iA + iB)
        break

print(countMax)



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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui.append(a[i] + arui[i])
for i in range(M):
    brui.append(b[i] + brui[i])

ans = 0
for i in range(N + 1):
    if arui[i] > K:
        break
    bcnt = M
    while brui[bcnt] + arui[i] > K:
        bcnt -= 1
    ans = max(ans, i + bcnt)

print(ans)

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]

ans = 0
bcnt = M
for i in range(N + 1):
    if arui[i] > K:
        break

    while brui[bcnt] + arui[i] > K:
        bcnt -= 1
    ans = max(ans, i + bcnt)

print(ans)


Verdicts: Wrong Answer

Accepted