A10947 | The Great Mixing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 . Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration . 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 . Assume that the friends have unlimited amount of each Coke type.
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 . 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.
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 , 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  using one liter of Coke of types  and : .
In the second case, we can achieve concentration  using two liters of  type and one liter of  type: .
In the second case, we can achieve concentration  using two liters of  type and one liter of  type: .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted