40pts求调
查看原帖
40pts求调
690320
MoGuYun_12楼主2024/11/3 12:24
#include <bits/stdc++.h>

using namespace std;
#define N 10005
typedef long long ll;

int n,a[N],T;

bool check(int x){
	priority_queue <ll,vector<ll>,greater<ll> > q;
	for(int i=1;i<=x;i++) q.push(a[i]);
	int now=x+1; ll ans;
	while(now<=n){
		int mn=q.top(); q.pop();
		mn+=a[now];
		q.push(mn);
		now++;
	}
	while(!q.empty()) {
		ans=q.top(); q.pop(); }
	return ans<=T;
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>T;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	} 
	cout<<l;
	return 0;
}

2024/11/3 12:24
加载中...