Problem p03078 (python)

Fixed submission:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def main():
    x, y, z, w = ns()
    a = na()
    b = na()
    c = na()

    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)

    ans = []
    for ai in a:
        for bi in b:
            ans.append(ai + bi)

    ans.sort(reverse=True)
    ans = ans[:3010]

    res = []
    for ci in c:
        for i in range(len(ans)):
            res.append(ci + ans[i])
    res.sort(reverse=True)

    for i in range(w):
        print(res[i])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def main():
    x, y, z, w = ns()
    a = na()
    b = na()
    c = na()

    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)

    ans = []
    lim = 4000
    for i in range(x):
        if x > lim:
            break
        for j in range(y):
            if x * y > lim:
                break
            for k in range(z):
                if x * y * z > lim:
                    break
                ans.append(a[i] + b[j] + c[k])

    ans.sort(reverse=True)

    for i in range(w):
        print(ans[i])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def main():
    x, y, z, w = ns()
    a = na()
    b = na()
    c = na()

    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)

    ans = []
    lim = 3333
    for i in range(x):
        if x > lim:
            break
        for j in range(y):
            if x * y > lim:
                break
            for k in range(z):
                if x * y * z > lim:
                    break
                ans.append(a[i] + b[j] + c[k])
                
    ans.sort(reverse=True)

    for i in range(w):
        print(ans[i])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def main():
    x, y, z, w = ns()
    a = na()
    b = na()
    c = na()

    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)

    ans = []
    for i in range(x):
        if x > 3000:
            break
        for j in range(y):
            if x * y > 3000:
                break
            for k in range(z):
                if x * y * z > 3000:
                    break
                ans.append(a[i] + b[j] + c[k])
    ans.sort(reverse=True)

    for i in range(w):
        print(ans[i])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def main():
    x, y, z, w = ns()
    size = [[0, x], [1, y], [2, z]]
    size.sort(key=lambda x: x[1])
    d = []
    for _ in range(3):
        tmp = na()
        tmp.sort(reverse=True)
        d.append(tmp)

    d2 = []
    for i, s in size:
        d2.append(d[i])

    lima = min(size[0][1], 15)
    limb = min(size[1][1], int((3375 / lima) ** (1 / 2)) + 1)
    limc = min(size[2][1], int((3375 / lima / limb) ** (1 / 2)) + 2)

    ans = []
    for i in range(lima):
        for j in range(limb):
            for k in range(limc):
                ans.append(d2[0][i] + d2[1][j] + d2[2][k])
    ans.sort(reverse=True)

    for i in range(w):
        print(ans[i])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def main():
    x, y, z, w = ns()
    size = [[0, x], [1, y], [2, z]]
    size.sort(key=lambda x: x[1])
    d = []
    for _ in range(3):
        tmp = na()
        tmp.sort(reverse=True)
        d.append(tmp)

    d2 = []
    for i, s in size:
        d2.append(d[i])

    lima = min(size[0][1], 15)
    limb = min(size[1][1], int(math.sqrt(3000 / lima)) + 1)
    limc = min(size[2][1], int(math.sqrt(3000 / lima / limb)) + 1)

    ans = []
    for i in range(lima):
        for j in range(limb):
            for k in range(limc):
                ans.append(d2[0][i] + d2[1][j] + d2[2][k])
    ans.sort(reverse=True)

    for i in range(w):
        print(ans[i])


if __name__ == '__main__':
    main()