def maksimum(n, a):
    dp = [[0] * n for _ in range(n)]

    for length in range(1, n + 1):
        for i in range(n - length + 1):
            j = i + length - 1
            if (j - i + 1) % 2 == n % 2: 
                dp[i][j] = max(
                    a[i] + (dp[i + 1][j] if i + 1 <= j else 0),
                    a[j] + (dp[i][j - 1] if i <= j - 1 else 0)
                )
            else:
                dp[i][j] = min(
                    dp[i + 1][j] if i + 1 <= j else 0,
                    dp[i][j - 1] if i <= j - 1 else 0
                )

    return dp[0][n - 1]

n, m = map(int, input().split())
a = list(map(int, input().split()))

if m == 2:
    zbir = sum(a)
    brt1 = maksimum(n, a)
    brt2 = zbir - brt1
    print(brt1, brt2)