BOJ - 17390 - 이건 꼭 풀어야 해!

Updated:

import sys

def solution():
    N, Q = map(int, sys.stdin.readline().split())
    arr = list(map(int, sys.stdin.readline().split()))

    arr.sort()
    dp = [0] * (N+1)

    v = 0
    for i in range(N):
        v  += arr[i]
        dp[i+1] = v

    for _ in range(Q):
        L, R = map(int, sys.stdin.readline().split())
        print(dp[R] - dp[L-1])


solution()

https://www.acmicpc.net/problem/17390

Categories:

Updated:

Leave a comment