What one would like to have is a program that checks before turning on an electrical device whether the combined power drawn by all running devices exceeds the fuses capacity (and it blows), or whether it is safe to turn it on.

Input

The input consists of several test cases. Each test case describes a set of electrical devices and gives a sequence of turn on/off operations for these devices.

The first line of each test case contains three integers n, m and c, where n is the number of devices (n <= 20), m the number of operations performed on these devices and c is the capacity of the fuse (in Amperes). The following n lines contain one positive integer ci each, the consumption (in Amperes) of the i-th device.

This is followed by m lines also containing one integer each, between 1 and n inclusive. They describe a sequence of turn on/turn off operations performed on the devices. For every number, the state of that particular devices is toggled, i.e. if it is currently running, it is turned off, and if it is currently turned off, it will by switched on. At the beginning all devices are turned off.

The input will be terminated by a test case starting with n = m = c = 0. This test case should not be processed.

Output

For each test case, first output the number of the test case. Then output whether the fuse was blown during the operation sequence. The fuse will be blown if the sum of the power consumptions ci of turned on devices at some point exceeds the capacity of the fuse c.

If the fuse is not blown, output the maximal power consumption by turned on devices that occurred during the sequence.

Output a blank line after each test case.

Sample Input

2 2 10
5
7
1
2
3 6 10
2
5
7
2
1
2
3
1
3
0 0 0

Sample Output

Sequence 1
Fuse was blown.

Sequence 2
Fuse was not blown.

Maximal power consumption was 9 amperes.

题目大意:有一堆电器,给出他们的功率,然后依次对他们进行操作(开或者关,取决于之前状态),判断是否超过保险丝的容量。

分析:定义两个数组分别存电器的功率和他的当前状态,然后模拟每一次操作,当前关,则打开,当前打开,则关掉。

注意格式问题。

#include <stdio.h>
#include<memory.h>
int p[21];//设备功率
int s[21];//status,状态
int main()
{
int a,b,c;
int num=1;
while(scanf("%d %d %d",&a,&b,&c)&&a&&b&&c)
{
int i;
for(i=1;i<=a;i++)
scanf("%d",&p[i]);
memset(s,0,sizeof(s));//很重要!
int sum=0;
int max=0;
for(i=0;i<b;i++)
{
int x;
scanf("%d",&x);
if(s[x])
{
s[x]=0;
sum-=p[x];
}
else
{
s[x]=1;
sum+=p[x];
}
if(max<sum)
max=sum;
}
printf("Sequence %d\n",num++);
if(max>c)
printf("Fuse was blown.\n");
else
{
printf("Fuse was not blown.\n");
printf("Maximal power consumption was %d amperes.\n",max);
}
printf("\n");
}
return 0;
}