본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 11441번 합 구하기

by 현장 2022. 5. 7.

-Code

from sys import stdin
input = stdin.readline()
n = int(input())
nums = list(map(int, input().split()))
m = int(input())
temp = [0]
for i in range(n):
    temp.append(temp[i] + nums[i])

for _ in range(m):
    a, b = map(int, input().split())
    print(temp[b] - temp[a - 1])