2017 ICPCECIC Birthday present

题目描述

Bob’s father’s birthday is coming,.Because Bob’s father is a math teacher so that Bob wanted to give him an array of positive intergers a of length n as a gift.His father thinks that an array’s beauty is the greatest common divisor of all its elements. Bob wants to give him as beautiful an array as possible. But the shop has only one array a left. So Bob wants to decrease some numbers in the array(no more than K for each number).Bob can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n.Help Bob find the maximum possible beauty of the array he will give to his father .

输入

The first line contains two integers n and k (1 ≤ n ≤ 3·1e5; 1 ≤ k ≤ 1e6). The second line contains n integers ai (1 ≤ ai ≤ 1e6) — array a.

输出

In the single line print a single number — the maximum possible beauty of the resulting array.

样例输入

6 1
3 6 10 12 13 16

样例输出

3


题意

一个序列,n个元素,每个数可以向下减少最多k个值,问能得到的序列的最大公共因子是多少。减少一定值以后的数要大于等于0。


思路

找a[i]%ans<=k;这个关系以后这个题基本就可以用暴力写了。
不过最坑的事情还是发生了。
这道题竟然TM的是多组输入。读题神TM能读出是多组输入来。

代码

*#include <bits/stdc++.h>

using namespace std;
int a[1000000];
int main()
{
    int n,k,i,j;
    while(scanf("%d %d",&n,&k)!=EOF){
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int h = a[0];
    for(i=h;i>=1;i--)
    {
        int f=0;
        for(j=0;j<n;j++)
        {
            if(a[j]%i>k)
            {
                f = 1;
                break;
            }
        }
        if(f==0)
        {
            printf("%d\n",i);
            break;
        }
    }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

渴鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值