408723: GYM103274 A Alien Crop Triangles

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Alien Crop Trianglestime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

What a day! From reports received by the police department, a strange, triangular shaped object was seen flying and beaming strong light across the sky of Nlogonia for a few minutes this morning. Was it Triangolonian aliens? A secret government project? Someone playing a prank? Either way, you noticed your property now has several triangular patches that are missing its grass... time to buy some grass seeds to fix those.

Grass seeds come in bags of a certain kilogram weight. Each kg of seeds can be used to cover 30$$$m^2$$$ of grass. A local supplier has given you a quote for all $$$B$$$ seed bags it sells. Each bag has a weight of $$$W_i$$$ kg and costs $$$P_i$$$ Nlogonian coins.

You went ahead and measured all the $$$N$$$ triangles missing its grass that you need to cover with seeds. As they have different shapes, you decided to measure their sides ($$$A_i$$$, $$$B_i$$$, $$$C_i$$$) in meters.

Given your local supplier quote, and the measurements of each triangle. Can you find the minimum number of coins you need to buy enough seeds to fix up your property?

Input

The first line of input contains two integers separated by a space $$$B$$$ and $$$N$$$ ($$$1 \leq B \leq 5$$$, $$$0 \leq N \leq 10^5$$$), representing, respectively, the number of bags in the local supplier quotation and the number of triangles with missing grass in your property. Each of the next $$$B$$$ lines in the input contains two integers separated by a space $$$W_i$$$, and $$$P_i$$$, ($$$0 \leq W_i \leq 25$$$, $$$0 \leq P_i \leq 100$$$), representing, respectively the weight in kilograms, and price in Nlogonian coins of the $$$i$$$-th bag in the local supplier quote. Each of the next and last $$$N$$$ lines contains three integer numbers separated by a space $$$A_i$$$, $$$B_i$$$, and $$$C_i$$$, representing each of the sides measured in the $$$i$$$-th triangle.

Output

Output a line containing a single integer number, the minimum number of coins required to buy enough seeds to fix your property. If there is no way you can fix the property print $$$-1$$$.

ExampleInput
1 1
1 100
10 10 10
Output
200

加入题单

上一题 下一题 算法标签: