목차

용액

ps
링크acmicpc.net/…
출처BOJ
문제 번호2467
문제명용액
레벨골드 5
분류

투 포인터

시간복잡도O(n)
인풋사이즈n<=100,000
사용한 언어Python
제출기록40768KB / 120ms
최고기록116ms
해결날짜2021/09/16

풀이

코드

"""Solution code for "BOJ 2467. 용액".

- Problem link: https://www.acmicpc.net/problem/2467
- Solution link: http://www.teferi.net/ps/problems/boj/2467
"""

INF = float('inf')


def main():
    N = int(input())  # pylint: disable=unused-variable
    nums = [int(x) for x in input().split()]

    from_left, from_right = iter(nums), reversed(nums)
    left, right = next(from_left), next(from_right)
    min_abs_sum = INF
    answer = None
    for _ in range(N - 1):
        sum_val = left + right
        if abs(sum_val) < min_abs_sum:
            min_abs_sum, answer = abs(sum_val), (left, right)
        if sum_val > 0:
            right = next(from_right)
        else:
            left = next(from_left)

    print(*answer)


if __name__ == '__main__':
    main()