测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A10947. The Great Mixing

编程题 普及/提高-

题目描述

Sasha and Kolya decided to get drunk with Coke, again. This time they have $k$ types of Coke. $i$ -th type is characterised by its carbon dioxide concentration ![](/uploads/luogu/CF788C/e1c7e5030c197d01ff231112151d3da349759c26_6e1e2045d615.png). Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration ![](/uploads/acgo/image/8faffebca0de1526_d8f8206b3b4f.jpeg). The drink should also be tasty, so the glass can contain only integer number of liters of each Coke type (some types can be not presented in the glass). Also, they want to minimize the total volume of Coke in the glass.

Carbon dioxide concentration is defined as the volume of carbone dioxide in the Coke divided by the total volume of Coke. When you mix two Cokes, the volume of carbon dioxide sums up, and the total volume of Coke sums up as well.

Help them, find the minimal natural number of liters needed to create a glass with carbon dioxide concentration ![](/uploads/acgo/image/8faffebca0de1526_d8f8206b3b4f.jpeg). Assume that the friends have unlimited amount of each Coke type.

输入格式

The first line contains two integers $n$ , $k$ ( $0<=n<=1000$ , $1<=k<=10^{6}$ ) — carbon dioxide concentration the friends want and the number of Coke types.

The second line contains $k$ integers $a_{1},a_{2},...,a_{k}$ ( $0<=a_{i}<=1000$ ) — carbon dioxide concentration of each type of Coke. Some Coke types can have same concentration.

输出格式

Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration ![](/uploads/acgo/image/8905d5847f102810_325cb91b0a4d.jpeg), or -1 if it is impossible.

输入输出样例

输入 #1
400 4
100 300 450 500
输出 #1
2
输入 #2
50 2
100 25
输出 #2
3

说明/提示

In the first sample case, we can achieve concentration ![](/uploads/luogu/CF788C/53c0c0e0841a7863e5e41d3ae6109fc13a9793f0_f5c98a381fd1.png) using one liter of Coke of types ![](/uploads/luogu/CF788C/da8eb2670aa7e9cd04451ad3d364dcfa7808ce21_fe1fcf65e1b1.png) and ![](/uploads/luogu/CF788C/58f5368f174695d4a9676aa063eb233c189ffbac_d6c0ae9c6275.png): ![](/uploads/acgo/image/e2c26ff43b52f676_314c53c97f8e.jpeg).

In the second case, we can achieve concentration ![](/uploads/luogu/CF788C/963e89a320201d0d065c93114d2e7ec46c38edca_1fd4556e00f5.png) using two liters of ![](/uploads/luogu/CF788C/37018a685b28e11b8bb14963b061142acb08a0ad_806844892ea3.png) type and one liter of ![](/uploads/luogu/CF788C/651b259754ff1d1b6742b5c61d5d87e9e1ce4261_c452797f5746.png) type: ![](/uploads/acgo/image/32ff8e9fcf98d34c_b355ee76b2cf.jpeg).
上一题 去做题 下一题