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()