# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445910 | 2021-07-20T07:27:22 Z | snasibov05 | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 0 ms | 0 KB |
#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; }