显示代码纯文本
#include<cstdio>
#define is(a) ((a)>='0'&&(a)<='9')
using namespace std;
typedef long long LL;
char ch;bool read_flag;
inline void read(int& x)
{
x=0,read_flag=false;
while(ch=getchar(),!is(ch))if(ch=='-')read_flag=1;
do x=x*10+(ch^'0'),ch=getchar(); while(is(ch));
if(read_flag) x=-x;
}
const int Size=50010;
int n,m;
struct HP{
int hp[Size];
}a,temp;
inline void cut(LL x,int i,int num)
{
for(int j=i-1;j>0;j--){
LL t=x-(i-j)*(i-j);
t*=num;
if(t<=0) return ;
temp.hp[j]-=t;
}
}
inline bool judge(int x)
{
temp=a;
int k=0,i;
for(i=n;i>0;i--){
if(temp.hp[i]>=0){
int cnt=0;
while(temp.hp[i]>=0) k++,cnt++,temp.hp[i]-=x;
cut(x,i,cnt);
}
if(k>m) return false;
}
return true;
}
int _521()
{
#define enjoy_coding
#ifdef enjoy_coding
freopen("Keller_T1.in","r",stdin);
freopen("Keller_T1.out","w",stdout);
#else
freopen("1.in","r",stdin);
#endif
int i,j;
LL l=0,r=0,mid,ans=0;
read(n),read(m);
for(i=1;i<=n;i++) read(a.hp[i]),r+=a.hp[i]+1;
while(l<=r){
mid=l+r>>1;
if(judge(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
printf("%I64d\n",ans);
return 0;
}
int _520=_521();
int main(){;}