{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"Maybe you are familiar with the following situation. You have plugged in a lot \nof electrical devices, such as toasters, refrigerators, microwave ovens, computers, \nstereos, etc, and have them all running. But at the moment when you turn on the \nTV, the fuse blows, since the power drawn from all the machines is greater than \nthe capacity of the fuse. Of course this is a great safety feature, avoiding that \nhouses burn down too often due to fires ignited by overheating wires. But it is \nalso annoying to walk down to the basement (or some other inconvenient place) \nto replace to fuse or switch it back on. \n\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eWhat one would like to have is a program that checks before turning on an electrical \n device whether the combined power drawn by all running devices exceeds the fuses \n capacity (and it blows), or whether it is safe to turn it on. \u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eInput\u003c/b\u003e\u003cbr\u003e\n \u003cbr\u003e\n The input consists of several test cases. Each test case describes a set of \n electrical devices and gives a sequence of turn on/off operations for these \n devices. \u003c/p\u003e\n\u003cp\u003e The first line of each test case contains three integers n, m and c, where \n n is the number of devices (n \u0026lt;\u003d 20), m the number of operations performed \n on these devices and c is the capacity of the fuse (in Amperes). The following \n n lines contain one positive integer ci each, the consumption (in Amperes) of \n the i-th device. \u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eThis is followed by m lines also containing one integer each, between 1 and \n n inclusive. They describe a sequence of turn on/turn off operations performed \n on the devices. For every number, the state of that particular devices is toggled, \n i.e. if it is currently running, it is turned off, and if it is currently turned \n off, it will by switched on. At the beginning all devices are turned off. \u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eThe input will be terminated by a test case starting with n \u003d m \u003d c \u003d 0. This \n test case should not be processed. \u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eOutput\u003c/b\u003e\u003cbr\u003e\n \u003cbr\u003e\n For each test case, first output the number of the test case. Then output whether \n the fuse was blown during the operation sequence. The fuse will be blown if \n the sum of the power consumptions ci of turned on devices at some point exceeds \n the capacity of the fuse c. \u003c/p\u003e\n\u003cp\u003e If the fuse is not blown, output the maximal power consumption by turned on \n devices that occurred during the sequence. \u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eOutput a blank line after each test case. \u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eSample Input \u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e2 2 10\u003cbr\u003e\n 5\u003cbr\u003e\n 7\u003cbr\u003e\n 1\u003cbr\u003e\n 2\u003cbr\u003e\n 3 6 10\u003cbr\u003e\n 2\u003cbr\u003e\n 5\u003cbr\u003e\n 7\u003cbr\u003e\n 2\u003cbr\u003e\n 1\u003cbr\u003e\n 2\u003cbr\u003e\n 3\u003cbr\u003e\n 1\u003cbr\u003e\n 3\u003cbr\u003e\n 0 0 0\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eSample Output\u003c/b\u003e\u003cbr\u003e\n \u003cbr\u003e\n Sequence 1\u003cbr\u003e\n Fuse was blown.\u003c/p\u003e\n\u003cp\u003eSequence 2\u003cbr\u003e\n Fuse was not blown.\u003cbr\u003e\n Maximal power consumption was 9 amperes.\u003cbr\u003e\n\u003c/p\u003e"}}]}