Idea: To find the maximum minimum value, first think of dichotomy. We found that this time t satisfies the monotonicity of the answer, so we dichotomy the answer. When we check, we find that we judge whether the minimum value of the interval of length x is less than t, dp[i] Means 1-i-1 position satisfies the meaning of the question and the i position must be written, then you can get dp[i]=min(dp[j])+w[i] we can use a monotonic queue to maintain dp[j]
#pragma GCC optimize(2)#include<cstdio>#include<cstring>#include<algorithm>#include<set>#include<iostream>#include<vector>#include<queue>#include<map>#include<stack>#include<iomanip>#include<cstring>#include<time.h>usingnamespace std;typedeflonglong ll;#define SIS std::ios::sync_with_stdio(false)#define space putchar(' ')#define enter putchar('\n')#define lson root<<1#define rson root<<1|1typedef pair<int,int> PII;constint mod=1e9+7;constint N=2e6+10;constint M=1e5+10;constint inf=0x3f3f3f3f;constint maxx=2e5+7;constdouble eps=1e-6;intgcd(int a,int b){
return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){
return a*(b/gcd(a,b));}template<classT>voidread(T &x){
char c;bool op =0;while(c =getchar(), c <'0'|| c >'9')if(c =='-')
op =1;
x = c -'0';while(c =getchar(), c >='0'&& c <='9')
x = x *10+ c -'0';if(op)
x =-x;}template<classT>voidwrite(T x){
if(x <0)
x =-x,putchar('-');if(x >=10)write(x /10);putchar('0'+ x %10);}
ll qsm(int a,int b,int p){
ll res=1%p;while(b){
if(b&1)
res=res*a%p;
a=1ll*a*a%p;
b>>=1;}return res;}int n, m;int dp[N];int q[N];int w[N];boolcheck(int x){
int hh=0,tt=0;for(int i=1;i<=n;i++){
if(q[hh]<i-x-1)hh++;
dp[i]=dp[q[hh]]+w[i];while(hh<=tt&&dp[q[tt]]>=dp[i])tt--;
q[++tt]=i;}for(int i=n-x;i<=n;i++)if(dp[i]<=m)returntrue;returnfalse;}intmain(){
cin>>n>>m;int l=0,r=n;for(int i=1;i<=n;i++)cin>>w[i];while(l<=r){
int mid=l+r>>1;if(check(mid)) r=mid-1;else l=mid+1;}
cout<<r+1<<endl;return0;}