func_code_string: #include <bits/stdc++.h>   using namespace std;   struct sak {     int x, y;     sak(int x1, int y1) {       x = x1;       y = y1;     }   };   vector<sak> A, B;   vector<int> AA, BB;   int findA(int k) {     int t1 = -1;     for (int i = 0; i < A.size(); i++)       if (A[i].x <= k && AA[i] == 0 && (t1 == -1 || A[t1].y < A[i].y)) {         t1 = i;       }     return t1;   }   int findB(int k) {     int t1 = -1;     for (int i = 0; i < B.size(); i++)       if (B[i].x <= k && BB[i] == 0 && (t1 == -1 || B[t1].y < B[i].y)) {         t1 = i;       }     return t1;   }   int main() {     int n, k;     while (scanf( %d %d , &n, &k) == 2) {       int x, y, z;       A.clear();       B.clear();       AA.clear();       BB.clear();       for (int i = 0; i < n; i++) {         scanf( %d %d %d , &x, &y, &z);         if (x == 0) {           A.push_back(sak(y, z));           AA.push_back(0);         } else {           B.push_back(sak(y, z));           BB.push_back(0);         }       }       int maxi = 0;       int sak1 = findA(k);       if (A.size() > 0 && sak1 != -1) {         int cnt = 1;         x = 1;         y = 0;         int kk = k + A[sak1].y;         AA[sak1] = 1;         while (1) {           sak1 = findB(kk);           if (sak1 == -1) break;           cnt++;           kk += B[sak1].y;           BB[sak1] = 1;           y++;           sak1 = findA(kk);           if (sak1 == -1) break;           cnt++;           kk += A[sak1].y;           AA[sak1] = 1;           x++;         }         if (cnt > maxi) maxi = cnt;       }       for (int i = 0; i < AA.size(); i++) AA[i] = 0;       for (int i = 0; i < BB.size(); i++) BB[i] = 0;       sak1 = findB(k);       if (B.size() > 0 && sak1 != -1) {         int cnt = 1;         x = 0;         y = 1;         int kk = k + B[sak1].y;         BB[sak1] = 1;         while (1) {           sak1 = findA(kk);           if (sak1 == -1) break;           cnt++;           kk += A[sak1].y;           AA[sak1] = 1;           x++;           sak1 = findB(kk);           if (sak1 == -1) break;           cnt++;           kk += B[sak1].y;           BB[sak1] = 1;           y++;         }         if (cnt > maxi) maxi = cnt;       }       printf( %d n , maxi);     }     return 0;   }   