Pages

Saturday, June 2, 2012

661 - Blowing Fuses



//
// main.cpp
// Blowing Fuses
//
// Created by Panks on 23/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <vector>
using namespace std;
int main (int argc, const char * argv[])
{


int n,m,c;
int getit;
int count=0;

int* devpowr=new int[20];
bool* devstat=new bool[20];

cin>>n>>m>>c;
while (n!=0) {
count++;
for (int i=0; i<n; i++) {
cin>>getit;
devpowr[i]=getit;
devstat[i]=false;
}
int total=0,mtotal=0;
int tmp;
for (int i=1; i<=m; i++) {
cin>>tmp;
tmp--;
if(devstat[tmp]==false){
devstat[tmp]=true;
total+=devpowr[tmp];
mtotal=max(mtotal, total);
if(total>c){
cout<<"Sequence "<<count<<"\nFuse was blown.\n\n";
for(int r = i + 1; r <= m; r++) {
cin >> tmp;}

break;
}
}else{
devstat[tmp]=false;
total-=devpowr[tmp];
}

if(i==m){
cout<<"Sequence "<<count<<"\nFuse was not blown.\nMaximal power consumption was "<<mtotal<<" amperes.\n\n";
break;
}
}
cin>>n>>m>>c;
}
return 0;
}


No comments:

Post a Comment