#27834: CPP


11030067@mail.hpsh.tp.edu.tw (和平110級鄧雨珊)

學校 : 臺北市立和平高級中學
編號 : 163096
來源 : [61.64.210.174]
最後登入時間 :
2022-10-23 16:54:59
c094. 00661 - Blowing Fuses -- UVa661 | From: [203.72.60.244] | 發表日期 : 2021-11-01 11:01

#include <iostream>
using namespace std;

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, c, t=1, x;
while (cin >> n >> m >> c){
if (n+m+c==0){
break;
}
int a[25];
bool on[25]={false};
for (int i=1; i<=n; i++){
cin >> a[i];
}
int sum=0, mx=0;
bool blown=false;
while (m--){
cin >> x;
on[x]=!on[x];
if (on[x]){
sum+=a[x];
}
else {
sum-=a[x];
}
mx=max(mx, sum);
if (sum>c){
blown=true;
}
}
if (t>1){
cout <<"\n";
}
cout <<"Sequence "<< t++ <<endl;
if (blown){
cout <<"Fuse was blown.\n";
}
else {
cout <<"Fuse was not blown.\n";
cout <<"Maximal power consumption was "<< mx <<" amperes.\n";
}
}
}
 
ZeroJudge Forum