func_code_string: #include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using std::cerr;   using std::cin;   using std::cos;   using std::cout;   using std::endl;   using std::make_pair;   using std::max;   using std::min;   using std::next_permutation;   using std::pair;   using std::priority_queue;   using std::queue;   using std::random_shuffle;   using std::set;   using std::sin;   using std::sort;   using std::sqrt;   using std::stack;   using std::string;   using std::stringstream;   using std::swap;   using std::vector;   const long double PI = 3.14159265358979323846;   int main() {     int n, d, s;     long long sum = 0;     int add = 0;     cin >> n >> d >> s;     vector<pair<int, int> > can, ne;     for (int i = 0; i < n; ++i) {       int c, l, f;       cin >> c >> f >> l;       sum += c;       pair<int, int> p(f, c);       if (l < d) {         ne.push_back(p);         if (c) ++add;       } else         can.push_back(p);     }     sort(can.begin(), can.end());     int mr = 0;     long long fuel = 0;     while ((mr < can.size()) && (fuel + can[mr].first <= s)) {       fuel += can[mr].first;       ++mr;     }     vector<pair<int, int> > cacan, necan;     for (int i = 0; i < can.size(); ++i) {       if (can[i].second)         cacan.push_back(can[i]);       else         necan.push_back(can[i]);     }     vector<long long> cacans(cacan.size());     for (int i = 0; i < cacan.size(); ++i) {       if (i)         cacans[i] = cacans[i - 1] + cacan[i].first;       else         cacans[i] = cacan[i].first;     }     for (int k = 1; k <= cacan.size(); ++k) {       long long free = sum - (int)(cacan.size()) + k - add;       long long fu = cacans[k - 1];       if (fu > s) continue;       int num = necan.size() + ne.size() - add;       if (num <= free) {         if (mr < n) {           mr = n;           fuel = fu;         } else if (mr == n) {           if (fuel > fu) fuel = fu;         }         continue;       }       num -= free;       int mmr = n - num;       for (int i = 0; i < min(num, (int)necan.size()); ++i) {         if (fu + necan[i].first <= s) {           ++mmr;           fu += necan[i].first;         } else           break;       }       if (mmr > mr) {         mr = mmr;         fuel = fu;       } else if (mmr == mr)         if (fuel > fu) fuel = fu;     }     cout << mr <<     << fuel << endl;     return 0;   }   