题目传送门
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define read(x) scanf("%d",&x)
const int maxn=200010;
int a[maxn];
int dp[maxn][30];
int n,m;
void init()
{
for(int i=0; i<n; i++)dp[i][0]=a[i];
for(int j=1; (1<<j)<=n; j++)
{
for(int i=0; i+(1<<j)-1<n;i++)
dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
}
}
int RMQ(int L,int R)
{
int k=0;
while((1<<(k+1))<=R-L+1)k++;
return max(dp[L][k],dp[R-(1<<k)+1][k]);
}
bool check(int mid)
{
int len=n/mid;
int sum=0;
for(int i=0;i+len<=mid*len;i+=len)
sum+=RMQ(i,i+len-1);
if(sum>m)
return true;
return false;
}
int solve()
{
int left=1,right=n,mid;
while(left!=right)
{
mid=(left+right)>>1;
if(check(mid)) right=mid;
else left=mid+1;
}
return left;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
int sum=0;
if(n<0&&m<0)break;
for(int i=0; i<n; i++)
{
read(a[i]);
sum+=a[i];
}
if(sum<=m)
{
puts("-1");
continue;
}
else
{
init();
int ans=solve();
printf("%d\n",ans);
}
}
return 0;
}