eolymp
bolt
Try our new interface for solving problems
Məsələlər

Roller coaster fun

Roller coaster fun

Jimmy and his friends like to visit large theme parks. In the current theme park there are many roller coasters which then are categorized by Jimmy. He assigns a fun value to each coaster; however, the fun decreases with each run. More formal: for a specific roller coaster \textbf{i}, Jimmy assigns two fun coefficients \textbf{a_i} and \textbf{b_i}. While riding this roller coaster for the \textbf{k}-th time, Jimmy gains a fun value of \textbf{f(i, k) = a_i-(k-1)^2·b_i}. If \textbf{f(i, k)} is non-positive, riding the roller coaster is no longer funny. Jimmy tries to maximize the total fun until he leaves the park. Can you tell Jimmy how much fun he can gain for a given time? \InputFile The input consists of a single test case. The first line contains the integer \textbf{N}, where \textbf{N} is the amount of different roller coasters in the theme park (\textbf{0} < \textbf{N} ≤ \textbf{100}). The following \textbf{N} lines contain the integers \textbf{a_i}, \textbf{b_i} and \textbf{t_i} where \textbf{a_i} and \textbf{b_i} are the fun coefficients as specified above and \textbf{t_i} is the time for a single ride with the \textbf{i}-th roller coaster (\textbf{0} ≤ \textbf{a_i} ≤ \textbf{1000}; \textbf{0} ≤ \textbf{b_i} ≤ \textbf{1000}; \textbf{0} < \textbf{t_i} ≤ \textbf{25000}). The next line contains a positive integer \textbf{Q} denoting the number of times that Jimmy is visiting the park (\textbf{0} ≤ \textbf{Q} ≤ \textbf{1000}). Each of the following \textbf{Q} lines contains an integral time \textbf{T_i} that Jimmy spends during his \textbf{i}-th visit (\textbf{0} ≤ \textbf{T_i} ≤ \textbf{25000}). \OutputFile For each of the \textbf{Q} possible times, print one line containing the maximal total fun value if Jimmy spends \textbf{T_i} minutes in the theme park.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
2
5 0 5
7 0 7
4
88
5
6
7
Çıxış verilənləri #1
88
5
5
7
Mənbə ACM ICPC German Collegiate Programming Contest 2012