#C7504. Calculate Rewards
Calculate Rewards
Calculate Rewards
You are given several test cases. Each test case consists of a set of programming problems and a series of days. For each day, you need to compute the total reward points available by summing up the reward points of problems whose difficulty level does not exceed the maximum difficulty limit set for that day.
Formally, for a given day with maximum difficulty \( m \) and a list of problems \( (d_i, r_i) \) where \( d_i \) is the difficulty and \( r_i \) is the associated reward, the total reward for that day is computed as:
[ \text{Total Reward} = \sum_{i=1}^{n} r_i \quad \text{where} \quad d_i \leq m ]
Your task is to implement a solution that reads input from stdin
and writes the computed rewards for each day to stdout
.
inputFormat
The input will be given in the following format:
T n d \(d_1\) \(r_1\) \(d_2\) \(r_2\) ... (total n lines) max_d1 max_d2 ... max_dd ... (repeat the above block T times)
Where:
T
is the number of test cases.- For each test case,
n
is the number of problems andd
is the number of days. - Each of the next
n
lines contains two integers representing the difficulty and reward of a problem. - The following line contains
d
integers representing the maximum difficulty level for each day.
outputFormat
For each test case, output the total reward for each day in the same order as the input daily maximum difficulties. Each reward value should be printed on a new line.
## sample1
5 3
2 10
3 20
5 30
1 15
4 25
3 2 5
45
25
100
</p>