#include<iostream>
using namespace std;
int main()
{
int n=0 , m=0 , c=0 ;
int a[2][1000] , i=0;
int record;
int j=0;
while(cin>>n>>m>>c)
{
j++;
if(n==0 && m==0 && c==0)
{
return 0;
}
long long int sum=0;
long long int max=0;
for(i=1;i<=n;i++)
{
cin>>a[0][i];
a[1][i]=0;
}
for(i=0;i<m;i++)
{
cin>>record;
if(a[1][record]==0)
{
sum+=a[0][record];
a[1][record]=1;
}
else
{
sum-=a[0][record];
a[1][record]=0;
}
if(sum>c)
{
max=-1;
break;
}
if(sum>=max)
{
max=sum;
}
}
/*if(j==24)
{
max=121;
}*/
cout<<"Sequence "<<j<<endl;
if(max!=-1)
{
cout<<"Fuse was not blown."<<endl<<"Maximal power consumption was "<<max<<" amperes."<<endl<<endl;
}
else
{
cout<<"Fuse was blown."<<endl<<endl;
}
}
//system("pause");
return 0;
}
程式碼如上
line24 電流最大值是121
但是我的答案總是0(甚至加了註解那行也是0)
請高手指點迷津