My issue
can u explain me third test case that how the answer is coming 4?
My code
#include<bits/stdc++.h>
#include<unordered_set>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
void tc(){
int n;ll c, sum=0;cin>>n>>c;
int a[100];
// vector<ll> vec;
for(int i=0; i<n; i++){
cin>>a[i];sum+=a[i];
}
sort(a, a+n);
// for(int i=0; i<n; i++)cout<<a[i]<<" ";
// cout<<endl<<sum<<endl;
int ans=0;
for(int i=0; i<n-1; i++){
sum-=a[i];
c-=(a[i]*sum);
if(c<0)break;
ans++;
}
cout<<n-ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
while(t>0){
t--;
tc();
cout<<endl;
}
return 0;
}
Problem Link: Destroying Bridges Part 2 Practice Coding Problem