diff --git a/zeta_python/completed/2473.py b/zeta_python/completed/2473.py new file mode 100644 index 0000000..93c9792 --- /dev/null +++ b/zeta_python/completed/2473.py @@ -0,0 +1,31 @@ +def solve(N: int, S: list[int]): + S.sort() + st1: int = 0 + st2: int = st1 + 1 + end: int = N - 1 + r = 1000_0000_0000_0000 + r_pos = None, None, None + while st2 < end: + while st2 < end: + s = S[st1] + S[st2] + S[end] + if abs(s) < r: + r = abs(s) + r_pos = st1, st2, end + if r == 0: + return sorted((S[r_pos[0]], S[r_pos[1]], S[r_pos[2]])) + if s < 0: + st2 += 1 + elif s > 0: + end -= 1 + + st1 += 1 + st2 = st1 + 1 + end = N - 1 + + return sorted((S[r_pos[0]], S[r_pos[1]], S[r_pos[2]])) + + +if __name__ == "__main__": + N = int(input()) + S = list(map(int, input().split())) + print(*solve(N, S)) diff --git a/zeta_python/stdin.txt b/zeta_python/stdin.txt index 9a03714..e69de29 100644 --- a/zeta_python/stdin.txt +++ b/zeta_python/stdin.txt @@ -1 +0,0 @@ -10 \ No newline at end of file