X and Y were in an election battle in their city. This city consists of N towns, and each town has M1 number of people who will vote for Y and M2 number of people who will not take part in the election. X after seeing the lack of his supporters, decided to campaign.
If X does a campaign in town T, both M1 and M2 number of people in this town become his supporters.
Your task is to calculate the least number of towns in which X has to campaign to win the election.
Note: It is always possible for X to win the election.
Constraints:
1 < N<= 200000
1< M1,M2 <= 1000000000
Test Case
2
2 2
2 2
Answer: 1
Explanation: X can campaign in either city and gain 4 votes, Y can thus only get a maximum of 2 votes
Test Case #2:
4
2 2
1 3
5 1
2 2
Answer: 1
Explanation: X needs to campaign in city 3 to gain 5 + 1 = 6 votes. Y can only get a maximum of 2 + 2 + 1 = 5 votes.
I tried an O(NlogN) solution using priority queue, but it failed a few test cases. Is an O(N) solution possible?