hiho week 69 register

Ended

Participants:406

Verdict:Accepted
Score:100 / 100
Submitted:2015-10-27 03:11:44

Lang:G++

Edit
1
2
3
4
5
#include <cstdio>
int n,k,d[100001],i,l,h,m,s,v,c;
void R(int&v){for(c=0;c<48;c=getchar());for(c^=48;c<=9;c=getchar()^48)v=v*10+c;}
bool J(int t){for(s=v=i=0;i<n;++i){v+=t;v-=v>d[i]?++s,d[i]:v;}return s>n/2;}
int main(){R(n);R(k);for(i=0;i<n;++i)R(d[i]);l=1;h=k+1;while(l<h){m=(l+h)/2;J(m)?h=m:l=m+1;}printf("%d\n",l);}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX