IT/Algorithm

[구름] 절약

BronxBomber 2024. 6. 13. 16:02
728x90

나의 접근 법

"in" 이 들어오면 total_value를 +=1을 해주고, "out"이 들어오면 -=1을 해준다.

다만, 그 반복문을 도는 중에 현재 갖고 있는 금액보다 금액이 더 적어지면 반복문을 종료하고 "fail"을 출력하도록 해주었다.

나의 코드

import sys
user_input = input()
total_value = 0
aaa = int(user_input)
for _ in range(aaa):
	value = input()
	new_value = str(value)
	new_value2 = new_value.split()
	
	if new_value2[0] == "out":
		total_value -= int(new_value2[1])
	else:
		total_value += int(new_value2[1])
	if total_value < 0:
		break
		print("fail")

if total_value <= 0:
	print("fail")
else:
	print("success")