Corrupt Election
Time limit1sMemory limit64 MB
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.
- Level
Medium6 of 10
- Topics
- Brute force, Implementation, Sorting
- Solved
- No attempts yet
Problem
A 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.
- If a voter cast or more ballots for a single candidate, or cast or more ballots in total, every ballot from that voter becomes void. and are fixed integers between 1 and 100,000.
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 and either, so you have to work them out. Given the voting record, count the pairs that put Cheki in office.
Input
The first line contains the number of voters ().
Each of the next lines contains and , the number of ballots that voter cast for Cheki and for Chaka (, , ).
The input always has the sum of greater than the sum of .
Output
Print the number of pairs that put Cheki in office.
Note
In the first example Cheki takes office only when and .