博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
D - Garden
阅读量:5290 次
发布时间:2019-06-14

本文共 2157 字,大约阅读时间需要 7 分钟。

Problem description

Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.

Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.

See the examples for better understanding.

Input

The first line of input contains two integer numbers n and k (1 ≤ n, k ≤ 100) — the number of buckets and the length of the garden, respectively.

The second line of input contains n integer numbers ai (1 ≤ ai ≤ 100) — the length of the segment that can be watered by the i-th bucket in one hour.

It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.

Output

Print one integer number — the minimum number of hours required to water the garden.

Examples

Input

3 6 2 3 5

Output

2

Input

6 7 1 2 3 4 5 6

Output

7

Note

In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.

In the second test we can choose only the bucket that allows us to water the segment of length 1.

解题思路:题目的意思就是有n个桶,选择其中一个长度为a(每小时可以浇的长度为a)的桶,使得刚好浇完长度为k的花园,要求浇过的不能再浇,求全程最短用时。结合提示可以知道,要刚好浇完长度为k的花园,必须选择a刚好被k整除的桶,这样最后才不会有重叠,并且a在所有桶长度中是k的较大因子,这样全程用时才最短。

AC代码:

1 #include 
2 using namespace std; 3 int main() 4 { 5 int n,k,x,mt=200; 6 cin>>n>>k; 7 while(n--){ 8 cin>>x; 9 if(k%x==0)mt=min(mt,k/x);//取最短时间10 }11 cout<
<

 

转载于:https://www.cnblogs.com/acgoto/p/9105140.html

你可能感兴趣的文章
常见算法之‘选择排序’
查看>>
Java学习笔记39(转换流)
查看>>
计算一个圆的直径面积周长
查看>>
XSS攻击及防御
查看>>
7.29 DFS总结
查看>>
c++操作io常见命令
查看>>
页面JS引用添加随机参数避免页面缓存
查看>>
java的基础知识文件操作和标识符
查看>>
Tika解析word文件
查看>>
变量作用域
查看>>
.NET程序集签名
查看>>
Python操作列表
查看>>
java reflect反射---Java高级开发必须懂的
查看>>
18.5 线程的优先级
查看>>
sessionStorage/localStorage 本地存储
查看>>
SVN设置必须锁定
查看>>
Oracle 手动建库
查看>>
《架构之美》阅读笔记04
查看>>
图像状态资源的介绍~~以button按钮为例
查看>>
【转】eclipse技巧2
查看>>