• Home
  • About
    • on Weekend photo

      on Weekend

      ๐™Ž๐™ฉ๐™ช๐™™๐™ฎ๐™ž๐™ฃ๐™œ

    • Learn More
    • Instagram
    • Github
  • Archive
    • All Posts
    • All Tags
    • All Categories
  • Categories
    • Problem Solving
    • TIL
    • Study
    • Etc
    • ํ•„์‚ฌ
  • Projects

[๋ฐฑ์ค€] 11256

23 Jan 2021

๋ฐฑ์ค€ 11256

๋ฌธ์ œ ๋งํฌ

์ฝ”๋“œ

import heapq

T = int(input())
for _ in range(T) :
  J, N = map(int, input().split())
  box = []
  for i in range(N) :
    r, c = map(int, input().split())
    heapq.heappush(box, (-1)*(r*c))
  cnt=0
  while(J > 0 ) :
    J -= (-1)*heapq.heappop(box)
    cnt+=1
  print(cnt)

์‰ฌ์šด ๊ทธ๋ฆฌ๋”” ๋ฌธ์ œ์˜€์Šต๋‹ˆ๋‹ค. ๋ฐ•์Šค์˜ ๊ฐ€๋กœ ๊ธธ์ด์™€ ์„ธ๋กœ ๊ธธ์ด๋ฅผ ๊ณฑํ•ด Max heap queue๋กœ ์ €์žฅํ•˜๊ณ , ํฐ ์ €์žฅ์šฉ๋Ÿ‰์˜ ๋ฐ•์Šค๋ถ€ํ„ฐ ๊บผ๋‚ด์„œ ์‚ฌํƒ•์„ ๋„ฃ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.



problem_solvingpython Share Tweet +1