#C8256. Maximum Task Satisfaction

    ID: 52218 Type: Default 1000ms 256MiB

Maximum Task Satisfaction

Maximum Task Satisfaction

This problem is a variation of the classic 0/1 knapsack problem. You are given a list of tasks, where each task requires a certain number of hours to complete and provides a specific satisfaction score. Each task can only be performed once. You will also be given multiple queries where each query represents the total hours available. Your goal is to determine, for each query, the maximum satisfaction points you can accumulate by choosing a subset of tasks such that the total required hours do not exceed the available time.

Formally, if you have n tasks with each task i characterized by its required hours h_i and satisfaction s_i, and a query with H available hours, you need to maximize the total satisfaction. This can be expressed using the dynamic programming recurrence:

dp[H]=max(dp[H], dp[Hhi]+si)dp[H] = \max\left(dp[H],\ dp[H-h_i] + s_i\right)

for all tasks such that h_i ≤ H, processed in reverse order to ensure each task is only used once.

inputFormat

The input is read from standard input and has the following format:

  • The first line contains a single integer n representing the number of tasks.
  • The next n lines each contain two integers: the number of hours required and the satisfaction points for that task.
  • The following line contains an integer q representing the number of queries.
  • The next q lines each contain a single integer representing the available hours for that query.

outputFormat

For each query, output one line containing a single integer: the maximum total satisfaction points that can be achieved without exceeding the available hours for that query.

## sample
3
4 5
3 7
2 10
3
5
6
10
17

17 22

</p>