1 /*多么变态的一道题,交了18次*/ 2 3 4 #include5 #include 6 #include 7 #define max(a,b) (a>b?a:b) 8 int dp[200005][20],llog2[200005];//用llog2数组进行优化 9 int n,k;10 11 void DpMax(){12 for(int j=1;j<=llog2[n]+1;j++){ //llog213 for(int i=1;i+(1< <=n;i++){14 dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);15 }16 }17 }18 19 int GetMax(int L,int R){20 int j=llog2[R-L+1];//llog221 return max(dp[L][j],dp[R-(1< k)38 return i;39 }40 pre_tot = tot;41 pre_sum = sum;42 }43 else44 {45 for(int j = num; j <= sum; j += num)46 {47 tot += GetMax(j-num+1, j);48 if(tot > k)49 return i;50 }51 pre_num = num;52 pre_tot = tot;53 pre_sum = sum;54 }55 }56 return -1;57 }58 59 int main(){60 for(int i=2;i<200005;++i){ //llog261 llog2[i]=(i&(i-1))==0?llog2[i-1]+1:llog2[i-1];62 }63 while(scanf("%d%d",&n,&k),n>0||k>0){64 memset(dp,0,sizeof(dp));65 for(int i=1;i<=n;i++){66 scanf("%d",&dp[i][0]);67 }68 DpMax();69 printf("%d\n",work());70 }71 }72 73 74