AtCoder Regular Contest 147
E
Examination
AtCoder
⌀ 2553
原题
← DF →
翻译中…

Problem Statement

翻译中…

$N$ students, numbered $1,2,\ldots,N$, took an examination. Student $i\,(1 \leq i \leq N)$ had to score at least $B_i$ points to graduate, where they actually scored $A_i$ points.

翻译中…

You can repeat the following operation any number of times (possibly zero):

翻译中…
  • Choose two students, and swap their scores.
翻译中…

Your goal is to make everyone graduate. Determine whether it is possible. If it is possible, find the maximum number of students whose scores do not change during the process.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 3 \times 10^5$
  • $1 \leq A_i,B_i \leq 10^9\,(1 \leq i \leq N)$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 B_1
A_2 B_2
\vdots
A_N B_N

翻译中…

Output

翻译中…

If it is possible to make everyone graduate, print the maximum number of students whose scores do not change during the process.

翻译中…

Otherwise, print -1.

翻译中…

样例

Input #1
3
1 2
3 1
3 3
Output #1
1
If you swap scores of Student $1$ and $2$, everyone can graduate. Here, the number of students whose scores do not change is $1$ (only Student $3$).
Input #2
2
100 1
100 1
Output #2
2
Input #3
6
3 2
1 6
4 5
1 3
5 5
9 8
Output #3
-1
Input #4
6
3 1
4 5
5 2
2 3
5 4
5 1
Output #4
3
题目信息
题号
arc147_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。