#P5928. [清华集训 2014] 文学

    ID: 5036 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>计算几何2015WC/CTSC/集训队凸包半平面交

[清华集训 2014] 文学

Description

Ju Jiang and the Chairman are a pair of good friends. They both enjoy reading, and often read books in related fields together for systematic learning. One day, the Chairman made a list of pp books, including famous works such as Jean-Christophe and Biographies of Famous People. As a well-known young man with strong literary taste, Ju Jiang plans to finish all the books on this list in as little time as possible.

As a man of culture, Ju Jiang reads differently from ordinary people. He uses a method called “batch reading”. First, based on his preferences, he assigns two parameters x,yx, y to each book; for book ii, these parameters are xi,yix_i, y_i. Of course, due to Ju Jiang’s unique taste, two different books may have the same x,yx, y parameters.

Each time he reads, he sets three coefficients a,b,ca, b, c. All books satisfying a×x+b×yca \times x + b \times y \leq c can be finished in this “batch reading”, and this batch reading takes a total time of ww.

Now, Ju Jiang has nn “batch reading” plans. For plan ii, the three parameters are ai,bi,cia_i, b_i, c_i, and the required time is wiw_i. Ju Jiang wants to choose some of these nn plans so that he can finish all books in the least total time. You need to find the minimum time Ju Jiang needs.

Input Format

The first line contains two positive integers n,pn, p, representing the number of “batch reading” plans and the number of books.

The next nn lines each contain four integers. The ii-th line contains ai,bi,ci,wia_i, b_i, c_i, w_i, describing the ii-th “batch reading” plan.

The next pp lines each contain two integers. The ii-th line contains xi,yix_i, y_i, describing the parameters of the ii-th book.

Output Format

Output one integer in one line, representing the minimum required time. If it is impossible to finish all the books no matter what, output 1-1.

4 3
-1 0 0 10
-1 -1 -1 2
-1 1 -1 2
-1 -2 -1 1
0 2
0 -2
1 0
3

Hint

For 100%100\% of the testdata: 1n,p1001 \leq n, p \leq 100, 106ai,bi,ci,xi,yi106-10^6 \leq a_i, b_i, c_i, x_i, y_i \leq 10^6, 0<wi1060 < w_i \leq 10^6. It is guaranteed that for any “batch reading” plan, aia_i and bib_i are not both 00. Also, there do not exist i,ji, j (iji \ne j) such that ai×bj=aj×bia_i \times b_j = a_j \times b_i.

Translated by ChatGPT 5