Untitled
public
Apr 01, 2025
Never
11
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,t;int d[10001]; 4 priority_queue<int,vector<int>,greater<int> >que; 5 int main(){ 6 cin>>n>>t; 7 for(int i=1;i<=n;++i)cin>>d[i]; 8 int L=1,R=n,i=(L+R)>>1; 9 while(L<=R){int j,maxx=0,i=(L+R)>>1; 10 for(j=1;j<=i;++j){que.push(d[j]);} 11 while(!que.empty()){ 12 if(j>n){ 13 maxx=max(maxx,que.top()); 14 que.pop(); 15 }else{ 16 que.push(d[j]+que.top()); 17 maxx=max(maxx,que.top()); 18 que.pop(); 19 } 20 ++j; 21 } 22 if(maxx<=t){ 23 R=i-1; 24 }else{ 25 L=i+1; 26 } 27 } 28 cout<<L<<endl; 29 return 0; 30 }