Programming/Algorithm(Python)
[구현] SWEA 1284번 수도 요금 경쟁
code_wizard
2023. 10. 12. 17:37

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV189xUaI8UCFAZN
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
SSAFY 알고리즘 스터디 1번째, 알고리즘 리뷰
# 첫 번째 풀이, if문
T = int(input())
for test_case in range(1, T + 1):
p, q, r, s, w = map(int, input().split())
result = [p*w, 0, 0]
if w > r: # 요금이 임계값을 넘었다면
result[1] = q + s*(w-r)
else: # 넘지 않았다면
result[1] = q
if result[0] < result[1]: # a요금이 더 저렴하다면
result[2] = result[0]
else:
result[2] = result[1]
print("#"+str(test_case), result[2])
# 두 번째 풀이, lambda
T = int(input())
for test_case in range(1, T + 1):
p, q, r, s, w = map(int, input().split())
result = [p*w, 0, 0]
result[1] = q + s * (w - r) if w > r else q
result[2] = (lambda a, b: a if a < b else b)(result[0], result[1])
print("#"+str(test_case), result[2])
# 입력, 출력 예시
입력2
9 100 20 3 10
8 300 100 10 250
출력
#1 90
#2 1800
#2 1800