-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path150368.py
More file actions
50 lines (35 loc) · 2.12 KB
/
150368.py
File metadata and controls
50 lines (35 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from itertools import product
possible_discounts = [10, 20, 30, 40]
def calculate_subscription_revenue(users, emoticons, discounts):
# 각 이모티콘의 할인된 가격 계산
discounted_prices = [(1 - discounts[i] * 0.01) * emoticons[i] for i in range(len(emoticons))]
total_sales = 0
subscribe_count = 0
for user in users: # 모든 사용자에 대해 현재 할인 비율을 적용했을 때의 구독자 수와 매출 계산
min_discount_rate, max_spendable_amount = user
discounted_total_emoticon_cost = 0
for idx in range(len(emoticons)):
if discounts[idx] >= min_discount_rate:
# 할인율이 사용자의 최소 요구 할인율보다 큰거나 같은 경우
discounted_total_emoticon_cost += discounted_prices[idx]
if discounted_total_emoticon_cost >= max_spendable_amount:
# 할인된 이모티콘 전체 가격이 사용자의 최대 구매 가능 금액보다 크거나 같은 경우
# => 서비스 구독
subscribe_count += 1
else:
# 할인된 이모티콘 전체 가격이 사용자의 최대 구매 가능 금액보다 작은 경우
# => 할인된 이모티콘 구매
total_sales += discounted_total_emoticon_cost
return subscribe_count, total_sales
def search_best_discount(users, emoticons):
best_subscribe_count = -1
best_sales = -1
for discounts in product(possible_discounts, repeat=len(emoticons)): # 가능한 할인율을 각각의 이모티콘에 적용
current_subscribe_count, current_sales = calculate_subscription_revenue(users, emoticons, discounts)
if current_subscribe_count > best_subscribe_count or (
current_subscribe_count == best_subscribe_count and current_sales > best_sales):
# 구독자 수가 더 많거나, 구독자 수가 같은 경우 매출이 더 큰 경우
best_subscribe_count, best_sales = current_subscribe_count, current_sales
return [best_subscribe_count, best_sales]
def solution(users, emoticons):
return search_best_discount(users, emoticons)