My code is working for all the test cases on problem page but when I submit it it shows me wrong answer. So what are the possible corner cases.
Link to the problem: https://www.codechef.com/problems/MARCHA1
My solution:
#include
#include
using namespace std;
int solve(int i, int m, int *a) {
for (int j = i - 1; j >= 0; j--) {
if (a[j] == m)
return 1;
if (a[j] < m) {
int sum = m - a[j];
return solve(j, sum, a);
}
}
return 0;
}
int main() {
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
int *a = new int[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (solve(n, m, a)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}