This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 40;
const int maxc = (1 << 20) + 10;
int A, B;
int n, m;
int a[maxn];
int b[maxn];
long long a2[maxc];
long long b2[maxc];
long long ans;
void in();
void solve();
void out();
int main(){
in();
solve();
out();
}
void in(){
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = 0; i < n / 2; i++)
cin >> a[i + 1];
A = n / 2;
for(int i = n / 2; i < n; i++)
cin >> b[i - n / 2 + 1];
B = n - A;
}
void solve(){
for(int i = 1; i < (1 << A); i++){
a2[i] = a2[i - (i & -i)];
a2[i] += a[__builtin_ctz(i) + 1];
}
for(int i = 1; i < (1 << B); i++){
b2[i] = b2[i - (i & -i)];
b2[i] += b[__builtin_ctz(i) + 1];
}
sort(a2, a2 + (1 << A));
sort(b2, b2 + (1 << B));
A = 1 << A;
B = 1 << B;
int nowb = B - 1;
for(int i = 0; i < A; i++){
while(nowb != -1 && b2[nowb] + a2[i] > m)
nowb--;
ans += nowb + 1;
}
}
void out(){
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |