Skip to content

Commit

Permalink
2024-02-14
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Feb 14, 2024
1 parent 5b540db commit e861d2b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pknujsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
| 30차시 | 2024.01.23 | DP | [ABBC](https://www.acmicpc.net/problem/25381) | [#119](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/119) |
| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) |
| 32차시 | 2024.02.04 | BFS | [숨바꼭질 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) |
| 33차시 | 2024.02.06 || [철로](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/132) |
| 33차시 | 2024.02.06 || [철로](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/132) |
| 34차시 | 2024.02.12 | BFS | [이분 그래프](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/135) |
| 35차시 | 2024.02.14 | 그리디 | [선물할인](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/137) |
36 changes: 36 additions & 0 deletions pknujsp/그리디/35-선물할인.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from sys import *

n, budget, max_sales = map(int, stdin.readline().split())
gifts = sorted(list(map(int, stdin.readline().split())))

min_price_gift = max_price_gift = 0
prices = 0
sales = 0

for sale_gift in range(max_sales):
prices += gifts[sale_gift] // 2
max_price_gift += 1

if prices > budget:
print(sale_gift)
exit()

sales = max_price_gift - min_price_gift
while max_price_gift < n:
if sales < max_sales or max_sales == 0:
if max_sales == 0:
prices += gifts[max_price_gift]
else:
prices += gifts[max_price_gift] // 2

if prices > budget:
break

max_price_gift += 1
sales += 1
else:
prices += gifts[min_price_gift] // 2
min_price_gift += 1
sales -= 1

print(max_price_gift)

0 comments on commit e861d2b

Please sign in to comment.