Problem p02623 (python)

Fixed submission:
def resolve():
    import numpy as np

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

    A = np.insert(np.cumsum(A), 0, 0)
    B = np.insert(np.cumsum(B), 0, 0)

    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)

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import numpy as np

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

    A_cumsum = np.cumsum(A)
    B_cumsum = np.cumsum(B)

    ans = 0
    j = M
    for i in range(N + 1):
        if A_cumsum[i] > K:
            break
        while A_cumsum[i] + B_cumsum[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)

resolve()

Buggy submission (verdict: Runtime Error):
import sys #追加
sys.setrecursionlimit(500*500) #追加

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

    def dfs(n, i, j, d, k):
        if k >= K or (i == N and j == M):
            return n
        if d == 1 and i < N and k + A[i] <= K:
            k += A[i]
            l = dfs(n + 1, i + 1, j, d, k)
            r = dfs(n + 1, i + 1, j, -d, k)
            return max(l, r)
        elif d == -1 and j < M and k + B[j] <= K:
            k += B[j]
            l = dfs(n + 1, i, j + 1, d, k)
            r = dfs(n + 1, i, j + 1, -d, k)
            return max(l, r)
        else:
            return n

    print(dfs(0, 0, 0, 1, 0))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    def dfs(n, i, j, d, k):
        if k >= K or (i == N and j == M):
            return n
        if d == 1 and i < N and k + A[i] <= K:
            k += A[i]
            l = dfs(n + 1, i + 1, j, d, k)
            r = dfs(n + 1, i + 1, j, -d, k)
            return max(l, r)
        elif d == -1 and j < M and k + B[j] <= K:
            k += B[j]
            l = dfs(n + 1, i, j + 1, d, k)
            r = dfs(n + 1, i, j + 1, -d, k)
            return max(l, r)
        else:
            return n

    print(dfs(0, 0, 0, 1, 0))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    def dfs(n, i, j, k):
        if k >= K or (i == N and j == M):
            return n
        if i < N and A[i] < B[j] and k + A[i] <= K:
            k += A[i]
            l = dfs(n + 1, i + 1, j, k)
        elif j < M and k + B[j] <= K:
            k += B[j]
            l = dfs(n + 1, i, j + 1, k)
        else:
            return n

        return l

    print(dfs(0, 0, 0, 0))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    def dfs(n, i, j, d, k):
        if k >= K or (i == N and j == M):
            return n
        if d == 1 and i < N and k + A[i] <= K:
            k += A[i]
            l = dfs(n + 1, i + 1, j, d, k)
            if j < M:
                r = dfs(n + 1, i + 1, j, -d, k)
        elif d == -1 and j < M and k + B[j] <= K:
            k += B[j]
            l = dfs(n + 1, i, j + 1, d, k)
            if i < N:
                r = dfs(n + 1, i, j + 1, -d, k)
        else:
            return n

        return max(l, r)

    print(dfs(0, 0, 0, 1, 0))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    def dfs(n, i, j, d, k):
        if k >= K or (i == len(A) and j == len(B)):
            return n
        if d == 1 and i < len(A) and k + A[i] <= K:
            k += A[i]
            l = dfs(n + 1, i + 1, j, d, k)
            r = dfs(n + 1, i + 1, j, -d, k)
        elif d == -1 and j < len(B) and k + B[j] <= K:
            k += B[j]
            l = dfs(n + 1, i, j + 1, d, k)
            r = dfs(n + 1, i, j + 1, -d, k)
        else:
            return n

        return max(l, r)

    print(dfs(0, 0, 0, 1, 0))

resolve()