纪念品
#include <vector> #include <iostream> #include <map> #include <queue> using namespace std; int main() { int n, m, k; cin>>n>>m>>k; map<int, map<int, priority_queue<int, vector<int>, greater<>>>> mp; while(n>0) { n--; int price, weight, v; cin>>price>>weight>>v; mp[v][price].push(weight); } auto it = mp.rbegin(); int sumk = 0; int sumw = 0; int res_count = 0; for(;it != mp.rend(); it++){ //v l->s if(sumk == k || sumw == m) { cout<<res_count<<endl; return 0; } for(auto prices : it->second){ // price s->l if(sumk + prices.first > k) { break; }else{ if(sumk + it->first <= k && sumw + prices.second.top() <= m){ //put weight s->l res_count++; sumk += it->first; sumw += prices.second.top(); prices.second.pop(); } else { break; } } } } cout<<res_count<<endl; return 0; }