๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš€ Development/Problem Solving

[Softeer] ๊ธˆ๊ณ ํ„ธ์ด ํŒŒ์ด์ฌ

by Jay Din 2023. 5. 26.
728x90
๋ฐ˜์‘ํ˜•

https://softeer.ai/practice/info.do?idx=1&eid=395 

 

Softeer

์—ฐ์Šต๋ฌธ์ œ๋ฅผ ๋‹ด์„ Set์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”. ์ทจ์†Œ ํ™•์ธ

softeer.ai

๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ์ •๋ฆฌ

  • ๋ฃจํŒก์€ ๋ฐฐ๋‚ญ์„ ํ•˜๋‚˜ ๋ฉ”๊ณ  ์€ํ–‰๊ธˆ๊ณ ์— ๋“ค์–ด์™”๋‹ค.
  • ๊ธˆ๊ณ  ์•ˆ์—๋Š” ๊ฐ’๋น„์‹ผ ๊ธˆ, ์€, ๋ฐฑ๊ธˆ ๋“ฑ์˜ ๊ท€๊ธˆ์† ๋ฉ์–ด๋ฆฌ๊ฐ€ ์žˆ๋‹ค.
  • ๊ฐ ๊ธˆ์†์˜ ๋ฌด๊ฒŒ์™€ ๋ฌด๊ฒŒ๋‹น ๊ฐ€๊ฒฉ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ ๋ฐฐ๋‚ญ์„ ์ฑ„์šธ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ๊ฐ’๋น„์‹ผ ๊ฐ€๊ฒฉ์„ ๊ตฌํ•˜๋ผ.
  • ๋ฃจํŒก์€ ์ „๋™ํ†ฑ์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ ๊ท€๊ธˆ์†์€ ํ†ฑ์œผ๋กœ ์ž๋ฅด๋ฉด ์ž˜๋ ค์ง„ ๋ถ€๋ถ„์˜ ๋ฌด๊ฒŒ ๋งŒํผ ๊ฐ€์น˜๋ฅผ ๊ฐ€์ง„๋‹ค.

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

์˜ˆ์ œ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์ด ์ฃผ์–ด์ง„๋‹ค.

100 2
90 1
70 2
  • w = 100
  • ๋ณด์„์˜ ๊ฐœ์ˆ˜ = 2
  • 1๋ฒˆ์งธ ๋ณด์„์€ ๋ฌด๊ฒŒ๊ฐ€ 90์ด๊ณ  ๋ฌด๊ฒŒ๋‹น 1๊ฐ’์„ ๊ฐ€์ง„๋‹ค.
  • 2๋ฒˆ์งธ ๋ณด์„์€ ๋ฌด๊ฒŒ๊ฐ€ 70์ด๊ณ  ๋ฌด๊ฒŒ๋‹น 2๊ฐ’์„ ๊ฐ€์ง„๋‹ค.
  1. ๊ฐ€์žฅ ๋น„์‹ผ ๊ฐ’์„ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.
  2. ์ž…๋ ฅ๋ฐ›์€ ๋ณด์„ ๋ฌด๊ฒŒ์™€ ๋ฌด๊ฒŒ๋‹น ๊ฐ€๊ฒฉ์„ ๋ฐฐ์—ด์— ๋„ฃ๋Š”๋‹ค.
  3. ๋ฌด๊ฒŒ๋‹น ๊ฐ€๊ฒฉ์ด ๋น„์‹ผ ์ˆœ์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•œ๋‹ค.
  4. ๋ฌด๊ฒŒ w์™€ ๋ฌด๊ฒŒ๋‹น ๊ฐ€๊ฒฉ์„ ๋น„๊ตํ•˜์—ฌ ์ตœ๋Œ€ ๊ฐ’์„ ๊ตฌํ•œ๋‹ค.

์—ฌ๊ธฐ์„œ ๋ฌด๊ฒŒ๋‹น ๊ฐ€๊ฒฉ์ด๋ผ๋Š” ๊ฒƒ์ด

90 1์ด ์ฃผ์–ด์ง€๋ฉด, ์ด ๋ณด์„์€ 1kg ๋‹น 1์˜ ๊ฐ’์„ ๊ฐ€์ง„๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ 70 2๋Š” 1kg ๋‹น 2์˜ ๊ฐ’์„ ๊ฐ€์ง€๋Š” ๊ฒƒ์ด๋‹ค.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋ฌด๊ฒŒ๋‹น ๊ฐ€๊ฒฉ์ด ๋†’์€ ์ˆœ์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๋ฐ˜์‘ํ˜•

 

๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ๋ณด์„์˜ ์ตœ๋Œ€ ๊ฐ’์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

๋”ฐ๋ผ์„œ ๋ณด์„ 100kg์„ ๋ฐฐ๋‚ญ์— ๋‹ด์„ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ๊ฐ’์€ 170์ด ๋œ๋‹ค.

import sys
input = sys.stdin.readline

# ๋ฌด๊ฒŒ, ๋ณด์„ ๊ฐœ์ˆ˜
w, n = map(int, input().split())
graph = []

for i in range(n):
	# ๋ฌด๊ฒŒ, ๋ฌด๊ฒŒ๋‹น ๊ฐ€๊ฒฉ
	m, p = map(int,input().split())
    graph.append([m,p])

graph = sorted(graph, key=lambda x: -x[1])

answer = 0
# ์ตœ๋Œ€ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ๊ณผ์ •
for i in graph:
    weight = i[0]
    price = i[1]
    if w >= weight:
        answer += weight*price
        w-=weight
    else:
        answer += w*price
        break  

print(answer)

 

 

728x90
๋ฐ˜์‘ํ˜•