Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ByteAurora/20230727/1450.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from bisect import bisect_right


def get_possible_cases(weights):
cases = [0]
for i in weights:
for j in range(len(cases)):
cases.append(cases[j] + i)
return cases


def get_possible_grouping_count(item_count, bag_size, weights):
weight_group1 = weights[:item_count // 2]
weight_group2 = weights[item_count // 2:]

group1_cases = get_possible_cases(weight_group1)
group2_cases = get_possible_cases(weight_group2)

group2_cases.sort()

result = 0
for group1_case in group1_cases:
if bag_size - group1_case >= 0:
result += bisect_right(group2_cases, bag_size - group1_case)

return result


N, C = map(int, input().split())
weights = list(map(int, input().split()))

print(get_possible_grouping_count(N, C, weights))
20 changes: 20 additions & 0 deletions ByteAurora/20230810/138476.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def solution(k, tangerine):
answer = 0
mandarins = {}

for size in tangerine:
if size in mandarins:
mandarins[size] += 1
else:
mandarins[size] = 1

selected_count = 0

for size, count in sorted(mandarins.items(), key=lambda x: x[1], reverse=True):
selected_count += count
answer += 1

if selected_count >= k:
break

return answer
50 changes: 50 additions & 0 deletions ByteAurora/20230810/150368.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
29 changes: 29 additions & 0 deletions ByteAurora/20230810/154539.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 아래는 처음 풀었던 방법
# def find_nearest_big_number(numbers):
# for number in numbers[1:]:
# if numbers[0] < number:
# return number
#
# return -1
#
#
# def solution(numbers):
# answer = []
#
# for idx in range(len(numbers)):
# answer.append(find_nearest_big_number(numbers[idx:]))
#
# return answer

# 스택을 이용하여 푼 방법
def solution(numbers):
answer = [-1 for _ in range(len(numbers))]
stack = []

for idx, number in enumerate(numbers):
while stack and number > numbers[stack[-1]]: # 스택이 비어있지 않고, 현재 숫자가 스택의 마지막 숫자보다 큰 경우
answer[stack.pop()] = number

stack.append(idx)

return answer
48 changes: 48 additions & 0 deletions ByteAurora/20230810/92342.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
score_board_size = 10


def get_ryan_hit_combinations(arrow_count, length=score_board_size + 1):
if length == 1:
return [[arrow_count]]

ryan_hit_combinations = []

for i in range(arrow_count + 1):
for combination in get_ryan_hit_combinations(arrow_count - i, length - 1):
ryan_hit_combinations.append([i] + combination)

return ryan_hit_combinations


def check_ryan_win(apeach_target_hits, ryan_target_hits):
apeach_score = 0
ryan_score = 0

for idx in range(0, score_board_size + 1):
score = score_board_size - idx
if apeach_target_hits[score] == 0 and ryan_target_hits[score] == 0:
continue
elif apeach_target_hits[score] >= ryan_target_hits[score]:
apeach_score += (score_board_size - score)
elif apeach_target_hits[score] < ryan_target_hits[score]:
ryan_score += (score_board_size - score)

return ryan_score - apeach_score


def solution(n, info):
answer = [-1]
best_score_diff = -1

for ryan_target_hits in get_ryan_hit_combinations(n):
score_diff = check_ryan_win(info, ryan_target_hits)

if score_diff > 0:
if score_diff > best_score_diff:
answer = ryan_target_hits
best_score_diff = score_diff
elif score_diff == best_score_diff:
if ''.join(map(str, answer)) > ''.join(map(str, ryan_target_hits)):
answer = ryan_target_hits

return answer