Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //{ Driver Code Starts
- //Initial Template for C++
- #include <bits/stdc++.h>
- using namespace std;
- // } Driver Code Ends
- //User function Template for C++
- class Solution{
- public:
- int toyCount(int N, int K, vector<int> arr)
- {
- // code here
- vector<int> smaller;
- for(int i=0;i<N;i++)
- {
- if(arr[i]<K)
- {
- smaller.push_back(arr[i]);
- }
- }
- sort(smaller.begin(),smaller.end());
- int sum=0;
- int c=0;
- for(int i=0;i<smaller.size();i++)
- {
- if(sum+smaller[i]<=K)
- {
- c++;
- sum+=smaller[i];
- }
- }
- return c;
- }
- };
- //{ Driver Code Starts.
- int main(){
- int t;
- cin>>t;
- while(t--){
- int N, K;
- cin>>N>>K;
- vector<int> arr(N);
- for(int i = 0;i < N;i++)
- cin>>arr[i];
- Solution ob;
- cout<<ob.toyCount(N, K, arr)<<endl;
- }
- return 0;
- }
- // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment