UTS Open '18 P4 - Ianine's Lil Lab

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

UTS needs a computer lab for the new building at 30 Humbert Street, and Mr. Ianine is in charge of buying new computers. Each desktop computer needs a keyboard and a monitor. Luckily, Mr. Ianine has N (1N2105) coupons. The ith coupon lets him buy either Ki keyboards or Mi monitors, but it cannot be used for both keyboards and monitors.

Being the fair person that he is, Mr. Ianine wants all coupons to be treated equally. He defines the value of the ith coupon as Vi=Ki+Mi, and he must ensure that all the coupons he uses have the same value.

After using the coupons at the store, Mr. Ianine pairs up his keyboards and monitors. Each pair will be used for one working computer, and any extra unpaired keyboards and monitors are kept away in the IT room. What is the maximum number of working computers that he can get?

Input Specification

The first line contains N (1N2105), the number of coupons that Mr. Ianine has.

The next N lines contain two integers Ki and Mi, the number of keyboards and monitors that the ith coupon allows him to buy. It is guaranteed that Ki,Mi0 and 0Vi105.

Output Specification

Output the maximum number of working computers that Mr. Ianine can get, by using coupons of the same value.

Constraints

Subtask 1 [10%]

0Vi2 for all i.

Subtask 2 [30%]

1N20

Subtask 3 [60%]

No additional constraints.

Sample Input

Copy
6
1 4
7 1
0 5
4 1
4 4
2 3

Sample Output

Copy
6

Explanation for Sample Output

Mr. Ianine should use the coupons with value 5. He should use coupons 4 and 6 to buy 4+2=6 keyboards, and coupons 1 and 3 to buy 4+5=9 monitors. Then he will have 6 working computers.


Comments

There are no comments at the moment.