Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.0 kB
5
Indexable
Never
void solve ()
{
    int n,k;cin>>n>>k;
    vector<pair<int,int>>v1,v0;bool b=1;int l,m;int curr =0;int turn;
    For(n){
        cin>>b>>l>>m;
        if(b)v1.push_back({m,l});
        else v0.push_back({m,l});
        if(l<=k&&m>curr){
            turn=b;curr = m;
        }
    }
    sort(v1.begin(),v1.end(),cmp);sort(v0.begin(),v0.end(),cmp);
    int cnt = 0;bool f=true;
    while (n--&&f){
        f = false;        
        if(turn%2!=0){
            For(v1.size())
                if(v1[i].second<=k&&v1[i].second!=-1){
                    k+= v1[i].first;
                    v1[i].second =-1;
                    cnt++;turn++; f = true;
                    break;
                }
        }
        else{
            For(v0.size())
                if(v0[i].second<=k&&v0[i].second!=-1){
                    k+= v0[i].first;
                    v0[i].second =-1;
                    cnt++;turn++;f=true;
                    break;
                }
        }
    }
    cout << cnt << endl;
}
Leave a Comment