Untitled

Anonymous
Plain Text
11/04/2026 6:48 PM
710 B
10
Indexable
Never
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define el endl 
#define PI 3.14159265358979323846
using namespace std;
void fastIO(){ios::sync_with_stdio(false);cin.tie(nullptr);}
 



void testCase()
{
    int n,l,r,k;
    cin>>n>>l>>r>>k;

    vector <ll>bar(n);

    for(int i=0;i<n;i++){
        cin>>bar[i];
    }
    sort(bar.begin(),bar.end());
    int cnt=0;
    int i=0;
    while(k>0 && i<n){
        if(bar[i]>=l && bar[i]<=r && (k-bar[i])>=0){cnt++;k-=bar[i];}
        i++;
    }
    cout<<cnt<<el;
}
 
 
 
 
 
int main()
{
    fastIO();
    int t=1;
    cin>>t;
 
    while(t--){
        testCase();
    }
 
    
    return 0;
}
Editor is loading...
Leave a Comment