#include <stdio.h> long long sum[100001]; int main(){ int N, M, first, last, num; scanf("%d %d", &N, &M); for (int i = 1; i <= N; i++){ scanf("%d", &num); sum[i] = sum[i-1] + num; } while (M--){ scanf("%d %d", &first, &last); printf("%lld\n", sum[last] - sum[first-1]); } } import java.io.*; import java.util.StringTokenizer;
public class 백준_구간합구하기4 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[] input = new int[N + 1];
st = new StringTokenizer(br.readLine());
input[1] = Integer.parseInt(st.nextToken());
for (int i = 2; i <= N; i++) {
input[i] = input[i-1] + Integer.parseInt(st.nextToken());
}
for (int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
bw.write((input[b] - input[a-1]) + "\n");
}
bw.flush();
}
}