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

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

Discription

Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all.

Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula:

The less value c(a) is, the more beautiful the array is.

It’s time to change the world and Levko is going to change his array for the better. To be exact, Levko wants to change the values of at most k array elements (it is allowed to replace the values by any integers). Of course, the changes should make the array as beautiful as possible.

Help Levko and calculate what minimum number c(a) he can reach.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2000). The second line contains space-separated integers a1, a2, ... , an ( - 109 ≤ ai ≤ 109).

Output

A single number — the minimum value of c(a) Levko can get.

Examples

Input
5 2 4 7 4 7 4
Output
0
Input
3 1 -100 0 100
Output
100
Input
6 3 1 2 3 7 8 9
Output
1

Note

In the first sample Levko can change the second and fourth elements and get array:4, 4, 4, 4, 4.

In the third sample he can get array: 1, 2, 3, 4, 5, 6.

 

 

   二分答案之后直接dp就行啦,水水水hhhh

 

#include
#define ll long longusing namespace std;const int maxn=20005,inf=2*1e9;int n,a[maxn],f[maxn],k,mid;inline int mabs(int x){ return x<0?-x:x;}inline bool solve(){ for(int i=1;i<=n;i++){ f[i]=i-1; for(int j=1;j
>1; if(solve()) r=mid-1,ans=mid; else l=mid+1; } printf("%d\n",ans); return 0;}

  

转载于:https://www.cnblogs.com/JYYHH/p/8985367.html

你可能感兴趣的文章
论文笔记——MobileNets(Efficient Convolutional Neural Networks for Mobile Vision Applications)
查看>>
从今天开始
查看>>
Attribute(特性)与AOP
查看>>
[翻译] CBStoreHouseTransition
查看>>
第三次作业
查看>>
Codeforces 962 /2错误 相间位置排列 堆模拟 X轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边...
查看>>
Matrix快速幂 模板
查看>>
laravel command调用方法命令
查看>>
20162302 - 20162319 结对编程项目-四则运算(第一周)
查看>>
用python2和python3伪装浏览器爬取网页
查看>>
MySQL开启远程连接权限
查看>>
tomcat7.0.27的bio,nio.apr高级运行模式
查看>>
SAP HANA 三大特点
查看>>
C#预处理器命令
查看>>
苹果手表:大方向和谷歌一样,硬件分道扬镳
查看>>
ccf 出现次数最多的数
查看>>
单例模式
查看>>
Competing Consumers Pattern (竞争消费者模式)
查看>>
HDUOJ ------1398
查看>>
cf--------(div1)1A. Theatre Square
查看>>