<오답>
import sys
input = sys.stdin.readline
s = int(input())
result = []
for i in range(s+1):
if i <= s:
result.append(i)
s = s-i
print(max(result))
# s의 범위가 커서 시간초과가 나옴
<정답>
import sys
input = sys.stdin.readline
s = int(input())
n = 1
while n*(n+1)/2 <= s:
n+=1
print(n-1)
# 1~n까지 합 구하는 식 : n * (n+1) /2
'문제풀이 > 백준(Boj) 문제풀이' 카테고리의 다른 글
[백준][그리디 알고리즘] 1439. 뒤집기 (파이썬/Python) (0) | 2021.10.03 |
---|---|
[백준][그리디 알고리즘] 2720. 세탁소 사장 동혁 (파이썬/Python) (0) | 2021.10.03 |
[백준][그리디 알고리즘] 1946. 신입 사원(파이썬/Python) (0) | 2021.09.30 |
[백준][그리디 알고리즘] 10162. 전자레인지 (파이썬/Python) (0) | 2021.09.30 |
[백준][그리디 알고리즘] 5585. 거스름돈(파이썬/Python) (0) | 2021.09.30 |