Can you find the bug


#1

Here’s my code
Works for the test case but fails while submitting

int n,s;
vector a;
unordered_set ans;
vector<vector<vector>> dp;

bool possible(int i, int csum, int csize){
if (i>=n || csum<0) return 0;
int &r=dp[i][csum][csize];
if (r!=-1) return r;
bool pos1=possible(i+1, csum, csize), pos2;
csum-=a[i], csize–;
if (!csum && !csize) pos2=1;
else if (!csum || !csize) pos2=0;
else pos2=possible(i+1, csum, csize);
r=pos1|pos2;
if (!pos1 && pos2) ans.insert(i);
return r;
}

vector<vector > Solution::avgset(vector &A) {
//sort(A.begin(),A.end());
n=A.size();
if (n==1) return {{}};
s=0;
a.resize(n);
for (int i=0;i<n;i++) {
s+=A[i];
a[i]=A[i];
}
//cout<<s<<" “<<n<<endl;
dp=vector<vector<vector>> (n,vector<vector> (s/2+1,vector (n/2,-1)));
ans.clear();
int j=0;
for (int i=0;i<n;i++) dp[i][0][0]=1;
for (int i=1;i<=n/2;i++){
int csum=is/n;
if (csum
n!=s*i) continue;
//cout<<csum<<” "<<i<<endl;
if (possible(0,csum,i)){
//cout<<i<<endl;
j=1;
break;
}
else ans.clear();
}
vector<vector> res;
if (j){
res.resize(2);
for (int i=0;i<n;i++){
if (ans.find(i)==ans.end()){
res[1].push_back(A[i]);
}
else res[0].push_back(A[i]);
}
sort(res[0].begin(),res[0].end());
sort(res[1].begin(),res[1].end());
}
return res;
}