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;
using ll = long long;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
const int maxn = 45;
template <class K, class V = __gnu_pbds::null_type>
using ordered_multiset = __gnu_pbds::tree<K, V, std::less_equal<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
int N;
ll M;
ll A[maxn], B[maxn];
int main()
{
cin >> N >> M;
int split = N/2;
for (int i = 0; i < split; i++) {
cin >> A[i];
}
for (int i = split; i < N; i++) {
cin >> B[i-split];
}
ordered_multiset<ll> s;
for (int i = 0; i < (1<<split); i++) {
ll total = 0;
for (int j = 0; j < split; j++) {
if (i & (1<<j)) total += A[j];
}
s.insert(total);
}
ll ans = 0;
for (int i = 0; i < (1<<(N-split)); i++) {
ll total = 0;
for (int j = 0; j < N-split; j++) {
if (i & (1<<j)) total += B[j];
}
if (total <= M) {
ans += s.order_of_key(M-total+1);
}
}
cout << ans << '\n';
}
# | 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... |