Get Time

   Problem Statement  

 Problem Statement for StampsCollection

Problem Statement

    You have decided to sell your stamp collection, which consists of n stamps numbered 0 to n-1. You have already found some buyers. The i-th buyer wants to buy the stamps listed in demand[i]. This will be a space-separated list containing either one or two stamps. He is willing to pay a total of price[i]. If he wants to buy two stamps, he will not agree to buy only one of them.

To make this task simpler, for each stamp, there will be no more than two buyers who want to buy it. Return the maximum amount of money you can get from selling your stamps.


Parameters:int, String[], int[]
Method signature:int sell(int n, String[] demand, int[] price)
(be sure your method is public)


-You don't have to sell all of your stamps.


-n will be between 1 and 50, inclusive.
-demand will contain between 1 and 50 elements, inclusive.
-price will contain the same number of elements as demand.
-Each element of demand will be a space-separated list of one or two distinct integers.
-All numbers in demand will be between 0 and n-1, inclusive, with no leading zeroes.
-All numbers in price will be between 1 and 1000000, inclusive.
-For each stamp, there will be at most 2 buyers who want to buy it.


{"0 4"}
Returns: 3
There is only one buyer, so all we can do is to sell two stamps.
{"1 0","0"}
Returns: 5
There are two buyers, but both want to buy stamp 0.
{"0 1","0 2","1 2"}
Returns: 12
Only one buyer can get what he wants - we choose the third one, who is willing to pay the most.
{"0","1 0","1 2"}
Returns: 10
Although the second buyer will pay the most, it is better to choose the first and third buyers.
{"0 1","1 2","2 3","3 0","4 5","5 6","6 4","8","8","9","9 10","10 11","11 12","12"}
Returns: 40

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 418 Round 1 - Division I, Level Two