-
[Greedy]2812알고리즘 2020. 11. 8. 22:34
n,m=map(int,input().split(' ')) x_l=(list(map(int,input()))) #자릿수 : n-m before=0 max_val=0 s='' temp_s=[] cur_p=n-m for idx,i in enumerate(x_l): tt=min((n-m),len(x_l)-idx) if tt!=cur_p: s+=str(temp_s.pop(0)) cur_p=tt while True: if len(temp_s)==0: temp_s.append(i) break if i>temp_s[-1]: temp_s.pop() else: temp_s.append(i) break if len(list(s))!=n-m: s+=str(temp_s.pop(0)) print(s) else: print(s)
거의 3일 묵히면서 풀었다.. 스택을 사용한다는 것이 키!
'알고리즘' 카테고리의 다른 글
[Python]Minheap (0) 2020.11.09 [Dijkstra] 1753 (0) 2020.11.09 [DP]2156 (0) 2020.11.05 [DFS]1987 (0) 2020.11.05 [DP]1915 (0) 2020.10.31