UVa 661 - Blowing Fuses
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define high 25
typedef map<int, bool>mpib;
int consumtion[high];
int main()
{
fast;
int n , m , c , tc=0 , i=0 , x , maxi=-1 , power=0;
mpib mp;
while(cin >> n >> m >> c)
{
if(!n and !m and !c) break;
mp.clear();
maxi = -1;
power = 0;
bool flown = false;
for(i=1; i<=n; i++)
{
cin >> consumtion[i];
}
for(i=0; i<m; i++)
{
cin >> x;
if(!mp[x])
{
mp[x] = true;
power+=consumtion[x];
}
else
{
mp[x] = false;
power -= consumtion[x];
}
maxi = max(power, maxi);
if(power > c) flown = true;
}
cout << "Sequence " << ++tc << "\n";
if(flown)
{
cout << "Fuse was blown.\n\n";
}
else
{
cout << "Fuse was not blown.\nMaximal power consumption was " << maxi << " amperes.\n\n";
}
}
return 0;
}
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define high 25
typedef map<int, bool>mpib;
int consumtion[high];
int main()
{
fast;
int n , m , c , tc=0 , i=0 , x , maxi=-1 , power=0;
mpib mp;
while(cin >> n >> m >> c)
{
if(!n and !m and !c) break;
mp.clear();
maxi = -1;
power = 0;
bool flown = false;
for(i=1; i<=n; i++)
{
cin >> consumtion[i];
}
for(i=0; i<m; i++)
{
cin >> x;
if(!mp[x])
{
mp[x] = true;
power+=consumtion[x];
}
else
{
mp[x] = false;
power -= consumtion[x];
}
maxi = max(power, maxi);
if(power > c) flown = true;
}
cout << "Sequence " << ++tc << "\n";
if(flown)
{
cout << "Fuse was blown.\n\n";
}
else
{
cout << "Fuse was not blown.\nMaximal power consumption was " << maxi << " amperes.\n\n";
}
}
return 0;
}
Comments
Post a Comment