https://www.acmicpc.net/problem/17390
Python Code
연속된 합을 구해놓고 빼주면 된다.
import sys
N, Q = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
A = sorted(A)
for i in range(1, len(A)):
A[i] = A[i] + A[i-1]
for _ in range(Q):
L, R = map(int, sys.stdin.readline().split())
if L == 1:
print(A[R-1])
else:
print(A[R-1] - A[L-2])
'Programming [Python] > 백준 알고리즘 솔루션' 카테고리의 다른 글
#243 백준 파이썬 [11655] ROT13 (0) | 2019.12.02 |
---|---|
#242 백준 파이썬 [10992] 별 찍기 - 17 (0) | 2019.12.02 |
#240 백준 파이썬 [17389] 보너스 점수 (0) | 2019.12.02 |
#239 백준 파이썬 [9325] 얼마? (0) | 2019.12.01 |
#238 백준 파이썬 [16395] 파스칼의 삼각형 (0) | 2019.12.01 |