View Code of Problem 3939

#include<iostream>
using namespace std;
int main(){
	int n,q;
	int a[100010];
	while(scanf("%d%d",&n,&q)!=EOF){
		a[0]=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			a[i]+=a[i-1];
		}
		while(q--){
			int l,r;
			scanf("%d%d",&l,&r);
			printf("%d\n",a[r]-a[l-1]);
		}
	}
}

Double click to view unformatted code.


Back to problem 3939