#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
void solve(){
int n; cin >> n;
ll m; cin >> m;
vector<ll> a, b;
for(int i=1; i<=n; i++){
ll u; cin >> u;
if(i * 2 <= n) a.push_back(u);
else b.push_back(u);
}
vector<ll> s1, s2;
for(int mask=0; mask<MASK(sz(a)); mask++){
ll sum = 0;
for(int i=0; i<sz(a); i++) if(BIT(mask, i)){
sum += a[i];
}
s1.push_back(sum);
}
for(int mask=0; mask<MASK(sz(b)); mask++){
ll sum = 0;
for(int i=0; i<sz(b); i++) if(BIT(mask, i)){
sum += b[i];
}
s2.push_back(sum);
}
sort(ALL(s1));
sort(ALL(s2));
ll ans = 0;
for(ll x: s1){
ll p = upper_bound(ALL(s2), m - x) - s2.begin();
ans += p;
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("task.inp", "r", stdin);
// freopen("task.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
456 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1888 KB |
Output is correct |
2 |
Correct |
76 ms |
5584 KB |
Output is correct |
3 |
Correct |
304 ms |
20952 KB |
Output is correct |
4 |
Correct |
71 ms |
5572 KB |
Output is correct |
5 |
Correct |
14 ms |
1752 KB |
Output is correct |
6 |
Correct |
8 ms |
992 KB |
Output is correct |
7 |
Correct |
17 ms |
1556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3032 KB |
Output is correct |
2 |
Correct |
26 ms |
2144 KB |
Output is correct |
3 |
Correct |
121 ms |
11452 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
1112 KB |
Output is correct |
6 |
Correct |
17 ms |
1500 KB |
Output is correct |
7 |
Correct |
19 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
3660 KB |
Output is correct |
2 |
Correct |
105 ms |
8264 KB |
Output is correct |
3 |
Correct |
103 ms |
8272 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
69 ms |
7000 KB |
Output is correct |
6 |
Correct |
259 ms |
21260 KB |
Output is correct |
7 |
Correct |
101 ms |
8012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
13376 KB |
Output is correct |
2 |
Correct |
25 ms |
2140 KB |
Output is correct |
3 |
Correct |
8 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
206 ms |
14080 KB |
Output is correct |
7 |
Correct |
16 ms |
1752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
2144 KB |
Output is correct |
2 |
Correct |
72 ms |
5396 KB |
Output is correct |
3 |
Correct |
9 ms |
1116 KB |
Output is correct |
4 |
Correct |
9 ms |
1116 KB |
Output is correct |
5 |
Correct |
76 ms |
8552 KB |
Output is correct |
6 |
Correct |
24 ms |
2144 KB |
Output is correct |
7 |
Correct |
293 ms |
20824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
20948 KB |
Output is correct |
2 |
Correct |
25 ms |
2144 KB |
Output is correct |
3 |
Correct |
9 ms |
1116 KB |
Output is correct |
4 |
Correct |
299 ms |
20812 KB |
Output is correct |
5 |
Correct |
101 ms |
11436 KB |
Output is correct |
6 |
Correct |
17 ms |
1752 KB |
Output is correct |
7 |
Correct |
34 ms |
3032 KB |
Output is correct |