Riding Roller Coasters
Time limit1sMemory limit128 MB
Given N coasters with fun a_i-(k-1)^2*b_i per ride and fixed ride times, answer Q queries for the maximum total fun within each time budget.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Sang-geun and his friends went to an amusement park. The park has many kinds of roller coasters, and Sang-geun has analyzed each one in advance, writing down the fun he feels from riding it as a number. However, the more times he rides the same roller coaster, the less fun it becomes.
Sang-geun defined the fun of riding roller coaster for the -th time as the following function.
If is not positive, riding that roller coaster again gives him no fun at all.
Sang-geun wants to ride roller coasters so that the total fun is maximized. Given the amount of time he can stay in the park, find the maximum total fun he can obtain while the total time spent riding roller coasters does not exceed that time. Riding roller coaster once takes a fixed amount of time.
Input
The first line contains the number of roller coasters . ()
Each of the next lines contains three integers , , and . Here and are the coefficients of the fun function, and is the time it takes to ride roller coaster once. (, )
The next line contains the number of park visits . ()
Each of the next lines contains a time that Sang-geun can stay in the park. ()
Output
Print lines. For each visit time , print on one line the maximum total fun Sang-geun can obtain while the total time spent riding roller coasters does not exceed .