-
Notifications
You must be signed in to change notification settings - Fork 0
/
661 - Blowing Fuses.cpp
49 lines (42 loc) · 1.08 KB
/
661 - Blowing Fuses.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
using namespace std;
int main()
{
int n, m, c, counter = 1;
while(cin>>n>>m>>c)
{
if(n == 0)
return 0;
int devices[n], toggle[n], sum = 0, operation, max = 0;
for(int i=0; i<n; i++)
{
cin>>devices[i];
toggle[i] = 0;
}
for(int i=0; i<m; i++)
{
cin>>operation;
if(toggle[operation-1] == 0)
{
toggle[operation-1] = 1;
sum += devices[operation-1];
if(sum > max)
max = sum;
}
else
{
toggle[operation-1] = 0;
sum -= devices[operation-1];
}
}
cout<<"Sequence "<<counter++<<endl;
if(max > c)
cout<<"Fuse was blown."<<endl<<endl;
else
{
cout<<"Fuse was not blown."<<endl;
cout<<"Maximal power consumption was "<<max<<" amperes."<<endl<<endl;
}
}
return 0;
}