회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
틀린 이유를 모르겠어요
5710번 - 전기 요금
icelattebest
1년 전
0
제발 살려주세요
import sys input = sys.stdin.readline def solution(): def tcost_to_tpower(total_cost): if total_cost <= 200: return total_cost // 2 elif total_cost <= 29_900: return (total_cost - 200) // 3 + 100 elif total_cost <= 4_949_900: return (total_cost - 29_900) // 5 + 10_000 else: return (total_cost - 4_949_900) // 7 + 1_000_000 def cost(power): if power <= 100: return power * 2 elif power <= 10_000: return 100 * 2 + (power - 100) * 3 elif power <= 1_000_000: return 100 * 2 + 9_900 * 3 + (power - 10_000) * 5 else: return 100 * 2 + 9_900 * 3 + 990_000 * 5 + (power - 1_000_000) * 7 while True: A, B = map(int, input().strip().split()) if A == 0 and B == 0: break total_power = tcost_to_tpower(A) left, right = 0, total_power result = 0 while left <= right: my = (left + right) // 2 neighbor = total_power - my my_cost = cost(my) neighbor_cost = cost(neighbor) diff = neighbor_cost - my_cost if diff == B: result = my_cost break elif diff > B: left = my + 1 else: right = my - 1 print(result) solution()
댓글을 작성하려면
로그인
해야 합니다.
icelattebest 1년 전
제발 살려주세요