hi jaeneee
baekjoon(1049-기타줄 )_ python 본문
1) 문제
2) 예시
3) 제출
import sys
input = sys.stdin.readline
# n = 끊어진 기타줄 개수, m = 기타줄 브랜드 개수 입력받기
n, m = map(int, input().split())
# 첫 번째 브랜드의 패키지와 낱개 가격 입력 받기
sixPrice, onePrice = map(int, input().split())
# 2~m까지의 브랜드 가격을 tmp로 입력받고 최솟값을 각 가격에 저장
for i in range(1, m):
tmp1, tmp2 = map(int, input().split())
sixPrice, onePrice = min(sixPrice, tmp1), min(onePrice, tmp2)
# 낱개보다 패키지로 사는 것이 더 쌀 경우
if sixPrice <= onePrice * 6:
res = (sixPrice * (n // 6) + onePrice * (n % 6))
# 낱개까지 패키지로 사는 경우
if sixPrice < onePrice * (n % 6):
res = (sixPrice * (n//6 + 1))
# 패키지보다 낱개로 사는 경우
else:
res = (onePrice * n)
print(res)
4) 메모리/시간/코드길이
5) PLUS
총 네 번 시도했다,,,
문제점은
패키지가 당연히 낱개보다 쌀 것이라는 생각,,
그래서 낱개만 사는 경우는 고려하지 않았다,,
구글링 답지를 보면 다들 리스트에 저장해서 작은 값을 출력했다.
하지만 입력받을 때마다 작은 값을 sixPrice와 onePrice에 각각 저장했다.
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
sixPrice, onePrice = map(int, input().split())
for i in range(1, m):
tmp1, tmp2 = map(int, input().split())
sixPrice, onePrice = min(sixPrice, tmp1), min(onePrice, tmp2)
if sixPrice <= onePrice * 6:
print(min((sixPrice * (n // 6) + onePrice * (n % 6)), (sixPrice * (n//6 + 1))))
else:
print(onePrice * n)
이렇게 하면 안쪽에 있는 if 문도 없애고 바로 출력해서 더 간단해진다.
'알고리즘 > baekjoon' 카테고리의 다른 글
baekjoon(1158-요세푸스 문제)_ python (0) | 2022.05.24 |
---|---|
baekjoon(1120-문자열)_ python (0) | 2022.05.22 |
baekjoon(15596-정수 N개의 합)_ python (0) | 2022.05.18 |
baekjoon(1010-다리놓기)_ python (0) | 2022.05.16 |
baekjoon(1094-막대기)_ python (0) | 2022.05.15 |
Comments