💡 오늘의 교훈: 조건을 항상 잘 생각하는 습관을 들이자!!

N, M = map(int, input().split())
cost = []
totalCost = [0] * M
for _ in range(M):
cost.append(int(input()))
sortCost = sorted(cost)
# 달걀 갯수가 사람 수보다 많은 경우
if N >= M:
for i in range(M):
totalCost[i] = sortCost[i] * (M - i)
# 달걀 갯수가 사람 수보다 작은 경우
else:
for j in range((M-N),M):
totalCost[j] = sortCost[j] * (M - j)
print(sortCost[totalCost.index(max(totalCost))], max(totalCost))
💡 파이썬 index()
=> List내에서 값에 대한 index값을 찾을 때 사용한다.
array = [1, 2, 3, 4]
# 결과 값은 2가 나온다
print(array.index(3))
오프라인 코테 스터디 (12/30)
참가 인원: 기우석님
for (int i = 0; i < m; i++) {
if (i >= n)
break;
if (ans < arr[i] * (i + 1)) {
ans = arr[i] * (i + 1);
ans_value = arr[i];
}
}