#10025: 為何會RE


kkpp8888 (kkpp)


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main(int argc, char** argv) {
int m,n,l,r,f[1010],a,b,s;
while(scanf("%d %d",&n,&m)!=EOF){
for(a=1;a<=n;a++){
cin>>f[a];
}
for(a=0;a<m;a++){
scanf("%d %d",&l,&r);
for(b=l;b<=r;b++){
s=f[b]+s;
}
printf("%d\n",s);
s=0;
}
}
return 0;
}
#10375: Re:為何會RE


antiquerefer (antiquerefer)


#include
#include
#include
#include
#include
using namespace std;
int main(int argc, char** argv) {
int m,n,l,r,f[1010],a,b,s;
while(scanf("%d %d",&n,&m)!=EOF){
for(a=1;a<=n;a++){
cin>>f[a];
}
for(a=0;a<m;a++){
scanf("%d %d",&l,&r);
for(b=l;b<=r;b++){
s=f[b]+s;
}
printf("%d\n",s);
s=0;
}
}
return 0;
}



f[1010]大小只有1010

但你在存取他的時候卻有可能跑到100000

所以會segement fault