alexjercan/bugnet huggingface dataset:
Problem p02615 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque

N = int(input())
A = list([int(x) for x in input().split()])

A.sort(reverse=True)

comfort = 0
comfort_list = deque()

for a in A:
    if len(comfort_list) == 0:
        comfort_list.append(a)
    else:
        max_comfort = comfort_list.popleft()
        comfort += max_comfort
        comfort_list.append(min(a, max_comfort))
        comfort_list.append(min(a, max_comfort))

print(comfort)


Error: TLE

Fixed submission:

N = int(input())
A = list([int(x) for x in input().split()])

A.sort(reverse=True)


comfort = 0

comfort_list = []

for a in A:
    if comfort_list == []:
        comfort_list.append(a)
    else:
        max_comfort = comfort_list.pop(0)
        comfort += max_comfort
        comfort_list.append(min(a, max_comfort))
        comfort_list.append(min(a, max_comfort))

print(comfort)
Problem p02618 (Python) — buggy submission, verdict: Runtime Error

d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]

last = [0] * 26
for di in range(d):
    minus = [c[i] * (di + 1 - last[i]) for i in range(26)]
    cnt = [s[di][i] + minus[i] for i in range(26)]
    ti = cnt.index(max(cnt))
    last[ti] = di + 1
    print(ti + 1)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02618/Python/s583750787.py", line 4, in <module>
    t = [int(input()) for _ in range(d)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02618/Python/s583750787.py", line 4, in <listcomp>
    t = [int(input()) for _ in range(d)]
EOFError: EOF when reading a line


Fixed submission:

d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

last = [0] * 26
ans = 0
for di in range(d):
    ans += s[di][t[di] - 1]
    last[t[di] - 1] = di + 1
    ans -= sum(c[i] * (di + 1 - last[i]) for i in range(26))
    print(ans)
Problem p02620 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys


def B(T):
    global S, Z, D
    _last = [0] * Z
    cnt = 0
    for d in range(1, D + 1):
        t = T[d]
        _last[t] = d
        up = S[d][t]
        down = sum(C[i] * (d - _last[i]) for i in range(Z))
        cnt += up - down
    return cnt


def checkScore(r):
    global D, last
    L = last[r]
    rst = 0
    for d in range(1, D + 1):
        down = C[r] * (d - L[d])
        up = S[d][r] if L[d] == d else 0
        rst += up - down
    return rst


Z = 26
D = int(input())
C = list(map(int, input().split()))
S = [tuple([0] * Z)]
S += [tuple(map(int, input().split())) for _ in range(D)]
T = [None] + [int(input()) - 1 for _ in range(D)]

M = int(input())
Q = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]


last = [[0] * (D + 1) for _ in range(Z)]
V = [0] * Z
for d in range(1, D + 1):
    t = T[d]
    for p in range(Z):
        last[p][d] = last[p][d - 1]
    last[t][d] = d
for p in range(Z):
    V[p] = checkScore(p)

score = sum(V)

for d, q in Q:
    d += 1

    p = T[d]
    T[d] = q

    for r, L in ((p, last[p]), (q, last[q])):
        for e in range(1, D + 1):
            L[e] = L[e - 1] if r != T[e] else e

    score -= V[p] + V[q]
    V[p] = checkScore(p)
    V[q] = checkScore(q)
    score += V[p] + V[q]
    # # if M > 10 ** 4:
    #     print(score)
    # else:
    #     print(B(T))
    print(score)


Error: TLE

Fixed submission:

import sys


def B(T):
    global S, Z, D
    _last = [0] * Z
    cnt = 0
    for d in range(1, D + 1):
        t = T[d]
        _last[t] = d
        up = S[d][t]
        down = sum(C[i] * (d - _last[i]) for i in range(Z))
        cnt += up - down
    return cnt


def checkScore(r):
    global D
    L = last[r]
    rst = 0
    for d in range(1, D + 1):
        down = C[r] * (d - L[d])
        up = S[d][r] if down == 0 else 0
        rst += up - down
    return rst


Z = 26
D = int(input())
C = list(map(int, input().split()))
S = [tuple([0] * Z)]
S += [tuple(map(int, input().split())) for _ in range(D)]
T = [None] + [int(input()) - 1 for _ in range(D)]

M = int(input())
Q = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]


last = [[0] * (D + 1) for _ in range(Z)]
V = [0] * Z
for d in range(1, D + 1):
    t = T[d]
    for p in range(Z):
        last[p][d] = last[p][d - 1]
    last[t][d] = d
for p in range(Z):
    V[p] = checkScore(p)

score = sum(V)

for d, q in Q:
    d += 1

    p = T[d]
    T[d] = q

    for r, L in ((p, last[p]), (q, last[q])):
        for e in range(1, D + 1):
            L[e] = L[e - 1] if r != T[e] else e

    score -= V[p] + V[q]
    V[p] = checkScore(p)
    V[q] = checkScore(q)
    score += V[p] + V[q]
    # print(score == B(T), score, B(T))
    print(B(T))
Problem p02621 (Python) — buggy submission, verdict: Time Limit Exceeded

N = 10**6


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Error: TLE

Fixed submission:

N = 10**7


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)
Problem p02621 (Python) — buggy submission, verdict: Time Limit Exceeded

N = 5 * 10**8


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Error: TLE

Fixed submission:

N = 10**9


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)
Problem p02621 (Python) — buggy submission, verdict: Runtime Error

a = int(input())
print(a + a**2 + a**3)


Error: TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02621/Python/s078567518.py", line 2, in <module>
    print(a + a**2 + a**3)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'


Fixed submission:

a = input()
print(a + a**2 + a**3)
Problem p02622 (Python) — buggy submission, verdict: Runtime Error

S = input()
T = input()
N = len(S)
ans = 0
for i in range(N):
    if S[i] != T[i]:
        ans += 1
print(ans)


Error: TypeError: 'str' object does not support item assignment
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02622/Python/s028680665.py", line 7, in <module>
    S[i] = T[i]
TypeError: 'str' object does not support item assignment


Fixed submission:

S = input()
T = input()
N = len(S)
ans = 0
for i in range(N):
    if not S[i] == T[i]:
        S[i] = T[i]
        ans += 1
print(ans)
Problem p02622 (Python) — buggy submission, verdict: Time Limit Exceeded

s = input()
t = input()
a = 0
for i in range(0, len(s)):
    if s[i] != t[i]:
        a += 1
print(a)


Error: TLE

Fixed submission:

s = input()
t = input()
a = 1
b = 1
c = 0
while a <= len(s):
    for n in s:
        for m in t:
            if a == b and n == m:
                c += 1
            b += 1
        a += 1
        b = 1
print(len(s) - c)
Problem p02622 (Python) — buggy submission, verdict: Runtime Error

S = input()
T = input()
replaces = 0
for ch in range(len(S)):
    if S[ch] != T[ch]:
        replaces += 1

print(replaces)


Error: TypeError: 'str' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02622/Python/s517520692.py", line 4, in <module>
    for ch in range(S):
TypeError: 'str' object cannot be interpreted as an integer


Fixed submission:

S = input()
T = input()
replaces = 0
for ch in range(S):
    if S[ch] == T[ch]:
        replaces += 1

print(replaces)
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
acc_A = [0] + list(accumulate(A))
acc_B = [0] + list(accumulate(B))
res = 0
for i, a in enumerate(acc_A):
    if a > K:
        break
    idx = bisect_left(acc_B, K - a)
    idx = min(idx, M)
    if acc_B[idx] > K - a:
        idx -= 1
    res = max(res, i + idx)
print(res)


Error: 0

Fixed submission:

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
idx1 = 0
idx2 = 0
while True:
    if idx1 >= N and idx2 >= M:
        break
    if idx1 >= N:
        if B[idx2] <= K:
            K -= B[idx2]
            idx2 += 1
            continue
        else:
            break
    elif idx2 >= N:
        if A[idx1] <= K:
            K -= A[idx1]
            idx1 += 1
        else:
            break
    if A[idx1] <= B[idx2]:
        if A[idx1] <= K:
            K -= A[idx1]
            idx1 += 1
            continue
        else:
            break
    else:
        if B[idx2] <= K:
            K -= B[idx2]
            idx2 += 1
            continue
        else:
            break
print(idx1 + idx2)
Problem p02623 (Python) — buggy submission, verdict: Time Limit Exceeded

import itertools

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


A_accum = [0] + list(itertools.accumulate(A))
B_accum = [0] + list(itertools.accumulate(B))

book_num = 0

b_best = M
for n in range(N + 1):
    for m in range(b_best, -1, -1):
        if A_accum[n] + B_accum[m] <= K:
            b_best = m
            if book_num < n + m:
                book_num = n + m
            break

print(book_num)


Error: TLE

Fixed submission:

import itertools

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

book_num = 0

A_accum = [0] + list(itertools.accumulate(A))
B_accum = [0] + list(itertools.accumulate(B))
for n in range(N + 1):
    for m in range(M + 1):
        if K < A_accum[n] + B_accum[m]:
            break
        if book_num < n + m:
            book_num = n + m

print(book_num)
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

from itertools import accumulate
from bisect import bisect

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


Error: TypeError: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02623/Python/s760036159.py", line 10, in <module>
    ans = max(i - 1 + bisect(b, k - x))
TypeError: 'int' object is not iterable


Fixed submission:

from itertools import accumulate
from bisect import bisect

n, m, k = map(int, input().split())
a = [*accumulate(map(int, input().split()), initial=0)]
b = [*accumulate(map(int, input().split()), initial=0)]
ans = 0
for i, x in enumerate(a):
    if x <= k:
        ans = max(i - 1 + bisect(b, k - x))
print(ans)
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

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

# 全部Aから選んでみる
minutes_a = 0
count_a = 0
for i in range(N):
    if minutes_a + A[i] > K:
        break
    minutes_a += A[i]
    count_a += 1

ans = count_a
minutes_b = 0
count_b = 0

for i in range(M):
    if minutes_a + minutes_b + B[i] > K:
        found = False
        while count_a > 0:
            minutes_a -= A[count_a - 1]
            count_a -= 1
            if minutes_a + minutes_b + B[i] <= K:
                minutes_b += B[i]
                count_b += 1
                found = True
                break
        if not found:
            break
    else:
        minutes_b += B[i]
        count_b += 1
    ans = max(ans, count_a + count_b)

print(ans)


Error: 0

Fixed submission:

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

# 全部Aから選んでみる
minutes_a = 0
count_a = 0
for i in range(N):
    if minutes_a + A[i] > K:
        break
    minutes_a += A[i]
    count_a += 1

minutes_b = 0
count_b = 0

if minutes_a < K:
    for i in range(M):
        if minutes_a + minutes_b + B[i] > K:
            break
        minutes_b += B[i]
        count_b += 1

for i in range(count_b, M):
    if minutes_a + minutes_b + B[i] > K:
        if count_a > 0 and minutes_a - A[count_a - 1] + minutes_b + B[i] <= K:
            minutes_a -= A[count_a - 1]
            count_a -= 1
            minutes_b += B[i]
            count_b += 1
            continue
        else:
            break
    minutes_b += B[i]
    count_b += 1

a_max = count_a + count_b

# 全部Bから選んでみる
minutes_b = 0
count_b = 0
for i in range(M):
    if minutes_b + B[i] > K:
        break
    minutes_b += B[i]
    count_b += 1

minutes_a = 0
count_a = 0

if minutes_b < K:
    for i in range(N):
        if minutes_b + minutes_a + A[i] > K:
            break
        minutes_a += A[i]
        count_a += 1

for i in range(count_a, N):
    if minutes_b + minutes_a + A[i] > K:
        if count_b > 0 and minutes_b - B[count_b - 1] + minutes_a + A[i] <= K:
            minutes_b -= B[count_a - 1]
            count_b -= 1
            minutes_a += A[i]
            count_a += 1
            continue
        else:
            break
    minutes_a += A[i]
    count_a += 1

print(max(a_max, count_a + count_b))
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

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)


Error: 0

Fixed submission:

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

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
num_books = 0
allot_to_A = 0
allot_to_B = K
time_bankB = allot_to_B
read_in_B = []
baf_timeB = 0

for i in range(len(time_B)):
    if time_B[i] <= time_bankB:
        time_bankB -= time_B[i]
        num_books += 1
        read_in_B.append(time_B[i])
    else:
        baf_timeB = time_bankB
if baf_timeB == 0:
    baf_timeB = K - sum(time_B)

max_books = num_books
tmp = max_books


for i in range(len(time_A)):
    tmp = max_books
    dif = 1
    allot_to_A += time_A[i]
    allot_to_B -= time_A[i]
    if allot_to_B < 0:
        break
    time_to_reduce = time_A[i]
    while time_to_reduce > 0:
        if time_to_reduce <= baf_timeB:
            baf_timeB -= time_to_reduce
            break
        else:
            baf_timeB += read_in_B[-1]
            dif -= 1
            del read_in_B[-1]
    tmp += dif
    max_books = max(tmp, max_books)

print(max_books)
Problem p02623 (Python) — buggy submission, verdict: Time Limit Exceeded

import numpy as np
from functools import reduce

N, M, K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))


def get_cum(arr):
    cum_arr = [0]
    for e in arr:
        tot = cum_arr[-1] + e
        if tot > K:
            return cum_arr
        cum_arr.append(tot)
    return cum_arr


cumA = get_cum(As)
cumB = get_cum(Bs)

max_count = 0
a_thresh = len(cumA) - 1
a_count = a_thresh
b_count = 0
b_thresh = len(cumB) - 1
while a_count >= 0 and b_count <= b_thresh:
    while b_count <= b_thresh and cumA[a_count] + cumB[b_count] <= K:
        b_count += 1
    b_count = max(0, b_count - 1)
    if cumA[a_count] + cumB[b_count] <= K:
        max_count = max(max_count, a_count + b_count)
    a_count -= 1

print(max_count)


Error: TLE

Fixed submission:

import numpy as np
from functools import reduce

N, M, K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

cumA = reduce(lambda x, y: x + [y + x[-1]], As, [0])
cumB = reduce(lambda x, y: x + [y + x[-1]], Bs, [0])
cumA.append(np.inf)
cumB.append(np.inf)
cumA = np.array(cumA)
cumB = np.array(cumB)

max_count = 0
a_thresh = np.where(cumA > K)[0][0]
a_count = a_thresh
b_count = 0
b_thresh = np.where(cumB > K)[0][0]
while a_count >= 0 and b_count <= b_thresh:
    while b_count <= b_thresh and cumA[a_count] + cumB[b_count] <= K:
        b_count += 1
    b_count = max(0, b_count - 1)
    if cumA[a_count] + cumB[b_count] <= K:
        max_count = max(max_count, a_count + b_count)
    a_count -= 1

print(max_count)
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

def check(A, mid, K):
    return A[mid] <= K


def binMax(A, K):
    ok = -1  # maxVal when minimize
    ng = len(A)  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(A, mid, K):
            ok = mid
        else:
            ng = mid
    return ok


def resolve():
    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()]
    presumA = [0 for _ in range(N + 1)]
    for i in range(N):
        presumA[i + 1] = presumA[i] + A[i]
    presumB = [0 for _ in range(M + 1)]
    for i in range(M):
        presumB[i + 1] = presumB[i] + B[i]
    startA = binMax(presumA, K)
    maxA = 0
    for ai in range(startA, -1, -1):
        maxA = max(maxA, ai + binMax(presumB, K - presumA[ai]))
    print(maxA)


resolve()


Error: 0

Fixed submission:

def resolve():
    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()]
    sumA = 0
    ai, bi = 0, 0
    while sumA <= K:
        if ai < N and A[ai] < B[bi] and sumA + A[ai] <= K:
            sumA += A[ai]
            ai += 1
        elif bi < M and sumA + B[bi] <= K:
            sumA += B[bi]
            bi += 1
        else:
            break
    print(ai + bi)


resolve()
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

import numpy as np

from numba import njit


@njit("i8[:](i8, i8[:], i8[:])", cache=True)
def cumsum(K, A, cA):
    for i, a in enumerate(A):
        cA[i] += cA[i - 1] + A[i]
        if cA[i] > K:
            break

    cA = cA[cA != 0]
    cA = np.append(0, cA)
    return cA


@njit("i8(i8, i8[:], i8[:])", cache=True)
def solve(K, cA, cB):
    ans = np.searchsorted(cA, K - cB, side="right") - 1
    ans += np.arange(len(cB))
    return ans.max()


N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)

cA = np.zeros(N, dtype=np.int64)
cB = np.zeros(M, dtype=np.int64)

# np.cumsumだとoverflowする
cA = cumsum(K, A, cA)
cB = cumsum(K, B, cB)

ans = solve(K, cA, cB)
print(ans)


Error: TLE

Fixed submission:

import numpy as np

N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)

# 累積和
A = np.cumsum(A)
B = np.cumsum(B)

# K以下を抽出
A = A[A <= K]
B = B[B <= K]

# Aを逆順にする
A = A[::-1]

c = 0
c_max = 0
for i, a in enumerate(A):
    c += len(A) - i

    for j, b in enumerate(B):
        if a + b <= K:
            cb = j + 1

    c += cb
    if c > c_max:
        c_max = c
    c = 0

print(c_max)
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for (i,) in range(iter_max):
        if cum1[i] > limit:
            cur = 0
        else:
            cur = i
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(cur + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = [0] + list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
for i, a in enumerate(cum_a):
    if a > K:
        cur = 0
    else:
        cur = i
    cand = bisect_right(cum_b, K - a)
    ans = max(cur + cand, ans)

print(ans)


Error: TypeError: search() missing 1 required positional argument: 'limit'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02623/Python/s364683935.py", line 58, in <module>
    print(search(cum_a, cum_b, N))
TypeError: search() missing 1 required positional argument: 'limit'


Fixed submission:

# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for i in range(iter_max):
        if cum1[i] > limit:
            break
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(i + 1 + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = list(accumulate(A_list))
cum_b = list(accumulate(B_list))

if cum_a[0] < cum_b[0]:
    print(search(cum_a, cum_b, N))
else:
    print(search(cum_b, cum_a, M))
Problem p02623 (Python) — buggy submission, verdict: Runtime Error

from itertools import accumulate

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

a_cumsum = [0] + list(accumulate(a))
b_cumsum = [0] + list(accumulate(b))
j = m
res = 0
for i in range(n + 1):
    if a_cumsum[i] > k:
        break
    while a_cumsum[i] + b_cumsum[j] > k:
        j -= 1
    if (v := i + j) > res:
        res = v
print(res)


Error: 0

Fixed submission:

from collections import deque

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

t = 0
res = 0
while a or b:
    if not a:
        if t + b[0] > k:
            break
        else:
            t += b.popleft()
    elif not b:
        if t + a[0] > k:
            break
        else:
            t += a.popleft()
    else:
        if t + a[0] > k and t + b[0] > k:
            break
        if a[0] < b[0]:
            t += a.popleft()
        elif a[0] > b[0]:
            t += b.popleft()
        else:
            if a[1] < b[1]:
                t += a.popleft()
            else:
                t += b.popleft()
    res += 1
print(res)