Count pairs (X, Y) such that voiding every voter with A_i>=X or B_i>=X or A_i+B_i>=Y leaves Cheki strictly ahead of Chaka.
Medium6Brute forceImplementationSortingNo attempts yetTime limit1sMemory limit64 MBA few months ago the country of Chex held a presidential election. Two candidates ran, Cheki and Chaka. Cheki promised to put more chocolate into Chex, the staple cereal of the country, and Chaka promised to make Chex taste like green onion.
Chex runs its elections with repeated voting. One voter casts at most 100,000 ballots in total between the two candidates. When the election ends, the candidate with more votes takes office. If both candidates receive the same number of votes, nobody takes office.
The residents liked the fresh promise from Chaka and gave Chaka more votes, yet Cheki took office. A month later an employee of the election commission reported the count as rigged. According to that report, the ballots of some voters were all thrown out by the following rule.
Once the void ballots are removed, Cheki takes office only when Cheki has strictly more votes than Chaka. The whistleblower does not know the values of X and Y either, so you have to work them out. Given the voting record, count the pairs (X,Y) that put Cheki in office.
The first line contains the number of voters N (2≤N≤1000).
Each of the next N lines contains Ai and Bi, the number of ballots that voter i cast for Cheki and for Chaka (0≤Ai, 0≤Bi, 1≤Ai+Bi≤100000).
The input always has the sum of Bi greater than the sum of Ai.
Print the number of pairs (X,Y) that put Cheki in office.
In the first example Cheki takes office only when X=6 and 9≤Y≤100000.