结构体的排序
#include<bits/stdc++.h> using namespace std; struct node{ int p,w,v; friend bool operator<(node a,node b){ if(a.v==b.v&&a.p==b.p) return a.w<b.w; if(a.v==b.v) return a.p<b.p; return a.v>b.v; } }; vector<node> G; int main(){ int p,w,v; int n,m,k,i,j,ans; while(cin>>n>>m>>k){ G.clear(); for(i=0;i<n;i++){ cin>>p>>w>>v; G.push_back((node){p,w,v}); } sort(G.begin(),G.end()); ans=0; for(i=0;i<G.size();i++){ if(G[i].p<=k&&G[i].w<=m){ k-=G[i].p; m-=G[i].w; ans++; } } cout<<ans<<endl; } return 0; }