# 挑剔的H胖胖

``````3 5
1 4 2
1 2 5
2 2 1``````

``14``

``````#include<cstdio>
#include<algorithm>
using namespace std;
struct note
{
int min;
int max;
int c;
};
bool cmp(note n1,note n2)
{
return n1.c>n2.c;
}
int main()
{
struct note s[105];
int i,j,k,m,n,t;
k=0,j=0;
int a,b,c;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d %d %d",&s[i].min,&s[i].max,&s[i].c);
k+=s[i].min;
j+=(s[i].min)*(s[i].c);
}
if(m<k)
printf("-1\n");
else
{
sort(s,s+n,cmp);
t=m-k;
for(i=0;i<n;i++)
{
if(t>=s[i].max-s[i].min)
{
t=t-s[i].max+s[i].min;
j=j+(s[i].max-s[i].min)*s[i].c;
}
else
{
j=j+(s[i].c)*t;
break;
}
}

printf("%d\n",j);
}

return 0;

}
``````

``````#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

struct node{
int x,y,z;};
bool cmp(node n1,node n2){

return n1.z > n2.z;

}
int main()
{
node items[105];
int m,n,cnt=0,cnt2=0,res=0;
cin>>m>>n;
for(int i=0;i<m;i++){
cin>>items[i].x>>items[i].y>>items[i].z;
cnt+=items[i].x;
cnt2+=items[i].y;
res+=(items[i].x*items[i].z);
}
if(cnt>n){
cout<<"-1"<<endl;
return 0;
}
n=n-cnt;
sort(items,items+m,cmp);
for(int i=0;i<m;i++){
if(n<=(items[i].y-items[i].x)){
res+=n*items[i].z;
break;
}
else{
res+=((items[i].y-items[i].x)*items[i].z);
n=n-(items[i].y-items[i].x);
}
}
cout<<res<<endl;
return 0;
}
``````