Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL))
- #define eb emplace_back
- int main()
- {
- fast();
- ll n,k;
- cin>>n>>k;
- vector<ll>both,alice,bob;
- ll t,a,b;
- for(ll i=0;i<n;i++)
- {
- cin>>t>>a>>b;
- if(a==1 && b==1)both.eb(t);
- else if(a==1)alice.eb(t);
- else if(b==1)bob.eb(t);
- }
- sort(alice.begin(),alice.end());
- sort(bob.begin(),bob.end());
- for(ll i=0;i<alice.size() && i<bob.size();i++)
- {
- both.eb(alice[i]+bob[i]);
- }
- sort(both.begin(),both.end());
- ll cnt=0,ans=0;
- for(ll i=0;i<both.size();i++)
- {
- if(cnt==k)break;
- ans+=both[i];
- cnt++;
- }
- if(cnt==k)cout<<ans<<endl;
- else cout<<-1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement