Ankit_132

Dotify Playlist

May 31st, 2023
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.    
  6.     int t;
  7.     cin>>t;
  8.    
  9.     while(t--)
  10.     {
  11.         int n, k, L;
  12.         cin>>n>>k>>L;
  13.        
  14.         vector<int> v;
  15.        
  16.         for(int i=0; i<n; i++)
  17.         {
  18.             int m, l;
  19.             cin>>m>>l;
  20.            
  21.             if(l != L)      continue;
  22.            
  23.             v.push_back(m);
  24.         }
  25.        
  26.         if(v.size() < k)
  27.         {
  28.             cout<<-1<<"\n";
  29.             continue;
  30.         }
  31.        
  32.         int ans = 0;
  33.         sort(v.rbegin(), v.rend());
  34.        
  35.         for(int i=0; i<k; i++)
  36.             ans += v[i];
  37.            
  38.         cout<<ans<<"\n";
  39.     }
  40.    
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment