D - Choose Me Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400400

問題文

AtCoder 市で市長選挙が行われます。候補者は青木氏と高橋氏です。
市には NN 個の町があり、ii 番目の町には青木派の有権者が AiA_i 人、高橋派の有権者が BiB_i 人います。他に有権者はいません。
高橋氏は、それぞれの町で演説を行うことができます。
高橋氏がある町で演説を行った場合、その町の高橋派も青木派も全員高橋氏に投票します。
一方、高橋氏がある町で演説を行わなかった場合、その町の青木派は全員青木氏に投票し、高橋派は投票に行きません。
高橋氏が青木氏より多く票を獲得するためには、最小でいくつの町で演説をする必要があるでしょうか?

制約

  • 入力は全て整数
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1Ai,Bi1091 \le A_i, B_i \le 10^9

入力

入力は以下の形式で標準入力から与えられる。

NN
A1A_1 B1B_1
\vdots
ANA_N BNB_N

出力

答えを出力せよ。


入力例 1Copy

Copy
4
2 1
2 2
5 1
1 3

出力例 1Copy

Copy
1

33 番目の町で演説を行うと、青木氏が 55 票、高橋氏が 66 票を得ます。


入力例 2Copy

Copy
5
2 1
2 1
2 1
2 1
2 1

出力例 2Copy

Copy
3

33 つの町で演説を行うと、青木氏が 44 票、高橋氏が 99 票を得ます。


入力例 3Copy

Copy
1
273 691

出力例 3Copy

Copy
1

Score : 400400 points

Problem Statement

AtCoder City will hold a mayoral election. The candidates are Aoki and Takahashi.
The city consists of NN towns, the ii-th of which has AiA_i pro-Aoki voters and BiB_i pro-Takahashi voters. There are no other voters.
Takahashi can make a speech in each town.
If he makes a speech in some town, all voters in that town, pro-Takahashi or pro-Aoki, will vote for Takahashi.
On the other hand, if he does not make a speech in some town, the pro-Aoki voters in that town will vote for Aoki, and the pro-Takahashi voters will not vote.
To get more votes than Aoki, in how many towns does Takahashi need to make speeches at least?

Constraints

  • All values in input are integers.
  • 1N2×1051 \le N \le 2 \times 10^5
  • 1Ai,Bi1091 \le A_i, B_i \le 10^9

Input

Input is given from Standard Input in the following format:

NN
A1A_1 B1B_1
\vdots
ANA_N BNB_N

Output

Print the answer.


Sample Input 1Copy

Copy
4
2 1
2 2
5 1
1 3

Sample Output 1Copy

Copy
1

After making a speech in the third town, Aoki and Takahashi will get 55 and 66 votes, respectively.


Sample Input 2Copy

Copy
5
2 1
2 1
2 1
2 1
2 1

Sample Output 2Copy

Copy
3

After making speeches in three towns, Aoki and Takahashi will get 44 and 99 votes, respectively.


Sample Input 3Copy

Copy
1
273 691

Sample Output 3Copy

Copy
1


2025-03-29 (Sat)
10:05:00 +00:00