# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445910 | snasibov05 | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 0 ms | 0 KiB |
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 <iostream>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
int main() {
int n; ll m; cin >> n >> m;
vector<ll> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
int mid = (n-1) / 2;
vector<ll> p1;
p1.pb(0);
for (int i = 0; i < (1 << (mid+1)); ++i) {
ll sum = 0;
int x = i;
for (int j = 0; j <= mid; ++j) {
if (x % 2 == 1) sum += v[j];
x /= 2;
}
if (sum <= m) p1.pb(sum);
}
sort(p1.begin(), p1.end());
ll ans = p1.size();
for (int i = 0; i < (1 << (n - mid - 1)); ++i) {
ll sum = 0;
int x = i;
for (int j = mid + 1; j < n; ++j) {
if (x % 2 == 1) sum += v[j];
x /= 2;
}
if (sum > m) continue;
int k = upper_bound(p1.begin(), p1.end(), m - sum) - p1.begin();
ans += 1ll * k;
}
ans /= 2;
cout << ans << "\n";
return 0;
}