Submission #5224893


Source Code Expand

Copy
import heapq
N = int(input())
A = list(map(int,input().split()))
L = []
R = []
for i in range(N):
  L.append(A[i])
for i in range(N):
  R.append(-A[3*N-i-1])
SUML = [0]*(N+1)
SUMR = [0]*(N+1)
S = sum(L)
T = sum(R)
SUML[0] = S
SUMR[0] = -T
heapq.heapify(L) #これ必要
heapq.heapify(R)
for i in range(N,2*N):
  a = heapq.heappushpop(L,A[i])
  S = S-a+A[i]
  SUML[i-N+1] = S
for j in range(N,2*N):
  b = heapq.heappushpop(R,-A[3*N-j-1])
  T = T-b-A[3*N-j-1]
  SUMR[j-N+1] = -T
ans = -float('inf')
for i in range(N+1):
  if SUML[i]-SUMR[N-i] >= ans:
    ans = SUML[i]-SUMR[N-i]
print(ans)

Submission Info

Submission Time
Task D - 3N Numbers
User Syuko4omi
Language Python3 (3.4.3)
Score 500
Code Size 616 Byte
Status
Exec Time 443 ms
Memory 39260 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt
Subtask 300 / 300 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt
All 200 / 200 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt
Case Name Status Exec Time Memory
0_00.txt 18 ms 3064 KB
0_01.txt 18 ms 3064 KB
0_02.txt 19 ms 3064 KB
1_00.txt 18 ms 3064 KB
1_01.txt 18 ms 3064 KB
1_02.txt 18 ms 3064 KB
1_03.txt 18 ms 3064 KB
1_04.txt 18 ms 3064 KB
1_05.txt 18 ms 3064 KB
1_06.txt 18 ms 3064 KB
1_07.txt 18 ms 3064 KB
1_08.txt 20 ms 3188 KB
1_09.txt 21 ms 3444 KB
1_10.txt 21 ms 3316 KB
1_11.txt 21 ms 3316 KB
1_12.txt 21 ms 3316 KB
1_13.txt 21 ms 3316 KB
1_14.txt 21 ms 3316 KB
1_15.txt 21 ms 3316 KB
1_16.txt 21 ms 3188 KB
1_17.txt 21 ms 3188 KB
1_18.txt 22 ms 3188 KB
1_19.txt 21 ms 3188 KB
1_20.txt 21 ms 3444 KB
1_21.txt 21 ms 3572 KB
1_22.txt 21 ms 3572 KB
1_23.txt 22 ms 3572 KB
2_00.txt 281 ms 14948 KB
2_01.txt 310 ms 39260 KB
2_02.txt 347 ms 29100 KB
2_03.txt 337 ms 29100 KB
2_04.txt 313 ms 29100 KB
2_05.txt 335 ms 29100 KB
2_06.txt 316 ms 29100 KB
2_07.txt 300 ms 29100 KB
2_08.txt 287 ms 14756 KB
2_09.txt 286 ms 15228 KB
2_10.txt 290 ms 14864 KB
2_11.txt 287 ms 14672 KB
2_12.txt 443 ms 36420 KB
2_13.txt 441 ms 36900 KB
2_14.txt 437 ms 36772 KB
2_15.txt 441 ms 36780 KB