PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000068. Hãy chọn tôi (Choose Me)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hãy chọn tôi (Choose Me)
Choose Me
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A city has towns. Town contains supporters of Aoki and supporters of Takahashi. If Takahashi gives a speech there, all residents vote for him; otherwise only the residents vote for Aoki, and abstain. Find the minimum number of towns where Takahashi must speak to get strictly more votes than Aoki.
Input
The first line contains . The next lines contain .
Output
Print the minimum number of towns.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
4
2 1
2 2
5 1
1 3
Output
1
Explanation
Initially Aoki has votes and Takahashi has . Speaking in town moves votes away from Aoki and adds to Takahashi, giving versus . One speech is sufficient.