CF788C.The Great Mixing

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

萨沙和科利亚决定再次用可乐来“喝醉”。这一次,他们有 kk 种可乐。第 ii 种可乐的二氧化碳浓度为 。今天,在为温哥华的谢尔盖举办的派对上,他们决定调制一杯二氧化碳浓度恰好为 的可乐。这杯饮料还必须美味,因此杯中每种可乐的体积(单位:升)必须为非负整数(某些种类的可乐可以不使用)。此外,他们希望最小化杯中可乐的总体积。

二氧化碳浓度定义为可乐中二氧化碳的体积除以可乐的总体积。当混合两种可乐时,二氧化碳体积相加,可乐总体积也相加。

请帮助他们找出调制出二氧化碳浓度恰好为 的可乐所需的最少正整数升数。假设朋友们拥有每种可乐的无限供应。

输入格式

The first line contains two integers n, k (0 ≤ n ≤ 1000, 1 ≤ k ≤ 106) — 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.

第一行包含两个整数 nn、kk(0 ≤ n ≤ 10000 \leq n \leq 1000,1 ≤ k ≤ 1061 \leq k \leq 10^6)——朋友们所期望的二氧化碳浓度值以及可乐种类的数量。

第二行包含 kk 个整数 a1, a2, ..., aka_1,\,a_2,\,...,\,a_k(0 ≤ ai ≤ 10000 \leq a_i \leq 1000)——每种可乐的二氧化碳浓度。某些可乐种类的浓度可能相同。

输出格式

Print the minimal natural number of liter needed to prepare a glass with carbon dioxide concentration , or -1 if it is impossible.

输出配制二氧化碳浓度为 的一杯饮料所需的最小自然数升数;若无法配制,则输出 -1。

输入输出样例

  • 输入#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: .

在第一个样例中,我们可以通过使用 1 升类型为 和类型为 的可乐,得到浓度为 的混合液:。

在第二个样例中,我们可以通过使用 2 升类型为 和 1 升类型为 的可乐,得到浓度为 的混合液:。

输入解题思路,AI测评打分。不知道怎么写?

首页