Jack The Lumberjack
InterviewTime limit1sMemory limit1024 MB
Given N tree species that are planted, grow linearly for Y years, then shrink, find the maximum total number of trees alive in any single year.
- Level
Medium5 of 10
- Topics
- Sorting, Simulation, Implementation
- Solved
- No attempts yet
Problem
Jack the Lumberjack used to love chopping down trees. Jack is getting older and is tired of the activity he once loved. He has an idea, 'The Big One', and wants to go into the forest one last time to harvest as many trees as possible.
Jack calls the forest administrator for his local evergreen forest. The administrator explains how the population changes for each tree species. For each species , trees are planted in year . For the next years, the population increases by per year. After years, it decreases by per year until it possibly dies out.
Jack wants to find the maximum number of trees that could be harvested at once, from now until the distant future. If he is no longer around to do it, his descendants will be.
Assume all populations change instantly and at the same time, once per year. Jack assesses each population's size after the yearly change occurs.
Input
The input contains a single test case. The first line contains an integer (), the number of tree species in the forest.
Each of the following lines contains four integers , , , (, , , ). Here is the starting population size, is the year in which the population is planted, and is the number of years during which the population increases by each year before it decreases by each year until it possibly dies out.
Output
Print the maximum number of trees that can be harvested in any single year.