- Contest 2014
As you might know the current exchange rate between Swiss francs and Euros is very low, which is why many Swiss go to Germany to buy products with the cheaper Euro. As Stofl's family sometimes encounters some money problems, they are planning a trip to Germany as well. Besides Stofl himself also his parents will come along (so three mice in total).
When importing goods from the EU into Switzerland there is a duty-free limit of 300 Swiss francs per mouse. However, a single good cannot be split up over multiple mice. So for instance if three mice buy four products for 200 Swiss francs each, they cannot import it duty-freely, even though the total value (here 800 Swiss francs) would be less than their accumulated duty-free limit of 900 Swiss francs.
Given the prices of the products (in Swiss francs) Stofl's family buys, determine whether they can distribute the goods to the three family members in such a way that they can import the entire shopping duty-freely (i.e. nobody gets more than 300 Swiss francs in value). To simplify the calulcation you can assume that all the products cost a round Swiss franc-amount (no rappen).
The first line of the input contains a single integer $n$ ($1\leq n\leq 100$), the number of products Stofl's family buys. Each of the following $n$ lines contains a single integer $p_i$ ($1\leq p_i\leq 1000$), the price of the $i$-th product in Swiss francs.
Output the word Yes if it is possible to import all the goods duty-freely, and No otherwise.
4 198 200 199 200
6 150 200 100 140 300 5
For the first example no matter how the products are split up between the three mice, at least one will always get more than $300$ Swiss francs in value.
For the second example a valid possibility would be the following: