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):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG


using namespace std;
typedef long long ll;

int N, M;
ll K;
vector<ll> A;
vector<ll> B;

bool is_ok(vector<ll> B, int cnt_a, int mid){
  return A[cnt_a] + B[mid] <= K;
}

int binary_search(vector<ll> B, int cnt_a) {
    int left = -1; // 配列の左端
    int right = B.size(); // 配列の右端
    // 両端の差が1になるまで続ける
    while (right - left > 1){
        int mid = (right + left) / 2; // 区間の真ん中
        if (is_ok(B, cnt_a, mid)) left = mid;  // もし調べている対象が「is_okの条件」に当てはまればleftをmidまで移動
        else right = mid;  // 当てはまらなければrightをmid-1に移動
    }
    return left;
}

int main(){
  cin >> N >> M >> K;
  // 0インデックスには何も読まない0という初期値をそのまま入れておく
  A.push_back(0);
  B.push_back(0);

  rep(i, N){
    ll a;
    cin >> a;
    A.push_back(a);
  }
  rep(i, M){
    ll b;
    cin >> b;
    B.push_back(b);
  }

  rep(i, N) A[i+1] += A[i];
  rep(i, M) B[i+1] += B[i];

  int ans = 0;
  int cnt_b;
  rep(cnt_a, N+1){
    if (A[cnt_a] > K) continue;
    cnt_b = binary_search(B, cnt_a);
    ans = max(ans, cnt_a + cnt_b);
  }
  cout << ans << endl;
}

from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))  
b_acc = [0] + list(accumulate(b))  

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    
    ok = 0
    ng = m + 1   
    
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        
        if b_acc[mid] <= rem:
        
            ok = mid
        else:
        
            ng = mid

    bn = ok
    ans = max(ans, an + bn)

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):
a.append("1000000001")
b.append("1000000001")
a[n]=int(a[n])
b[m]=int(b[m])

x=0
y=0
ans=0
time=0

for i in range(n+m):
    if a[x]<=b[y]:
        time+=a[x]
        if time>k:
            time-=a[x]
            print(ans)
            sys.exit()
        x+=1
        ans+=1
    else:
        time+=b[y]
        if time>k:
            time-=b[y]
            print(ans)
            sys.exit()   
        y+=1
        ans+=1
print(ans)

    

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)]
B=[0 for i in range(m)]
A[0]=a[0]
B[0]=b[0]
for i in range(n-1):
    A[i+1]=a[i+1]+A[i]

for i in range(m-1):
    B[i+1]=b[i+1]+B[i]

ans=0
A.insert(0,0)
B.insert(0,0)

for i in range(n+1):
    x=0
    y=m
    j=(x+y)//2
    if A[i]+B[m]<=k:
        ans=max(ans,i+m)
    elif not A[i]+B[0]>k:
        
        
        while y-x>1:
            if A[i]+B[j]<=k:
                x=j
            else:
                y=j
            j=(x+y)//2
        ans=max(ans,i+x)
    
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 sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n, m, k = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    A = list(accumulate(A))
    B = list(accumulate(B))
    ans = 0
    j = m
    for i in range(n + 1):
        if A[i] > k:
            break
        while A[i] + B[j] > k:
            j -= 1
        ans = max(ans, i + j)
        print(i, j, ans)
    print(ans)


if __name__=='__main__':
    main()

import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n, m, k = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    A = list(accumulate(A))
    B = list(accumulate(B))
    ans = 0
    j = m
    for i in range(n + 1):
        if A[i] > k:
            break
        while A[i] + B[j] > k:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


if __name__=='__main__':
    main()

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

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)


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():
    from itertools import chain

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

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == '__main__':
    main()


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 = map(int, input().split())
As = [int(n) for n in input().split()]
Bs = [int(n) for n in input().split()]

a_sum = [0] * (len(As) + 1)
b_sum = [0] * (len(Bs) + 1)

for i in range(1, len(As)):
    a_sum[i] = a_sum[i-1] + As[i]

for j in range(1, len(Bs)):
    b_sum[i] = b_sum[i-1] + Bs[i]

max_book_num = 0
j = M
for i in range(N+1):
    if a_sum[i] > K:
        continue

    while b_sum[j] + a_sum[i] > K:
        j -= 1
    
    max_book_num = max(max_book_num, i + j)

        
print(max_book_num)    



N,M,K = map(int, input().split())
As = [int(n) for n in input().split()]
Bs = [int(n) for n in input().split()]

a_sum = [0]
b_sum = [0]

for i in range(len(As)):
    a_sum.append(a_sum[-1] + As[i])

for j in range(len(Bs)):
    b_sum.append(b_sum[-1] + Bs[j])

 
max_book_num = 0
j = M
for i in range(N+1):
    if a_sum[i] > K:
        continue

    while b_sum[j] + a_sum[i] > K:
        j -= 1
    
    max_book_num = max(max_book_num, i + j)

        
print(max_book_num)    



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

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)

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

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(i+j,ans)
print(ans)

Verdicts: Wrong Answer

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):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m, k = rm()
a = rl()
b = list(itertools.accumulate(rl()))
if a[0] > k:
    ans = 0
else:
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k:
            right = j
        else:
            left = j
    ans = left + 1
t = 0
b0 = b[0]
for cnt, i in enumerate(a, 1):
    t += i
    if t > k:
        break
    if b0 > t-k:
        ans = max(ans, cnt)
        continue
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k-t:
            right = j
        else:
            left = j
    ans = max(ans, cnt + left + 1)
print(ans)



















import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m, k = rm()
a = rl()
b = list(itertools.accumulate(rl()))
if a[0] > k:
    ans = 0
else:
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k:
            right = j
        else:
            left = j
    ans = left + 1
t = 0
b0 = b[0]
for cnt, i in enumerate(a, 1):
    t += i
    if t > k:
        break
    if b0 > k-t:
        ans = max(ans, cnt)
        continue
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k-t:
            right = j
        else:
            left = j
    ans = max(ans, cnt + left + 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):
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)

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[j] + B[j])

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)

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

time = 0
cnt = 0
b = []

for i in B:
    if i+time>K:
        break
    time += i
    cnt += 1
    b.append(i)

b.reverse()
# print(b)
# print(cnt)
bi = 0
for i in range(N):
    if time+A[i] <= K:
        cnt += 1
        time += A[i]
    else:
        if len(b)-1 >= bi:
            if A[i] <= b[bi]:
                time -= b[bi]-A[i]
                bi += 1
        else:
            break
            # print("a")
            # print(time+A[i])
       
    # print(time)

time2 = 0
cnt2 = 0
a = []

for i in A:
    if i+time>K:
        break
    time2 += i
    cnt2 += 1
    a.append(i)

a.reverse()
# print(b)
# print(cnt)
ai = 0
for i in range(N):
    if time2+B[i] <= K:
        cnt2 += 1
        time2 += B[i]
    else:
        if len(a)-1 >= ai:
            if B[i] <= a[ai]:
                time2 -= a[ai]-B[i]
                ai += 1
        else:
            break
            # print("a")
            # print(time+A[i])
       
    # print(time)


print(max((cnt, cnt2))

'''
5 3 8
5 0 0 1 1
1 2 1000
'''

from itertools import accumulate

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


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

def main():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    
    A_sum = 0
    A_max = N
    tmp_sum = 0
    if A[0] > K:
        flag = False
    else:
        flag = True
    for i in range(N):
        tmp_sum += A[i]
        if tmp_sum > K:
            A_max = i
            break
        else:
            A_sum = tmp_sum
        
    ans = A_max
    tmp_ans = ans
    
    B_i = 0
    time = K - A_sum
    count = 0
    for i in range(-1,A_max):
        if i != -1 and flag:
            A_i = A_max -1 -i
            time += A[A_i]
            count = -1
            
        if i == -1 or flag:
            tmp_time = time
            next_B_i = B_i
            for j in range(B_i,M):
                tmp_time -= B[j]
                if tmp_time >= 0:
                    next_B_i += 1
                    count += 1
                    time = tmp_time
                else:
                    break
                    
            B_i = next_B_i
            tmp_ans += count
            if count >= 0:
                ans = tmp_ans
            
    print(ans)
    
if __name__ == '__main__':
    main()

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

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 io
import sys

_INPUT = """\
1 4 120
100 1 1 1 1 1 1 1 1 1 1
80 10 10 10 10
"""
sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  # return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

N,M,K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]



from itertools import accumulate
C = accumulate(A)
D = accumulate(B)

E = []
F = []
for c in C:
  if c > K: break
  E.append(c)

for d in D:
  if d > K: break
  F.append(d)

p(*E)
p(*F)

c = d = 0
ans = k = 0


for i, e in enumerate(E):
  for j, f in enumerate(F):
    if e + f > K: break
    ans = max(ans, i+1+j+1)

print(ans)


import io
import sys

_INPUT = """\
1 4 120
100 1 1 1 1 1 1 1 1 1 1
80 10 10 10 10
"""
sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

N,M,K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]



from itertools import accumulate
C = accumulate(A)
D = accumulate(B)

E = [0]
F = [0]
for c in C:
  if c > K: break
  E.append(c)

for d in D:
  if d > K: break
  F.append(d)

p(*E)
p(*F)

c = d = 0
ans = k = 0

for i, e in enumerate(E):
  for j, f in enumerate(F):
    if e + f > K: break
    ans = max(ans, i+j)

print(ans)


# import io
# import sys

# _INPUT = """\
# 1 4 120
# 100 1 1 1 1 1 1 1 1 1 1
# 80 10 10 10 10
# """


####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

N,M,K = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]


from itertools import accumulate
A = list(accumulate(a))
B = list(accumulate(b))

p(*A)
p(*B)

from bisect import bisect_right as br

ans = 0




A = [0] + A
for a, ka in enumerate(A):
  if ka > K: break

  b = br(B, K - ka) 
  ans = max(ans, a + b)


print(ans)


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):
def main():
    N, M, K = map(int, input().split())
    A = deque([int(a) for a in input().split()])
    B = deque([int(b) for b in input().split()])
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    A.appendleft(0)

    for i in range(len(A)):
        Asum += A[i]

        for j in range(idx_b + 1):
            if Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, i + (idx_b + 1))

    print(ans)
 
if __name__ == "__main__":
    main()

def main4():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    for i in range(N + 1):

        if i == 0:
            Asum += 0
        else:
            Asum += A[i - 1]

        while Asum + Bsum > K:
            if idx_b >= 0:
                Bsum -= B[idx_b]
                idx_b -= 1
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, i + idx_b + 1)

    print(ans)

if __name__ == "__main__":
    main4()

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):
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

# %%

N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

# %%
AA = [0] * (N + 1)
BB = [0] * (M + 1)
for i, v in enumerate(A):
    AA[i + 1] += v + AA[i]
for i, v in enumerate(B):
    BB[i + 1] += v + BB[i]

ans = 0
b_cnt = M
for a_cnt in range(N + 1):
    if AA[a_cnt] > K:
        continue
    while AA[a_cnt] + BB[b_cnt] > K:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

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(' '))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))
a_sum = 0
b_sum = sum(b_list)

j = m
best=0
for i, a in enumerate(a_list):
  a_sum+=a
  if a_sum>k:
    break
  while ((a_sum + b_sum) > k) & (j>=0):
    b_sum-=b_list[j]
    j-=1
    
  best = max(best,i+j+2)
      
  
    
print(best)

import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

if sum(list_)<=k:
  print(len(list_))
else:
  left = 0
  right = len(list_)
  while abs(left-right)>1:
    mid = (left+right) // 2
    if sum(list_[:mid])<=k:
      left = mid
    else:
      right = mid

  print(len(list_[left]))

n, m, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))
sa = [0] * (n+1)
sb = [0] * (m+1)

for i in range(n):
  sa[i+1] = a_list[i] + sa[i]
for j in range(m):
  sb[j+1] = b_list[j] + sb[j]

best=0
r = m
for a in a_list:
  if a>k:
    break
  while ((a + sb[r]) > k) & (r>=0):
    r-=1
    
  best = max(best,i+j+2)
      
  
    
print(best)

n, m, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))
sa = [0] * (n+1)
sb = [0] * (m+1)

for i in range(n):
  sa[i+1] = a_list[i] + sa[i]
for j in range(m):
  sb[j+1] = b_list[j] + sb[j]

best=0
r = m
for i, a in enumerate(sa):
  if a>k:
    break
  while ((a + sb[r]) > k) & (r>=0):
    r-=1
    
  best = max(best,i+r)
      
  
    
print(best)

Verdicts: Runtime Error

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):
from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [x for x in accumulate([int(n) for n in input().split()])]
B = [x for x in accumulate([int(n) for n in input().split()])]
ans = 0
a = bisect(A, K)
for i in range(a-1, -1, -1):
  b = bisect(B, K-A[i])
  ans = max(ans, i+b)
print(ans)


from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [0]+[x for x in accumulate([int(n) for n in input().split()])]
B = [0]+[x for x in accumulate([int(n) for n in input().split()])]
ans = 0
a = bisect_left(A, K)
for i in range(a):
  b = bisect_left(B, K-A[i])
  ans = max(ans, i+b)
print(ans)


from itertools import accumulate
from bisect import *

N, M, K = [int(n) for n in input().split()]
A = [0]+[x for x in accumulate([int(n) for n in input().split()])]
B = [0]+[x for x in accumulate([int(n) for n in input().split()])]
#print(A)

ans = 0
a = bisect_right(A, K)
#print(a)
for i in range(a):
  b = bisect_right(B, K-A[i])
  ans = max(ans, i+b)
#  print(ans, i, b)
print(ans-1)


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):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
a = na()
b = na()
aa = [0]
bb = [0]

for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)

import bisect
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    kk = k-aa[i]
    ans = max(ans, i+bisect.bisect_left(bb,kk))

print(ans)

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
a = na()
b = na()
aa = [0]
bb = [0]

for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)

import bisect
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    kk = k-aa[i]
    ans = max(ans, i+bisect.bisect_right(bb,kk)-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):
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = A[:]
cb = B[:]

for i in range(N-1):
  ca[i+1] += ca[i]
for i in range(M-1):
  cb[i+1] += cb[i]
print(ca, cb)
ans = 0
for i in range(N):
  if ca[i] <= K:
    idx = bisect.bisect_right(cb, K-ca[i])
  else:
    continue
  
  ans = max(ans, i+idx+1)


for i in range(M):
  if cb[i] <= K:
    idx = bisect.bisect_right(cb, K-cb[i])
  else:
    continue
  
  ans = max(ans, i+idx+1)
print(ans)


import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = A[:]
cb = B[:]

for i in range(N-1):
  ca[i+1] += ca[i]
for i in range(M-1):
  cb[i+1] += cb[i]

ans = 0
for i in range(N):
  if ca[i] <= K:
    idx = bisect.bisect_right(cb, K-ca[i])
  else:
    continue
  if 0 < idx < M:
    j = idx - 1
  elif idx == 0:
    j = 0
  elif idx == M:
    j = M
  
  ans = max(ans, (i+1)+j)

print(ans)


import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = A[:]
cb = B[:]

for i in range(N-1):
  ca[i+1] += ca[i]
for i in range(M-1):
  cb[i+1] += cb[i]

ans = 0
for i in range(N):
  if ca[i] <= K:
    idx = bisect.bisect_right(cb, K-ca[i])
  else:
    continue
  
  ans = max(ans, i+idx+1)

for i in range(M):
  if cb[i] <= K:
    idx = bisect.bisect_right(ca, K-cb[i])
  else:
    continue
  
  ans = max(ans, i+idx+1)
print(ans)


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

import numpy as np

a =[]

if K 

flag = True
while flag:
    if A[0] >= K or B[0] >= K:
        flag = False
    elif not A and not B:
        flag = False
    elif not A:
        a.append(B[0])
        B = B[1:]
    elif not B:
        a.append(A[0])
        A = A[1:]
    elif A[0] <= B[0]:
        a.append(A[0])
        A = A[1:]
    #elif A[0] > B[0]:
    else:
        a.append(B[0])
        B = B[1:]

res = np.cumsum(a)
r = list(res)

cnt = 0
for i in r:
    if i <= K:
        cnt += 1
    else:
        break
print(cnt)

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

import numpy as np

a =[]
flag = True
while flag:
    if A[0] >= K or B[0] >= K:
        flag = False
    elif not A and not B:
        flag = False
    elif not A:
        a.append(B[0])
        B = B[1:]
    elif not B:
        a.append(A[0])
        A = A[1:]
    elif A[0] <= B[0]:
        a.append(A[0])
        A = A[1:]
    else:
        a.append(B[0])
        B = B[1:]

res = np.cumsum(a)
r = list(res)

cnt = 0
for i in r:
    if i <= K:
        cnt += 1
    else:
        break
print(cnt)

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+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):
n, m, k=map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1=[0]


for i in range(n):
	
    
	acum1.append(acum[-1]+arr1[i])
    
acum2 = [0]

for i in range(m):
	
    
	acum2.append(acum2[-1]+arr2[i])

ans = 0
for i in range(n+1):
	
    
	if acum1[i] > k:
    	break
    
    
    
    while acum2[j]>k - acum1[i] and j>0:
    	j -= 1
        ans = max(ans, i+j)
print(ans)

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

acum1=[0]


for i in range(n):
	acum1.append(acum[-1]+arr1[i])
    
acum2 = [0]

for i in range(m):
	acum2.append(acum2[-1]+arr2[i])

ans = 0
for i in range(n+1):
	if acum1[i] > k:
    	break
    while acum2[j]>k - acum1[i] and j>0:
    	j -= 1
        ans = max(ans, i+j)
print(ans)


N, M, X = map(int, input().split())
C = []
A = []
for  i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])
    
result = -1


for i in range(1 << N):
    
    t = [0] * M
    c = 0
    #print(i)
    for j in range(N):
        #print(j)
        if(i >> j ) & 1 == 0 :
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)

n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]

for i in range(n): 
	
    
 acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
 acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
    
    
    
 if acum1[i]>k:
   break
       
    
    
 while acum2[j]>k-acum1[i] and j>0: 
   j-=1
 ans=max(ans,i+j)
print(ans)

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

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(n):
    f += b[i]
    e.append(f)


ans = 0
j = q-1
for i in range(n):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

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

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

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

c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

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


ans = 0
j = q-1
for i in range(n):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)

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

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

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


c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

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


ans = 0
j = m
for i in range(n+1):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

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):
import sys
n, m, k = list(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_max = 0
for i in range(n, 0, -1)
  if a[i-1] <= k:
    a_max = i
    break
b_max = 0
for i in range(m, 0, -1)
  if a[i-1] <= k:
    b_max = i
    break
    
ans = 0
for i in range(a_max, 0, -1):
  p = 0
  q = 0
  if a[i-1] <= k:
    p = a[i-1]
    q = i
  for j in range(b_max, 0, -1):
    if p + b[j-1] <= k:
      ans = max(ans, q + j)
    
print(ans)

import sys
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 = 0
j = m
for i in range(n + 1):
  if a[i] > k:
    break
  while a[i] + b[j] > k:
      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())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
time=0
count=0
l=len(a)+len(b)
for i in range(l)
    if len(b)>0:
        if len(a)>0:
            if a[0]<b[0]:
                if time+a[0]<=k:
                    time+=a[0]
                    a.pop(0)
                else:
                    break
            else:
                if time+b[0]<=k:
                    time+=b[0]
                    b.pop(0)
                else:
                    break
        else:
            if time+b[0]<=k:
                time+=b[0]
                b.pop(0)
            else:
                break
    elif len(a)>0:
        if time+a[0]<=k:
            time+=a[0]
            a.pop(0)
        else:
            break
    else:
        break
    count+=1
print(count)

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

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

res = 0
time = 0

while time <= K:
    if A[0] <= B[0]:
        time = time + A.pop(0)
    else:
        time = time + B.pop(0)
    res += 1

print(res)

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


lst = [0]*(N+1)

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

res = max(lst)
print(res)

"""
3 4 240
60 90 120
80 150 80 150

3 4 730
60 90 120
80 150 80 150
"""

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

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

res = max(lst)
print(res)

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

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, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    if arA[idxA] <= arA[idxB] and idxA < n:
        readTime += arA[idxA]
        idxA += 1
    else:
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)


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