Algorithm 版 (精华区)
发信人: pamws (书虫), 信区: Algorithm
标 题: 1195P-Blowing Fuses-ZJU
发信站: 哈工大紫丁香 (2002年10月09日17:26:24 星期三), 站内信件
Blowing Fuses
----------------------------------------------------------------------------
Time limit: 30 Seconds Memory limit: 32768K
Total Submit: 112 Accepted Submit: 44
----------------------------------------------------------------------------
Maybe you are familiar with the following situation. You have plugged in a l
ot of electrical devices, such as toasters, refrigerators, microwave ovens,
computers, stereos, etc, and have them all running. But at the moment when y
ou turn on the TV, the fuse blows, since the power drawn from all the machin
es is greater than the capacity of the fuse. Of course this is a great safet
y feature, avoiding that houses burn down too often due to fires ignited by
overheating wires. But it is also annoying to walk down to the basement (or
some other inconvenient place) to replace to fuse or switch it back on.
What one would like to have is a program that checks before turning on an el
ectrical device whether the combined power drawn by all running devices exce
eds 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 perform
ed 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 cu
rrently 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. Thi
s test case should not be processed.
Output
For each test case, first output the number of the test case. Then output wh
ether the fuse was blown during the operation sequence. The fuse will be blo
wn if the sum of the power consumptions ci of turned on devices at some poin
t 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.
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.226.228]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.211毫秒