题解
2023-03-31 21:13:41
发布于:上海
11阅读
0回复
0点赞
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll N=21;
ll n,T,sh,maxs,ans,w,MS;
struct node{
ll h,w,s;
}a[N];
bool cmp(node x,node y)
{return x.s+x.w>y.s+y.w;}
int main()
{
scanf("%lld%lld",&n,&T);
for(ll i=1;i<=n;i++)
scanf("%lld%lld%lld",&a[i].h,&a[i].w,&a[i].s);
sort(a+1,a+1+n,cmp);MS=1<<n;ans=-1;
for(ll i=0;i<MS;i++){
sh=w=0;maxs=2147483647;
for(ll j=n;j>=1;j--)
if((i>>j-1)&1){
sh+=a[j].h;
maxs=min(maxs,a[j].s-w);
w+=a[j].w;
}
if(sh<T) continue;
ans=max( maxs,ans);
}
if(ans<0)
printf("Mark is too tall");
else
printf("%lld",ans);
}
这里空空如也
有帮助,赞一个