#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly
/*
TASK: hidden
LANG: C++11
*/
using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 43
#define INF 1000000000000000000LL
#define mp make_pair
#define add push_back
#define remove pop
int n;
ll values[MAXN];
int size1, size2;
ll m;
vector<ll> one;
vector<ll> two;
void dfs1(int depth, ll sum, int bound, vector<ll> &target) {
if (depth == bound) {
target.add(sum);
return;
}
dfs1(depth + 1, sum + values[depth], bound, target);
dfs1(depth + 1, sum, bound, target);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> values[i];
}
dfs(0, 0, n / 2, one);
dfs(n / 2, 0, n, two);
sort(one.begin(), one.end());
sort(two.begin(), two.end());
//assert(one.size() + two.size() < 5000000);
ll answer = 0;
int twopointer = two.size() - 1;
for (int i = 0; i < (int) (one.size()); i++) {
if (one[i] > m) break;
while (twopointer >= 0 && two[twopointer] > m - one[i]) {
twopointer--;
}
answer += twopointer + 1;
}
cout << answer << endl;
}
Compilation message
bobek.cpp: In function 'int main()':
bobek.cpp:48:22: error: 'dfs' was not declared in this scope
dfs(0, 0, n / 2, one);
^