I have coded up the following solution to CSES’ Apple Division problem. When I individually run the test cases from CSES on my local compiler, I get the correct result. But, upon submitting the problem to the online grader, all I get for each test case is a 0. Not sure why this is happening.

Here’s my code:

```
#include <bits/stdc++.h>
using namespace std;
int n, arr[25];
vector<long long> weightSet;
long long ans = 1e7;
void perm(int idx) {
if(idx == n) {
bool setCheck[25]; memset(setCheck, -1, sizeof(setCheck));
long long setWeight = 0;
for(int i = 0; i < weightSet.size(); i++) {
setWeight+=arr[weightSet[i]];
setCheck[weightSet[i]] = 1;
}
long long remainingWeight = 0; for(int i = 0; i < n; i++) if(setCheck[i] != 1) remainingWeight+=arr[i];
ans = min(ans, llabs(setWeight - remainingWeight));
} else {
perm(idx+1);
weightSet.push_back(idx);
perm(idx+1);
weightSet.pop_back();
}
}
int main() {
cin >> n; for(int i = 0; i < n; i++) cin >> arr[i];
perm(0);
cout << ans << endl;
}
```

I’ve used simple recursion to generate subsets for each group, and for each subset I am storing the minimum difference value in the `ans`

variable.

Any help would be appreciated!