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<bits/stdc++.h>
#define ll long long
using 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<i;j++) if(mabs(a[i]-a[j])<=(i-j)*(double)mid) f[i]=min(f[i],f[j]+i-j-1);
if(f[i]+n-i<=k) return 1;
} return 0;
} int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%d",a+i); int l=0,r=inf,ans;
while(l<=r){
mid=(l+(ll)r)>>1;
if(solve()) r=mid-1,ans=mid;
else l=mid+1;
} printf("%d\n",ans);
return 0;
}

  

CodeForces - 361D Levko and Array的更多相关文章

  1. Codeforces 361D Levko and Array(二分)(DP)

    Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. 有意思的DP(CF360B Levko and Array)

    刚才面试了一个蛮有意思的DP题目,脑子断片,没写出来,不过早上状态还是蛮好的 一个长度为n的序列最多改变k次,使相邻两数之差绝对值的最大值最小 三维的dp我先尝试写一下 Codeforces 360B ...

  3. [codeforces 360]A. Levko and Array Recovery

    [codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...

  4. CF360B Levko and Array (二分查找+DP)

    链接:CF360B 题目: B. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes i ...

  5. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  6. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  7. codeforces 361 D. Levko and Array(dp+二分)

    题目链接:http://codeforces.com/contest/361/problem/D 题意:最多可以修改K次数字,每次修改一个数字变成任意值,C=max(a[i+1]-a[i]):求操作之 ...

  8. codeforces 361 C. Levko and Array Recovery(暴力+思维)

    题目链接:http://codeforces.com/contest/361/problem/C 题意:对一个数列有这么两个操作 1.(1,l,r,p)..将区间[l,r]所有数都加上p 2.(2,l ...

  9. Codeforces Round #210 (Div. 2) C. Levko and Array Recovery

    题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...

随机推荐

  1. Jquery Dialog 详解(正在学习jquery,详解转载)

    文章来源:http://xufish.blogbus.com/logs/39583154.html AUTHOR:Jevoly 还是先看例子吧.另外如果要拖动.改变dialog的大小的话要加上ui.d ...

  2. cf965d Single-use Stones

    ref #include <iostream> #include <cstdio> using namespace std; int a[100005], n, l, ans= ...

  3. 关于html头部引用(meta,link)

    /*这一段头部表示 如果安装了GCF,则使用GCF来渲染页面,如果为安装GCF,则使用最高版本的IE内核进行渲染.*/<meta content="IE=edge,chrome=1&q ...

  4. Java实现对cookie的增删改查

    原文地址:http://blog.csdn.net/k21325/article/details/54377830 @RequestMapping(value="meeting/addGua ...

  5. Spring整合hibernate -hibernateTemplate

    目录 1 在Spring中初始化hibernateTemplate并注入Sessionfactory 2 DAO里注入hibernateTemplate 3 getHibernateTemplate. ...

  6. iptables + Denyhost抵御暴力破解

    使用iptables 现在每分钟连接ssh的次数 #允许本地环回接口访问   1 iptables -A INPUT -i lo -j ACCEPT #对已经建立的所有链接都放行   1 iptabl ...

  7. Mysql 死锁

    http://www.cnblogs.com/benshan/archive/2013/05/09/3068886.html 声明:以下讨论只是针对InnoDB存储引擎. 何为死锁?   死锁是对资源 ...

  8. 【bzoj1520】[POI2006]Szk-Schools 费用流

    题目描述 输入 输出 如果有可行解, 输出最小代价,否则输出NIE. 样例输入 5 1 1 2 3 1 1 5 1 3 2 5 5 4 1 5 10 3 3 3 1 样例输出 9 题解 费用流 设xi ...

  9. Linux PC开发环境搭建建议

    搭建Linux PC开发环境 很早之前整理的在Linux(ubuntu)系统下搭建 PC开发环境的工具的推荐和简单说明,尽管现在有些已经不再使用,但还是要备份一下,作为以后的参考: package: ...

  10. 多啦A梦的制作

    小叮当简单颜色单一,操作起来也很容易上手.接下来的一个实例就是用css画出一个多啦A梦,首先将其分为头部,和身体.然后,再根据身体各部分细节进行进一步的具体刻画. 由于最近一直在学习JavaWeb方面 ...