#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK ""
#define int long long
using namespace std;
typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;
const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 41;
int n, m;
int a[MX];
int f1[MASK(20) + 5];
int f2[MASK(20) + 5];
void nhap(){
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
}
void solve(){
int mid = n>>1;
int id1, id2; id1 = id2 = 0;
for(int mask=0; mask<MASK(mid); mask++){
id1++;
for(int f=mask; f; f-=-f&f){
int i = __lg(-f&f) + 1;
f1[id1] += a[i];
}
}
for(int mask=0; mask<MASK(n - mid); mask++){
id2++;
for(int f=mask; f; f-=-f&f){
int i = __lg(-f&f) + mid + 1;
f2[id2] += a[i];
}
}
sort(f1+1, f1+id1+1);
sort(f2+1, f2+id2+1);
int ans = 0;
for(int i=1; i<=id1; i++){
while(id2 >= 1 && f1[i] + f2[id2] > m) id2--;
ans += f1[i] + f2[id2] <= m? id2 : 0;
}
cout << ans;
}
int32_t main(){
fastIO;
// file(TASK);
nhap();
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 |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
344 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 |
792 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 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 |
16 ms |
1884 KB |
Output is correct |
2 |
Correct |
49 ms |
4548 KB |
Output is correct |
3 |
Correct |
203 ms |
16708 KB |
Output is correct |
4 |
Correct |
45 ms |
4440 KB |
Output is correct |
5 |
Correct |
7 ms |
1368 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
10 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2392 KB |
Output is correct |
2 |
Correct |
16 ms |
2000 KB |
Output is correct |
3 |
Correct |
75 ms |
8540 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
10 ms |
1336 KB |
Output is correct |
7 |
Correct |
10 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3420 KB |
Output is correct |
2 |
Correct |
72 ms |
6492 KB |
Output is correct |
3 |
Correct |
69 ms |
6516 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
36 ms |
6488 KB |
Output is correct |
6 |
Correct |
161 ms |
16728 KB |
Output is correct |
7 |
Correct |
68 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
12628 KB |
Output is correct |
2 |
Correct |
16 ms |
1880 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
148 ms |
12876 KB |
Output is correct |
7 |
Correct |
10 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1884 KB |
Output is correct |
2 |
Correct |
45 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
4 |
Correct |
6 ms |
988 KB |
Output is correct |
5 |
Correct |
41 ms |
6452 KB |
Output is correct |
6 |
Correct |
16 ms |
1884 KB |
Output is correct |
7 |
Correct |
190 ms |
16724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
16692 KB |
Output is correct |
2 |
Correct |
16 ms |
1880 KB |
Output is correct |
3 |
Correct |
5 ms |
856 KB |
Output is correct |
4 |
Correct |
205 ms |
16852 KB |
Output is correct |
5 |
Correct |
54 ms |
8528 KB |
Output is correct |
6 |
Correct |
10 ms |
1372 KB |
Output is correct |
7 |
Correct |
21 ms |
2524 KB |
Output is correct |