알고리즘/백준
[백준] 1246번 : 온라인 판매
bigkwangs
2023. 10. 18. 00:09
728x90
해당 문제는 완전탐색으로 문제를 해결하였습니다. N^2 의 시간복잡도로 모든 경우의수를 확인하여 문제를 해결 할 수 있습니다. 달걀의 가격을 한번씩 모두 정해보면서 N개의 달걀이 넘지 않으면서 계산한 값의 합 중에서 가장 큰 값을 찾으면 됩니다.
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
P = []
for _ in range(M):
P.append(int(input()))
P.sort()
ans = 0
maxcost = 0
for pr in P:
cnt = 0
for pr2 in reversed(P):
if pr2 >= pr:
cnt += 1
if N >= cnt:
if cnt * pr > maxcost:
maxcost = cnt * pr
ans = pr
print(ans, maxcost)
728x90