728x90
문제
6081번: Hay Expenses
Every day Farmer John feeds the cows a lavish meal of premium gourmet hay. He then records the number of bales on the next line of his expense notebook. When tax time comes, FJ realizes that he neglected to record the dates for the hay feedings. He must ca
www.acmicpc.net

풀이
N과 Q를 입력받은 다음, N일 동안의 건초 더미 수를 입력받습니다.
그 후, 각 쿼리에 대해 시작 인덱스 start와 끝 인덱스 end를 입력받아 해당 범위의 건초 더미 합을 계산하고 출력합니다.
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
hay_bales = [int(input()) for _ in range(N)]
for _ in range(Q):
start, end = map(int, input().split()) # 쿼리의 시작과 끝 인덱스를 입력받음
print(sum(hay_bales[start-1:end])) # 해당 범위의 건초 더미 합을 계산하여 출력
728x90