luogu#P7954. [COCI 2014/2015 #6] PAPRIKA
[COCI 2014/2015 #6] PAPRIKA
Problem Description
Chef Marin is going to cook with peppers.
He decides to use all peppers whose age is at most days to make dish A, and use all the other peppers to make dish B.
Each pepper has its own dream: it knows whether it wants to become A or B.
But they do not know the value of . In order to maximize the number of peppers whose dreams come true, they will perform swaps using the following strategy:
- Pepper 1 compares ages with pepper 2, then pepper 2 compares ages with pepper 3, and so on, until pepper compares ages with pepper .
- If the two peppers currently being compared have indices , and the pepper with the larger current age wants to become dish A, and the pepper with the smaller current age wants to become dish B, then they swap their ages.
Compute the number of peppers whose dreams come true after doing this.
Input Format
The first line contains two integers .
The next lines each contain two integers , representing the age and dream of the -th pepper.
- If , it means the -th pepper wants to become dish A.
- If , it means the -th pepper wants to become dish B.
With this definition, a more precise statement of in the “Description” is:
Two peppers swap their ages if and only if and and .
Output Format
Output one integer on a single line: the number of peppers whose dreams come true.
4 5
2 0
3 0
4 0
5 0
0
5 5
3 1
2 0
13 1
2 0
10 1
5
6 10
15 1
12 1
8 0
10 1
3 0
1 1
4
Hint
Explanation for Sample 1
No pepper wants to become dish A.
Explanation for Sample 2
Every pair of peppers swapped their ages.
Constraints
For of the testdata, , and .
Notes
According to the original settings, the full score is 50 points.
Translated from COCI 2014-2015 Contest #6 Task A PAPRIKA。
Translated by ChatGPT 5