#P1752. 点菜

点菜

Description

There are nn people who come to a restaurant to order dishes. The restaurant has mm dishes in total, and each dish has two attributes: tastiness and price. These nn people come once every week, and each time each person will order at most one dish or none. Among these nn people, pp people are picky; they can only accept dishes with tastiness greater than or equal to a certain value. Another qq people are poor; they can only order dishes with price less than or equal to a certain value. Now please compute: what is the minimum number of weeks they need to come so that it is possible to have ordered all dishes at least once?

Input Format

  • Line 11: four positive integers n,m,p,qn, m, p, q.
  • Lines 2m+12 \sim m+1: each line contains two numbers, the tastiness and the price of a dish.
  • Line m+2m+2: pp numbers, the lower bounds of acceptable tastiness for each of the pp picky people.
  • Line m+3m+3: qq numbers, the upper bounds of acceptable price for each of the qq poor people.

Output Format

Output a single number: the minimum number of weeks needed. If it is impossible to have all dishes ordered at least once no matter how many weeks they come, output 1-1.

2 3 1 1
5 2
5 3
6 4
5
1
3

Hint

Constraints and Conventions:

  • For 20%20\% of the testdata, m20m \le 20.
  • For 40%40\% of the testdata, m2000m \le 2000.
  • For 100%100\% of the testdata, p+qn50000p+q \le n \le 50000, m200000m \le 200000.

Translated by ChatGPT 5