题意:
导图
代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
struct node{
int s,e,l;
bool operator<(const node & t)const{
return s*t.l<t.s*l;
}
};
node store[N];
int f[N];
int n,m;
int main()
{
int T;
cin>>T;
for(int C=1;C<=T;C++)
{
cin>>n;
m=0;
for(int i=0;i<n;i++)
{
int s,e,l;
cin>>s>>e>>l;
m+=s;
store[i]={s,e,l};
}
sort(store,store+n);
memset(f,-0x3f,sizeof f);
f[0]=0;
for(int i=0;i<n;i++)
{
int s=store[i].s,e=store[i].e,l=store[i].l;
for(int j=m;j>=s;j--)
f[j]=max(f[j],f[j-s]+e-(j-s)*l);
}
int res=0;
for(int i=0;i<=m;i++) res=max(res,f[i]);
cout<<"Case #"<<C<<": ";
cout<<res<<endl;
}
}