๋ฐฑ์ค 1461. ๋์๊ด - ๊ณจ๋IV
๋ฌธ์ ์ค๋ช
์ผ์ง์ ์ขํ๊ฐ ์๊ณ , 0 ์์น์ ์ด์ง๋ฌ์ง ์ฑ ๋ค์ ๊ฐ๊ฐ ์๋ ์๋ฆฌ์ ๊ฐ์ ธ๋ค ๋ฌ์ผ ํ๋๋ฐ ์ต์ํ์ผ๋ก ์์ง์ฌ์ผ ํ๊ณ , ์ต์ํ์ ๊ฑฐ๋ฆฌ๋ฅผ ์ถ๋ ฅํ๋ ๋ฌธ์
- ํ์ฌ ์์น: 0
- ํ๋ฒ์ m๊ถ
ํ์ด์ฌ ์ฝ๋
n, m = map(int, input().split())
books = list(map(int, input().split()))
pos_li = []
neg_li = []
furthest = 0
result = 0
for book in books:
furthest = max(abs(book), furthest)
if book > 0:
pos_li.append(book)
else:
neg_li.append(abs(book))
pos_li.sort(reverse=1)
neg_li.sort(reverse=1)
for i in range(0, len(pos_li), m):
result += pos_li[i] * 2
for i in range(0, len(neg_li), m):
result += neg_li[i] * 2
print(result - furthest)
'์๊ณ ๋ฆฌ์ฆ ๐ > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 9095. 1, 2, 3 ๋ํ๊ธฐ | ํ์ด์ฌ (0) | 2024.07.19 |
---|---|
[๋ฐฑ์ค] 11048. ์ด๋ํ๊ธฐ | ํ์ด์ฌ (0) | 2024.07.19 |
[๋ฐฑ์ค] 1149. RGB๊ฑฐ๋ฆฌ | ํ์ด์ฌ (0) | 2024.07.19 |
[๋ฐฑ์ค] 9251. LCS | ํ์ด์ฌ (0) | 2024.07.19 |
[๋ฐฑ์ค] 2579. ๊ณ๋จ ์ค๋ฅด๊ธฐ | ํ์ด์ฌ (0) | 2024.07.18 |