poj1484

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
using namespace std;

#define maxn 25

int n, m, blow, power[maxn];
bool on[maxn];

void out(int a)
{
int b = m - a - 1;
int x;
for (int i = 0; i < b; i++)
scanf(
"%d", &x);
}

void input()
{
memset(on,
0, sizeof(on));
for (int i = 0; i < n; i++)
scanf(
"%d", &power[i]);
int sum = 0;
int ans = 0;
for (int i = 0; i < m; i++)
{
int a;
scanf(
"%d", &a);
a
--;
if (!on[a])
sum
+= power[a];
else
sum
-= power[a];
on[a]
= !on[a];
ans
= max(ans, sum);
if (sum > blow)
{
out(i);
printf(
"Fuse was blown.\n");
return;
}
}
printf(
"Fuse was not blown.\n");
printf(
"Maximal power consumption was %d amperes.\n", ans);
}

int main()
{
//freopen("t.txt", "r", stdin);
int t = 0;
while (scanf("%d%d%d", &n, &m, &blow), n | m | blow)
{
t
++;
printf(
"Sequence %d\n", t);
input();
putchar(
'\n');
}
return 0;
}

你可能感兴趣的:(poj)