Skip to content

Commit

Permalink
[Silver III] Title: 최고의 피자, Time: 32 ms, Memory: 31120 KB -BaekjoonHub
Browse files Browse the repository at this point in the history
  • Loading branch information
alswo1212 committed Sep 3, 2024
1 parent 6273b95 commit 77fa3a2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 백준/Silver/5545. 최고의 피자/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# [Silver III] 최고의 피자 - 5545

[문제 링크](https://www.acmicpc.net/problem/5545)

### 성능 요약

메모리: 31120 KB, 시간: 32 ms

### 분류

그리디 알고리즘, 정렬

### 제출 일자

2024년 9월 3일 23:31:44

### 문제 설명

<p>상근이는 근처 피자 가게에서 매일 저녁으로 피자를 배달해 먹는다. 주머니 사정이 얇아진 상근이는 이번 달부터는 "최고의 피자"를 구매하려고 한다. 최고의 피자란, 피자 가게에서 주문할 수 있는 피자 중 1원당 열량이 가장 높은 피자를 말한다. 최고의 피자는 여러 종류가 있을 수도 있다.</p>

<p>이 피자 가게는 토핑 N개에서 여러 종류를 선택해서 주문할 수 있다. 같은 종류의 토핑을 2개 이상 선택할 수는 없다. 또, 토핑을 전혀 선택하지 않을 수도 있다.</p>

<p>선택한 토핑은 도우 위에 올라간다. 도우의 가격은 A원이고, 토핑의 가격은 모두 B원이다. 피자의 가격은 도우와 토핑의 가격의 합계가 된다. 즉, 토핑을 k종류 (0 ≤ k ≤ N) 선택했다면, 피자의 가격은 A + B*k원이 된다. 피자의 열량은 도우와 토핑의 열량의 합이다.</p>

<p>도우의 가격, 토핑의 가격, 그리고 도우와 각 토핑의 열량 값이 주어졌을 때, 최고의 피자의 1원 당 열량을 구하는 프로그램을 작성하시오.</p>

### 입력

<p>첫째 줄에 토핑의 종류의 수 N(1 ≤ N ≤ 100)이 주어진다. 둘째 줄에는 도우의 가격 A와 토핑의 가격 B가 주어진다. (1 ≤ A, B ≤ 1000) 셋째 줄에는 도우의 열량 C가 주어진다. (1 ≤ C ≤ 10000) 다음 줄부터 N개 줄에는 각 토핑의 열량 D<sub>i</sub>가 한 줄에 하나씩 주어진다. (1 ≤ D<sub>i</sub> ≤ 10000)</p>

### 출력

<p>첫째 줄에 최고의 피자의 1원 당 열량을 출력한다. 소수점 이하는 버리고 정수 값으로 출력한다.</p>

22 changes: 22 additions & 0 deletions 백준/Silver/5545. 최고의 피자/최고의 피자.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
input = sys.stdin.readline

N = int(input())
A, B = map(int, input().split())
C = int(input())

arr = [int(input()) for _ in range(N)]
arr.sort(key=lambda n : -n)
max_cal = C // A

cur_cal = C
for i in range(N):
cur_cal += arr[i]
cost = A + B * (i+1)
calc_cal = cur_cal // cost
if max_cal <= calc_cal:
max_cal = calc_cal
else:
break

print(max_cal)

0 comments on commit 77fa3a2

Please sign in to comment.