Language: C++

void solve(){
    int n,k,m;
    cin >> n >> m>> k;
    vector< pii > oo , oz , zo , zz;
    for(int i=0 ; i<n ;i++){
        int a, b , c;
        cin >> a >> b >> c;
        if(max(b ,c)==0){
            zz.pb({a , i});
        }
        else if(b == 1 && c == 1){
            oo.pb({a, i});
        }
        else if(b == 1 && c == 0){
            oz.pb({a , i});
        }
        else{
            zo.pb({a , i});
        }
    }
    sort(all(oo));
    sort(all(oz));
    sort(all(zo));
    sort(all(zz));
    int kk = 0 , l = 0, r = 0 , ans = 0 , z = 0 , rr = 0;
    vector< int > res;
    while(m--){
        if(kk < k ){
            int p1 =-1  , p2 = -1;
            if(l < oo.size())
                p1 = oo[l].F;
            if(r < min(zo.size() , oz.size()))
                p2 = oz[r].F + zo[r].F;
            if(p1 == -1 && p2 == -1) break;
            else if(p1 == -1){
                if(m>=1){
                    ans += p2;
                    res.pb(oz[r].S);
                    res.pb(zo[r].S);
                    kk++;
                    m--;
                }
                else{
                    m++;
                }
                r++;
                rr++;
                continue;
            }
            else if(p2 == -1){
                ans+=p1;
                res.pb(oo[l].S);
                l++;
                kk++;
                continue;
            }
            if(p1 < p2){
                ans+=p1;
                res.pb(oo[l].S);
                l++;
                kk++;
            }
            else{
                if(m >=1){
                    ans+=p2;
                    res.pb(oz[r].S);
                    res.pb(zo[r].S);
                    m--;
                    kk++;
                }
                else{
                    m++;
                }
                r++;
                rr++;
            }
        }
        else{
            int p1 = INF , p2 = INF , p3 = INF , p4 = INF;
            if(l < oo.size())
                p1 = oo[l].F;
            if(r < zo.size())
                p2 = zo[r].F;
            if(rr < oz.size())
                p4 = oz[rr].F;
            if(z < zz.size()) {
                p3 = zz[z].F;
            }
            if(p1 == INF && p2 == INF && p3 == INF  && p4 == INF) break;
            int mn = min({p1 , p2 , p3 , p4});
            if(mn == p1){
                ans+=p1;
                res.pb(oo[l].S);
                l++;
            }
            else if(mn == p3){
                ans+=p3;
                res.pb(zz[z].S);
                z++;
            }
            else if (mn == p2){
                ans+=p2;
                res.pb(zo[r].S);
                r++;
            }
            else{
                ans+=mn;
                res.pb(oz[rr].S);
                rr++;
            }
        }
    }
    if(kk < k || m >= 0){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;
    for(auto x : res ){
        cout << x+1<< " ";
    }
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:3:5: error: 'cin' was not declared in this scope
    3 |     cin >> n >> m>> k;
      |     ^~~
a.cc:4:5: error: 'vector' was not declared in this scope
    4 |     vector< pii > oo , oz , zo , zz;
      |     ^~~~~~
a.cc:4:13: error: 'pii' was not declared in this scope
    4 |     vector< pii > oo , oz , zo , zz;
      |             ^~~
a.cc:4:19: error: 'oo' was not declared in this scope
    4 |     vector< pii > oo , oz , zo , zz;
      |                   ^~
a.cc:4:24: error: 'oz' was not declared in this scope
    4 |     vector< pii > oo , oz , zo , zz;
      |                        ^~
a.cc:4:29: error: 'zo' was not declared in this scope
    4 |     vector< pii > oo , oz , zo , zz;
      |                             ^~
a.cc:4:34: error: 'zz' was not declared in this scope
    4 |     vector< pii > oo , oz , zo , zz;
      |                                  ^~
a.cc:8:12: error: 'max' was not declared in this scope
    8 |         if(max(b ,c)==0){
      |            ^~~
a.cc:21:10: error: 'all' was not declared in this scope
   21 |     sort(all(oo));
      |          ^~~
a.cc:21:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   21 |     sort(all(oo));
      |     ^~~~
      |     short
a.cc:26:13: error: expected primary-expression before 'int'
   26 |     vector< int > res;
      |             ^~~
a.cc:32:20: error: 'min' was not declared in this scope
   32 |             if(r < min(zo.size() , oz.size()))
      |                    ^~~
a.cc:38:21: error: 'res' was not declared in this scope
   38 |                     res.pb(oz[r].S);
      |                     ^~~
a.cc:52:17: error: 'res' was not declared in this scope
   52 |                 res.pb(oo[l].S);
      |                 ^~~
a.cc:59:17: error: 'res' was not declared in this scope
   59 |                 res.pb(oo[l].S);
      |                 ^~~
a.cc:66:21: error: 'res' was not declared in this scope
   66 |                     res.pb(oz[r].S);
      |                     ^~~
a.cc:79:22: error: 'INF' was not declared in this scope
   79 |             int p1 = INF , p2 = INF , p3 = INF , p4 = INF;
      |                      ^~~
a.cc:83:17: error: 'p2' was not declared in this scope; did you mean 'p1'?
   83 |                 p2 = zo[r].F;
      |                 ^~
      |                 p1
a.cc:85:17: error: 'p4' was not declared in this scope; did you mean 'p1'?
   85 |                 p4 = oz[rr].F;
      |                 ^~
      |                 p1
a.cc:87:17: error: 'p3' was not declared in this scope; did you mean 'p1'?
   87 |                 p3 = zz[z].F;
      |                 ^~
      |                 p1
a.cc:89:29: error: 'p2' was not declared in this scope; did you mean 'p1'?
   89 |             if(p1 == INF && p2 == INF && p3 == INF  && p4 == INF) break;
      |                             ^~
      |                             p1
a.cc:89:42: error: 'p3' was not declared in this scope; did you mean 'p1'?
   89 |             if(p1 == INF && p2 == INF && p3 == INF  && p4 == INF) break;
      |                                          ^~
      |                                          p1
a.cc:89:56: error: 'p4' was not declared in this scope; did you mean 'p1'?
   89 |             if(p1 == INF && p2 == INF && p3 == INF  && p4 == INF) break;
      |                                                        ^~
      |                                                        p1
a.cc:90:32: error: 'p2' was not declared in this scope; did you mean 'p1'?
   90 |             int mn = min({p1 , p2 , p3 , p4});
      |                                ^~
      |                                p1
a.cc:90:37: error: 'p3' was not declared in this scope; did you mean 'p1'?
   90 |             int mn = min({p1 , p2 , p3 , p4});
      |                                     ^~
      |                                     p1
a.cc:90:42: error: 'p4' was not declared in this scope; did you mean 'p1'?
   90 |             int mn = min({p1 , p2 , p3 , p4});
      |                                          ^~
      |                                          p1
a.cc:90:22: error: 'min' was not declared in this scope; did you mean 'mn'?
   90 |             int mn = min({p1 , p2 , p3 , p4});
      |                      ^~~
      |                      mn
a.cc:93:17: error: 'res' was not declared in this scope
   93 |                 res.pb(oo[l].S);
      |                 ^~~
a.cc:98:17: error: 'res' was not declared in this scope
   98 |                 res.pb(zz[z].S);
      |                 ^~~
a.cc:103:17: error: 'res' was not declared in this scope
  103 |                 res.pb(zo[r].S);
      |                 ^~~
a.cc:108:17: error: 'res' was not declared in this scope
  108 |                 res.pb(oz[rr].S);
      |                 ^~~
a.cc:114:9: error: 'cout' was not declared in this scope
  114 |         cout << -1 << endl;
      |         ^~~~
a.cc:114:23: error: 'endl' was not declared in this scope
  114 |         cout << -1 << endl;
      |                       ^~~~
a.cc:117:5: error: 'cout' was not declared in this scope
  117 |     cout << ans << endl;
      |     ^~~~
a.cc:117:20: error: 'endl' was not declared in this scope
  117 |     cout << ans << endl;
      |                    ^~~~
a.cc:118:18: error: 'res' was not declared in this scope
  118 |     for(auto x : res ){
      |                  ^~~