【ZhengQing】[1724]candy

Problem Description

Loading...

Problem Analysis

For the level back then
the English statement was still a bit hard to grasp…
But still…
after comparing the input and output I got it
it’s really just finding the total number of candies in a given interval
and this counts as a precomputed-table approach~

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
#include<string.h>
int a[100000];
int main() {
	int T,n,k,x,y;
	int i;
	scanf("%d",&T);
	while(T--) {
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		for(i=1,a[0]=0; i<=n; i++) {
			scanf("%d",&a[i]);
			a[i]+=a[i-1];
		}
		scanf("%d",&k);
		while(k--) {
			scanf("%d %d",&x,&y);
			printf("%d\n",a[y]-a[x-1]);
		}
	}
	return 0;
}

Problem link: ZZULI 1724 candy

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...