## 661 - Blowing Fuses

Moderator: Board moderators

Frostina
New poster
Posts: 23
Joined: Mon Dec 15, 2003 5:21 am

### 661 - Blowing Fuses

please tell me why... thx ... ^^"

[cpp]
#include <iostream>
using namespace std;
int main() {
long n,m,c,s,i,max;
int t,k=0;
while (cin>>n>>m>>c) {
if (!n&&!m&&!c) break;
int *on = new int[n];
int *power = new int[n];
for (i=0;i<n;i++) {
on = -1;
cin >> power;
}
for (i=0,s=0,max=0;i<m;i++) {
cin >> t;
--t;
on[t] = -on[t];
s+=power[t]*on[t];
if (s>c) break;
if (s>max) max = s;
}
cout << "Sequence " << ++k << endl;
if (s>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;
}
[/cpp]

Ryan Pai
Learning poster
Posts: 67
Joined: Fri Jul 04, 2003 9:59 am
Location: USA
Contact:
Think of a case like this:

Turning on something really powerful.
Turning it right off.

Logically this should blow a weak fuse.

Buffon
New poster
Posts: 2
Joined: Tue May 04, 2004 11:37 am
some features first.

think in your code, you are using 2 vectores, one only to take the signed of an integer..

why dont you take both to one?

Ok, another discusion is to see why you take
long n,m,c,s,i,max;
and your vectors are only INT. what happen if they give you unsigned longs as inputs, your program wont break, but gonna WA.

Another way can be you have one device that suply energy, its means that start from negative number, and only has 1 sequence that turn on that device, this means your max energy consumption will be negative, and you asume that start from zero, then this case will never pass.

im gonna solve this problem, when i get AC or PE i will report to you only i have seen some cases will be exploit.
try to solve myself, later take it part of contest.

Buffon
New poster
Posts: 2
Joined: Tue May 04, 2004 11:37 am
I get AC

sorry but exams get all my time :S
try to solve myself, later take it part of contest.

na5ir_algo
New poster
Posts: 2
Joined: Sat Jul 10, 2004 11:27 am

please tell me what to do. tell me if there is some logical mistake or others mistakes this is code which i have submitted to acm and got WA

[/cpp]
#include <iostream>

using namespace std;

int main(void)
{
int d = 0;
int o = 0;
int c = 0;
int *inarray;
int *farray;
int cap = 0;
int cindex = -1;
int maxcap = 0;
int seq = 0;
int size = 0;

cin>>d>>o>>c;

while(d != 0 || o!= 0 || c != 0)
{
seq++;
size = o+d;
inarray = new int[size];
size = d;
farray = new int[size];
size = o+d;
for(int z=0; z<size; z++)
{
inarray[z] = 0;

if(z < d)
farray[z] = 0;
}

for(int i=0; i<size; i++)
{
cin>>inarray;
if(i >= d)
{
cindex = inarray;

if(farray[cindex-1] == 0)
{
cap += inarray[cindex-1];
farray[cindex-1] = 1;
maxcap = cap;
}
else if(farray[cindex-1] == 1)
{
cap -= inarray[cindex-1];
farray[cindex-1] = 0;
}
}
}

if(cap > c)
{
cout<<"Sequence "<<seq<<endl;
cout<<"Fuse was blown."<<endl;
cout<<endl;
}
else if(cap < c)
{
cout<<"Sequence "<<seq<<endl;
cout<<"Fuse was not blown."<<endl;
cout<<"Maximal power consumption was "<<maxcap<<" amperes."<<endl;
cout<<endl;
}

cap = 0;
cin>>d>>o>>c;
}

return 0;
}
[cpp][/cpp]
-A-S-D-F-G-H-J-K-L-

nasty
New poster
Posts: 4
Joined: Sat Jul 10, 2004 11:27 am
Location: pakistan
yar dr a qadir se contact karoo

majid
New poster
Posts: 3
Joined: Sat Jul 10, 2004 12:17 pm

### i have checked ur program............

yar ek dafa phir Dr A Qadir se se contact karoo

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York
This is an international forum...

If you know English
else
use private message.

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Contact:
sohel wrote:This is an international forum...

If you know English
else
use private message.

I agree.

If you don't let people help you, then should not expect any help form them.

Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Contact:

### 661 - PE

Here's my code....I got PE from OJ!!!! Where's the problem?

Code: Select all

``````spoiler
``````
Last edited by Karthekeyan on Sun Dec 25, 2005 9:47 am, edited 1 time in total.
Karthe

Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET
Problem statement says ->
Output a blank line after each test case.
But your program doesn't print one after the last case.
You should never take more than you give in the circle of life.

Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Contact:
that was rite....thanx!!!!
Karthe

kenneth
New poster
Posts: 24
Joined: Wed Mar 02, 2005 12:29 am

### 661 WA =(

This is a very easy question, but I just can't get it accepted. Can anyone provide any help by either providing some critical input/output or point out where is the problem of my logic? Thanks in advance

Finally Accepted. The problem is I made a mistake by breaking the for loop as soon as the fuse was blown, resulting in the program not reading all the input properly >.<

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Karthekeyan,