목차

물고기 게임

ps
링크acmicpc.net/…
출처BOJ
문제 번호31027
문제명물고기 게임
레벨플래티넘 5
분류

게임 이론

시간복잡도O(n)
인풋사이즈n<=500000
사용한 언어Python 3.13
제출기록106684KB / 256ms
최고기록256ms
해결날짜2025/08/21

풀이

코드

"""Solution code for "BOJ 31027. 물고기 게임".

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

Tags: [game theory]
"""


def main():
    N = int(input())
    A1 = [int(x) for x in input().split()]
    A2 = [int(x) for x in input().split()]

    if N % 2 == 1:
        score1 = sum(A1[: N // 2]) + sum(A2[: N // 2])
        score2 = min(sum(A1), score1 + A1[N // 2] + A2[N // 2])
        otto_score = max(score1, score2)
    else:
        score1 = sum(A1[: N // 2]) + sum(A2[: N // 2])
        score2a = max(score1, sum(A1))
        score2b = score1 + A1[N // 2] + A2[N // 2]
        score2 = min(score2a, score2b)
        otto_score = max(score1, score2)

    print(otto_score, sum(A1) + sum(A2) - otto_score)


if __name__ == '__main__':
    main()