Fair Play
InterviewTime limit2sMemory limit1024 MB
Given n people each with billiards and pool skill values, decide whether they can be split into pairs so every pair has identical total skill in both categories.
Problem
Together with your coworker Larry, you are organizing the Billiards and Pool Competition for your coworkers at your small company. You and Larry usually agree, and he will surely approve of your latest idea. You even bought a nice prize for your coworkers to win, and you hope they are as excited as you are. You want to maximize the fun.
So it would be good to avoid complete walkovers: those are no fun for either player. After some thought, you decide it is a good idea to suggest to Larry that the players be divided into teams of two. That way, you can compensate for a player's strength by pairing them with a weaker player. In fact, it would be perfect if every team had exactly the same strength! Before telling Larry your plans, you decide to first figure out whether this is possible.
In your model, synergy plays a negligible role in determining team strength, and the strength of a team is determined only by the strength of its individual members. Every coworker has a certain skill level in both billiards and pool, given by two integers. When two coworkers team up, their total skill is the sum of their individual skills. Can you divide all coworkers into teams of two such that every team has exactly the same skill in both billiards and pool?
Input
The input consists of:
- A line with an integer (), the number of coworkers.
- Then lines follow, each containing two integers and (), the skill in billiards and pool, respectively, of each coworker.
Output
Output possible if all coworkers can be divided into teams of two with equal skill. Output impossible otherwise.