본문 바로가기
Algorithm/Implementaion

[백준] 11659번 구간 합 구하기 4

by 등촌동 꼬북이 2020. 12. 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])

'Algorithm > Implementaion' 카테고리의 다른 글

[백준] 1357 뒤집힌 덧셈  (0) 2020.11.30
[백준] 1417번 국회의원 선거  (0) 2020.11.28
[백준] 11286번 절대값 힙  (0) 2020.11.26
[백준] 1913번 달팽이  (0) 2020.11.26
[백준] 1032번 명령 프롬프트  (0) 2020.11.25

댓글