题目描述
Problem Description
You are planning to hold an art exhibition. In the exhibition, several paintings will be framed and displayed in a row from left to right.
There are $N$ paintings that are candidates for display, numbered from $1$ to $N$. The size of painting $i$ ($1 \leq i \leq N$) is $S_i$, and its value is $V_i$.
Additionally, there are $M$ frames for these paintings, numbered from $1$ to $M$. The size of frame $j$ ($1 \leq j \leq M$) is $C_j$. Only paintings whose size is $C_j$ or smaller can be placed in frame $j$. At most one painting can be placed in each frame.
All paintings to be displayed must be in some frame. For aesthetic reasons, the displayed paintings must satisfy the following conditions:
- For any two adjacent paintings, the size of the frame containing the painting on the right must be at least the size of the frame containing the painting on the left.
- For any two adjacent paintings, the value of the painting on the right must be at least the value of the painting on the left.
You want to display as many paintings as possible.
Given the number of candidate paintings, the number of frames, and their sizes and values, create a program to determine the maximum number of paintings that can be displayed.
Input Format
The input is given from the standard input in the following format:
$N$ $M$ $S_1$ $V_1$ $\vdots$ $S_N$ $V_N$ $C_1$ $\vdots$ $C_M$
Output Format
Output the maximum number of paintings that can be displayed in the exhibition on a single line to the standard output.
Sample Input and Output
Sample Input #1
3 4
10 20
5 1
3 5
4
6
10
4
Sample Output #1
2
Sample Input #2
3 2
1 2
1 2
1 2
1
1
Sample Output #2
2
Sample Input #3
4 2
28 1
8 8
6 10
16 9
4
3
Sample Output #3
0
Sample Input #4
8 8
508917604 35617051
501958939 840246141
485338402 32896484
957730250 357542366
904165504 137209882
684085683 775621730
552953629 20004459
125090903 607302990
433255278
979756183
28423637
856448848
276518245
314201319
666094038
149542543
Sample Output #4
3
Notes/Hints
Constraints
- $1 \leq N \leq 100,000$.
- $1 \leq M \leq 100,000$.
- $1 \leq S_i \leq 1,000,000,000$ ($1 \leq i \leq N$).
- $1 \leq V_i \leq 1,000,000,000$ ($1 \leq i \leq N$).
- $1 \leq C_j \leq 1,000,000,000$ ($1 \leq j \leq M$).
Subtasks
- ($10$ points) $N \leq 10$, $M \leq 10$.
- ($40$ points) $N \leq 1,000$, $M \leq 1,000$.
- ($50$ points) No additional constraints.
Sample Explanation 1
In this input/output example, arranging the paintings in the order (painting $2$, frame $2$) and (painting $1$, frame $3$) allows for displaying $2$ paintings. It is not possible to display more than $2$ paintings, so output $2$. Here, (painting $i$, frame $j$) represents painting $i$ placed in frame $j$.
Sample Explanation 2
Sample Explanation 3
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分