#QHD0000048. Siêu giảm giá (SuperSale)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Siêu giảm giá (SuperSale)
SuperSale
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A shop offers types of products, where product has value and weight . There are family members, and member can carry at most weight. Each member makes an independent selection and may take each product at most once within their own selection. Different members may select the same product. Maximize the sum of the optimal values across all family members.
Input
The first line contains , followed by lines with . Next comes , followed by lines each containing a capacity .
Output
Print the maximum combined total value.
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , , , .
- Subtask 2 (30%): , , , , .
- Subtask 3 (50%): , , , , .
Examples
Input
3
72 17
44 23
31 24
2
26
30
Output
144
Explanation
Both people can achieve maximum value by taking the first item of weight . Every pair is too heavy, so the combined maximum is .