TopcoderARCHIVE
Archive/Problems/SunShroom
SRM · Problem 17218

SunShroom

Problem statement, definition, constraints, and public examples.

Problem Statement

A Sun-shroom is a mushroom in the Plants vs. Zombies game. When you plant a Sun-shroom, it starts its life as a small mushroom. After two minutes have passed, the Sun-shroom instantly grows to a full-sized mushroom.

While the Sun-shroom is small, it produces 15 sun every 24 seconds. (A "sun" is a unit of currency in the game.) Once it's fully grown, it produces 25 sun every 24 seconds instead.

The first time a Sun-shroom produces sun is 24 seconds after it was planted. At two minutes into its life the shroom first grows and only then produces sun, so the produced amount is 25 sun.


You are given a long[] plantingTime. Each element of plantingTime is a time in seconds (counting from the beginning of the game) when you planted one mushroom.

You are also given a long queryTime (in the same units).

Calculate and return the total amount of sun produced by your shrooms during the first queryTime seconds of the game.

Definition

Class:
SunShroom
Method:
produceSun
Parameters:
long[], long
Returns:
long
Method signature:
long produceSun(long[] plantingTime, long queryTime)
(be sure your method is public)

Notes

  • In the actual game you have to purchase the Sun-shrooms before you plant them. In this problem we do not care about these costs.

Constraints

  • plantingTime will have between 1 and 50 elements, inclusive.
  • Each element of plantingTime will be between 0 and 10^12, inclusive.
  • queryTime will be between 1 and 10^12, inclusive.

Examples

  1. {10}
    33
    Returns: 0
    Ten seconds into the game you planted your only shroom. Then you waited for 23 more seconds, but the shroom hasn't produced any sun yet.
  2. {10}
    34
    Returns: 15
    This time you waited one more second and you were rewarded by the first batch of sun produced by the shroom.
  3. {47}
    200
    Returns: 110
    This shroom had enough time to mature and produce its first two bigger batches of sun.
  4. {47, 47, 47, 47, 47, 47}
    200
    Returns: 660
    The same test case as above, but you have planted six shrooms at the same time.
  5. {10, 100, 20, 200, 30, 300, 40, 400}
    123456
    Returns: 1027230
← All problems