forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path12.py
17 lines (14 loc) Β· 735 Bytes
/
12.py
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μ λͺ¨λ μμμ ν©μ μΆλ ₯