forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path12.py
More file actions
17 lines (14 loc) ยท 735 Bytes
/
12.py
File metadata and controls
17 lines (14 loc) ยท 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
n, k = map(int, input().split()) # N๊ณผ K๋ฅผ ์
๋ ฅ ๋ฐ๊ธฐ
a = list(map(int, input().split())) # ๋ฐฐ์ด A์ ๋ชจ๋ ์์๋ฅผ ์
๋ ฅ๋ฐ๊ธฐ
b = list(map(int, input().split())) # ๋ฐฐ์ด B์ ๋ชจ๋ ์์๋ฅผ ์
๋ ฅ๋ฐ๊ธฐ
a.sort() # ๋ฐฐ์ด A๋ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ ์ํ
b.sort(reverse=True) # ๋ฐฐ์ด B๋ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ ์ํ
# ์ฒซ ๋ฒ์งธ ์ธ๋ฑ์ค๋ถํฐ ํ์ธํ๋ฉฐ, ๋ ๋ฐฐ์ด์ ์์๋ฅผ ์ต๋ K๋ฒ ๋น๊ต
for i in range(k):
# A์ ์์๊ฐ B์ ์์๋ณด๋ค ์์ ๊ฒฝ์ฐ
if a[i] < b[i]:
# ๋ ์์๋ฅผ ๊ต์ฒด
a[i], b[i] = b[i], a[i]
else: # A์ ์์๊ฐ B์ ์์๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ ๋, ๋ฐ๋ณต๋ฌธ์ ํ์ถ
break
print(sum(a)) # ๋ฐฐ์ด A์ ๋ชจ๋ ์์์ ํฉ์ ์ถ๋ ฅ