Created
May 21, 2017 03:16
-
-
Save whatalnk/101b3bc4e7326cf5234b858cea83abd9 to your computer and use it in GitHub Desktop.
AtCoder ABC #062 (D, python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
N = int(input()) | |
a = list(map(int, input().split())) | |
left = [] | |
for i in a[:N]: | |
heapq.heappush(left, i) | |
right = [] | |
for i in a[(2 * N):(3 * N)]: | |
heapq.heappush(right, -i) | |
left_sum = [sum(left)] | |
right_sum = [-sum(right)] | |
for k in range(N, 2 * N): | |
heapq.heappush(left, a[k]) | |
v = heapq.heappop(left) | |
left_sum.append(left_sum[-1] + a[k] - v) | |
for k in range(2 * N - 1, N - 1, -1): | |
heapq.heappush(right, -a[k]) | |
v = heapq.heappop(right) | |
right_sum.append(right_sum[-1] + a[k] + v) | |
print(max([a - b for (a, b) in zip(left_sum, right_sum[::-1])])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment