A. Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
The Friends of Wetlands have dammed a creek to provide water for the nearby wetlands. During each month some rainwater flows into the dam, and then at the end of each month precisely 10 megalitres of water are released into the wetlands. If the dam contains less than 10 megalitres at the end of the month, the entire contents of the dam are released.
The local firefighters view the dam as a potential source of water to fight bushfires, and would like to know how much water there is likely to be in the dam in the height of the bushfire season in eight months' time. Your task is to use predicted rainfall figures to answer this question.
For example, suppose the predicted amounts of rainwater flowing into the dam for each of the eight months are 12, 9, 10, 7, 10, 13, 9 and 15 megalitres respectively. Assuming these figures are correct, after the first month the dam fills with 12 megalitres, and then 10 megalitres are taken (leaving 2). After the second month the dam fills to 2+9=11 megalitres, which is then reduced to 1. After the third month the dam fills to 11 megalitres and is again reduced to 1.
The fourth month is more interesting--here the dam only fills to 1+7=8 megalitres. Since the usual 10 megalitres cannot be taken, the dam is emptied completely. After the fifth month it fills to 10 and is again emptied, then it fills to 13 and reduces to 3, then fills to 12 and reduces to 2, and finally after the eighth month it fills to 17 and reduces to 7. Therefore your final answer for the firefighters is 7 megalitres.