各位好,我的程式碼可以跑得過範例
但是送出時卻出現RE(記憶體區段錯誤)
可以請各位幫幫我嗎?
這是我的程式碼:
#include<iostream>
using namespace std;
int main() {
int n,m,c,count=0;
while(cin>>n>>m>>c){
if(n==0)
break;
count++;
cout<<"Sequence "<<count<<endl;
int power[n+1],on[n+1],temp,total,max=0;
for(int i=1;i<=n;i++)
cin>>power[i];
for(int i=1;i<=n;i++)
on[i]=0;
for(int i=1;i<=m;i++){
total=0;
cin>>temp;
if(on[temp]==0)
on[temp]=1;
else
on[temp]=0;
for(int j=1;j<=n;j++)
total+=power[j]*on[j];
if(max<=total)
max=total;
if(total>c){
cout<<"Fuse was blown.\n\n";
break;
}
}
if(total<=c)
cout<<"Fuse was not blown.\nMaximal power consumption was "<<max<<" amperes.\n\n";
}
return 0;
}