Problem p02727 (python)

Fixed submission:
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)

    p = p[:X]
    q = q[:Y]
    pqr = p + q + r
    pqr.sort(reverse = True)
    return sum(pqr[:X+Y])




if __name__ == '__main__':
    # main()
    print(main())

Buggy submission (verdict: Runtime Error):
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        v = max([p[i], q[j], r[k]])
        if p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        elif q[j] == v:
            ans += q[j]
            countB += 1
            j += 1
        else:
            ans += r[k]
            countC += 1
            k += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        return ans + sum(targ[:Y-countB-countC])
    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        return ans + sum(targ[:X-countA-countC])

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.appendO(qq[-1] + q[i])

    out = ans
    for k in range(countC+1):
        m = X - k
        n = Y - (countC - k)
        if 0<= m < len(pp) and 0<=n < len(qq):
            out = max(out, ans + pp[m] + qq[n])
    return ans



if __name__ == '__main__':
    # main()
    print(main())

Buggy submission (verdict: Runtime Error):
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] >= p[i] and r[k] >= q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] > r[k]:
                countA += 1
                ans += p[i]
                i += 1
            elif q[j] > r[i]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countA-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]

    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])

    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y-(countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])

    return out


if __name__ == '__main__':
    # main()
    print(main())

Buggy submission (verdict: Runtime Error):
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    ans = 0
    i = 0
    for j in range(X):
        if j < C:
            if p[j] > r[i]:
                countA += 1
                ans += p[j]
            else:
                ans += r[i]
                i += 1
        else:
            ans += p[j]
            countA += 1
    for j in range(Y):
        if j < C:
            if q[j] > r[i]:
                countB += 1
                ans += q[j]
            else:
                ans += r[i]
                i += 1
        else:
            ans += q[j]
            countB += 1
    return ans


if __name__ == '__main__':
    # main()
    print(main())

Buggy submission (verdict: Runtime Error):
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    ans = 0
    i = 0
    for j in range(X):
        if j < C:
            if p[j] > r[i]:
                countA += 1
                ans += p[j]
            else:
                ans += r[i]
                i += 1
        else:
            ans += p[j]
            countA += 1
    for j in range(Y):
        if j < B:
            if q[j] > r[i]:
                countB += 1
                ans += q[j]
            else:
                ans += r[i]
                i += 1
        else:
            ans += q[j]
            countB += 1
    return ans


if __name__ == '__main__':
    # main()
    print(main())