0
点赞
收藏
分享

微信扫一扫

POJ 3622 Gourmet Grazers

少_游 2023-02-08 阅读 21


Gourmet Grazers


Description



Like so many others, the cows have developed very haughty tastes and will no longer graze on just any grass. Instead, Farmer John must purchase gourmet organic grass at the Green Grass Grocers store for each of his N (1 ≤ N ≤ 100,000) cows.

Each cow i demands grass of price at least Ai (1 ≤ Ai ≤ 1,000,000,000) and with a greenness score at least Bi (1 ≤ Bi ≤ 1,000,000,000). The GGG store has M (1 ≤ M ≤ 100,000) different types of grass available, each with a price Ci (1 ≤ Ci ≤ 1,000,000,000) and a greenness score of Di (1 ≤ Di ≤ 1,000,000,000). Of course, no cow would sacrifice her individuality, so no two cows can have the same kind of grass.

Help Farmer John satisfy the cows' expensive gourmet tastes while spending as little money as is necessary.


Input



* Line 1: Two space-separated integers: N and M.
* Lines 2..N+1: Line i+1 contains two space-separated integers: Ai and Bi 
* Lines N+2..N+M+1: Line i+N+1 contains two space-separated integers: Ci and Di


Output



* Line 1: A single integer which is the minimum cost to satisfy all the cows. If that is not possible, output -1.


Sample Input

4 71 12 31 44 23 22 14 35 25 42 64 4

Sample Output

12

Source


​​USACO 2007 December Gold​​

Time Limit: 3000MS

 

Memory Limit: 65536K

Total Submissions: 2420

 

Accepted: 897

举报

相关推荐

0 条评论