-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva661.cpp
More file actions
78 lines (71 loc) · 1.93 KB
/
Copy pathUva661.cpp
File metadata and controls
78 lines (71 loc) · 1.93 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
typedef pair<string,int> si;
int main()
{
int numberOfDevices;
int numberOfOperations;
int capacityOfFuse;
int seq=0;
while(true){
scanf("%d %d %d",&numberOfDevices,&numberOfOperations,&capacityOfFuse);
if(numberOfDevices==0 && numberOfOperations==0 && capacityOfFuse==0)break;
seq++;
vector<int> IndexInAmpers;
int consAmper;
int copyNumber=numberOfDevices;
while(copyNumber--){
scanf("%d",&consAmper);
IndexInAmpers.push_back(consAmper);
}
int num;
int numCopy=numberOfOperations;
vector<int> sequence;
while(numCopy--){
scanf("%d",&num);
sequence.push_back(num);
}
bool used[numberOfDevices];
for(int i=0;i<numberOfDevices;i++)used[i]=false;
int max=0;
vector<int> indexes;
for(int i=0;i<sequence.size();i++){
int num=sequence[i]-1;
if(!used[num]){
used[num]=true;
indexes.push_back(num);
}
else{
used[num]=false;
indexes.erase(remove(indexes.begin(),indexes.end(),num),indexes.end());
}
int curr=0;
for(int j=0;j<indexes.size();j++){
curr+=IndexInAmpers[indexes[j]];
}
if(curr>max){
max=curr;
}
}
cout<<"Sequence "<<seq<<endl;
if(max>capacityOfFuse){
cout<<"Fuse was blown."<<endl;
}
else{
cout<<"Fuse was not blown."<<endl;
cout<<"Maximal power consumption was "<<max<<" amperes."<<endl;
}
cout<<endl;
}
return 0;
}