#P2340. Smart and Witty Cows

    ID: 15614 Type: Default 1000ms 256MiB

Smart and Witty Cows

Smart and Witty Cows

Bessie is preparing a cow expo to prove that the cows are smart and witty. She interviewed N cows and recorded each cow's IQ and EQ. Bessie can choose an arbitrary subset of the cows for the expo. However, since negative IQ or EQ has a negative impact, she does not want the total IQ or the total EQ of the selected cows to be negative. Among all the subsets that satisfy these conditions (an empty set is allowed), she wants the one with the maximum sum of IQ and EQ. Formally, if a cow has IQ a and EQ b, and you select a subset S, you must have

$$\sum_{i\in S} a_i \ge 0 \quad\text{and}\quad \sum_{i\in S} b_i \ge 0, $$

and you want to maximize

iS(ai+bi).\sum_{i\in S} (a_i+b_i).

inputFormat

The first line contains an integer N (the number of cows). Each of the following N lines contains two integers: the IQ and the EQ of a cow.

outputFormat

Output a single integer: the maximum possible sum of IQ and EQ for a subset of cows such that both the total IQ and the total EQ are non-negative. The empty subset is allowed.

sample

3
10 -5
-5 10
-2 -2
10