Algorithm/Implementaion20 [백준] 11659번 구간 합 구하기 4 import sys N, M = map(int, sys.stdin.readline().split()) inputData = list(map(int, sys.stdin.readline().split())) ans = [inputData[0]] for i in range(1, N): ans.append(ans[i - 1] + inputData[i]) for i in range(M): x, y = map(int, sys.stdin.readline().split()) if x == 1: print(ans[y - 1]) else: print(ans[y - 1] - ans[x - 2]) 2020. 12. 4. [백준] 1357 뒤집힌 덧셈 변수를 거꾸로 하는 변수명[::-1]를 사용하면 쉬움 x, y = map(str, input().split()) print(int(str(int(x[::-1]) + int(y[::-1]))[::-1])) 2020. 11. 30. [백준] 1417번 국회의원 선거 쉬운 문제.. N = int(input()) if N == 1: print(0) else: votes = [] for i in range(N): votes.append(int(input())) pick = votes.pop(0) votes = sorted(votes, reverse=True) ans = 0 while True: if pick > max(votes): break votes[0] -= 1 pick += 1 votes = sorted(votes, reverse=True) ans += 1 print(ans) 2020. 11. 28. [백준] 11286번 절대값 힙 예전에 풀었던 우선순위큐를 이용하면 금방 풀 수 있는 문제 import sys import heapq heap = [] size = 0 for _ in range(int(sys.stdin.readline())): N = int(sys.stdin.readline()) if N != 0: heapq.heappush(heap, (abs(N), N)) size += 1 else: if size == 0: print(0) else: print(heapq.heappop(heap)[1]) size -= 1 2020. 11. 26. 이전 1 2 3 4 5 다음