jakaria_hossain

codeforces - reading books

Jun 29th, 2020
1,063
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL))
  5. #define eb emplace_back
  6. int main()
  7. {
  8.     fast();
  9.     ll n,k;
  10.     cin>>n>>k;
  11.     vector<ll>both,alice,bob;
  12.     ll t,a,b;
  13.     for(ll i=0;i<n;i++)
  14.     {
  15.         cin>>t>>a>>b;
  16.         if(a==1 && b==1)both.eb(t);
  17.         else if(a==1)alice.eb(t);
  18.         else if(b==1)bob.eb(t);
  19.     }
  20.     sort(alice.begin(),alice.end());
  21.     sort(bob.begin(),bob.end());
  22.     for(ll i=0;i<alice.size() && i<bob.size();i++)
  23.     {
  24.         both.eb(alice[i]+bob[i]);
  25.     }
  26.     sort(both.begin(),both.end());
  27.     ll cnt=0,ans=0;
  28.     for(ll i=0;i<both.size();i++)
  29.     {
  30.         if(cnt==k)break;
  31.         ans+=both[i];
  32.         cnt++;
  33.     }
  34.     if(cnt==k)cout<<ans<<endl;
  35.     else cout<<-1<<endl;
  36. }
RAW Paste Data