#P2792. [JSOI2008] 小店购物
[JSOI2008] 小店购物
Description
The shop’s promotions are simple and fun:
During a single shopping session, if you buy refined oil at this shop, then when you buy soap you can enjoy a discounted price of yuan per bar; if you buy soap, then when you buy cola you can enjoy a discounted price of yuan per can; and so on. In summary: if you buy item , then you may buy item at a discounted price of yuan per unit (with no limit on the quantity).
Interestingly, you need to buy some fixed items, and because different purchase orders may lead the shopkeeper to charge you different totals. For example, you need one bar of soap (original price yuan), one bottle of refined oil (original price yuan), and one can of cola (original price yuan). If you purchase in the order cola → refined oil → soap, the shopkeeper will charge you yuan; but if you purchase in the order refined oil → soap → cola, you only need to pay yuan.
The local residents know that JSOI team members are good at programming, so they ask you to write a program: given the original prices of all items in the shop, all promotion rules, and the items you need, compute the minimum amount of money you must spend (you are not allowed to buy any unnecessary items, even if doing so could reduce the total cost).
Input Format
The first line contains an integer , the total number of item types in the shop.
The next lines follow. The -th line contains a real number and an integer separated by a space, denoting the original price of item and the required quantity. The -th line contains an integer , the total number of promotion rules.
Then lines follow. Each line contains two integers and a real number , describing one promotion: if you buy item , then you may buy item at a discounted price of yuan per unit. Here is less than the original price of item . All pairs in the promotions are distinct. For convenience, the shopkeeper does not use one-cent units, so all prices are multiples of yuan.
Output Format
Output a single real number: the minimum total cost. Print the number with exactly two decimal places.
4
10.00 1
1.80 1
3.00 0
2.50 2
2
1 4 2.00
4 2 1.50
15.50
Hint
Constraints can be found in the Input Format.
Translated by ChatGPT 5
京公网安备 11011102002149号