-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABC_160_E.py
43 lines (43 loc) · 1.23 KB
/
ABC_160_E.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
import heapq
r=sys.stdin.readline
X,Y,A,B,C=map(int,r().split())
Red=list(map(int,r().split()))
Green=list(map(int,r().split()))
White=list(map(int,r().split()))
Red.sort(reverse=True)
Green.sort(reverse=True)
White=[-x for x in White]
RedtoEat=Red[:X]
GreentoEat=Green[:Y]
heapq.heapify(RedtoEat)
heapq.heapify(GreentoEat)
heapq.heapify(White)
res=0
while True:
if not White:
break
wtop=int(White[0]*(-1))
rtop=int(RedtoEat[0])
gtop=int(GreentoEat[0])
if wtop<=rtop and wtop<=gtop:
break
else:
if wtop>rtop and wtop>gtop:#둘다 후보임
if rtop>gtop:
heapq.heappop(GreentoEat)
tmp=heapq.heappop(White)
heapq.heappush(GreentoEat,-tmp)
else:
heapq.heappop(RedtoEat)
tmp=heapq.heappop(White)
heapq.heappush(RedtoEat,-tmp)
elif wtop>rtop:
heapq.heappop(RedtoEat)
tmp=heapq.heappop(White)
heapq.heappush(RedtoEat,-tmp)
elif wtop>gtop:
heapq.heappop(GreentoEat)
tmp=heapq.heappop(White)
heapq.heappush(GreentoEat,-tmp)
print(sum(RedtoEat)+sum(GreentoEat))