Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n,x,t,rem,sum=0,ctr =0,curr=0;
    vector <ll> v(n);
    cin>>n>>x>>t;
    for(ll i = 0 ; i < n ; i++){
        cin>>v[i];
        sum+=v[i];
    }
    sum+= x;
    rem = t%sum;
    if(rem >= t){
        cout<<1<<endl;
        return 0;
    }
    sort(v.begin(),v.end());
    if(x >= rem){
        ctr++;
    }

    for(ll i = 0 ; i < n ; i++){
        curr+=v[i];
        if((curr < rem) && ((curr+x) >= rem)){
            ctr++;
        }
        else
            break;
    }
    cout<<ctr<<endl;
    return 0 ;
}
Copy
Treasure sarah_alsharif_
GNU G++17
2 ms
488 KB
Runtime Error