Problem :WIPL Problem - CodeChef
Why my subtask 1 Subtask 1 (30 points):. is giving wrong answers.
I have written basic recursive code, so it should pass subtask 1(30 points) but it is giving WAs.Sample test cases are passing.
Can some help me figure out the bug in my code ?? I think I have done everything correctly.
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
typedef long long ll;
ll fun(ll *arr,ll n,ll k,ll h1,ll h2)
{
if(n<=0 )
{
return 1e9;
}
if(h1>=k && h2>=k )
{
return n;
}
if(h2>=k && h1<k )
{
return fun(arr,n-1,k,h1+arr[n-1],h2);
}
if(h1>=k && h2<k )
{
return fun(arr,n-1,k,h1,h2+arr[n-1]);
}
return min( fun(arr,n-1,k,h1+arr[n-1],h2) , fun(arr,n-1,k,h1,h2+arr[n-1]));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n,k;cin>>n>>k;
ll arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);
ll h1=0;
ll h2=0;
ll x = fun(arr,n,k,h1,h2);
if(x==1e9)
{
cout<<-1<<endl;
}
else
cout<<n-x<<endl;
}
}