题目描述
Problem Description
Chef Marin is preparing a dish using $n$ peppers.
He decides to use all peppers that are no older than $x$ days for dish A, and all other peppers for dish B.
Each pepper has its own dream of whether it wants to be part of dish A or dish B.
However, they do not know the value of $x$. To maximize the number of peppers that achieve their dreams, they will follow this strategy for swapping:
- The first pepper compares its age with the second pepper, then the second pepper compares its age with the third pepper, and so on, until the $(n-1)$-th pepper compares its age with the $n$-th pepper.
- If the current comparison involves peppers $i$ and $j$, where the current age of pepper $i$ is greater and it wants to be part of dish A, and the current age of pepper $j$ is smaller and it wants to be part of dish B, then they will swap ages.
Determine the number of peppers that achieve their dreams after these operations.
Input Format
The first line contains two integers $n$ and $x$.
The next $n$ lines each contain two integers $a_i$ and $b_i$, representing the age and dream of the $i$-th pepper.
- If $b_i=1$, it means the $i$-th pepper wants to be part of dish A.
- If $b_i=0$, it means the $i$-th pepper wants to be part of dish B.
According to this definition, the more precise description in the problem statement is:
Two peppers $i$ and $j$ will swap ages if and only if $a_i > a_j$ and $b_i=1$ and $b_j=0$.
Output Format
Output a single integer, which is the number of peppers that achieve their dreams.
Sample Input and Output
Sample Input #1
4 5
2 0
3 0
4 0
5 0
Sample Output #1
0
Sample Input #2
5 5
3 1
2 0
13 1
2 0
10 1
Sample Output #2
5
Sample Input #3
6 10
15 1
12 1
8 0
10 1
3 0
1 1
Sample Output #3
4
Notes
Sample 1 Explanation
No peppers want to be part of dish A.
Sample 2 Explanation
Every pair of peppers swaps their ages.
Data Constraints
For $100\%$ of the data, $1 \le n, x, a_i \le 10^3$ and $b_i \in \{0, 1\}$.
Notes
This problem is adapted from COCI 2014-2015 Contest #6 Task A PAPRIKA.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分