# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1124806 | luvna | Ice Hockey World Championship (CEOI15_bobek) | C++20 | 262 ms | 20900 KiB |
#include<bits/stdc++.h>
#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
using namespace std;
template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}
typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}
void solve(){
int n; ll limit; cin >> n >> limit;
vector<ll> a, b;
for(int i = 1; i <= n / 2; i++){
ll x; cin >> x;
a.pub(x);
}
for(int i = 1; i <= n - sz(a); i++){
ll x; cin >> x;
b.pub(x);
}
vector<ll> cntA, cntB;
for(int mask = 1; mask < (1 << sz(a)); mask++){
ll sum = 0;
for(int i = 0; i < sz(a); i++){
if(mask >> i & 1) sum += a[i];
}
if(sum > limit) continue;
cntA.pub(sum);
}
for(int mask = 1; mask < (1 << sz(b)); mask++){
ll sum = 0;
for(int i = 0; i < sz(b); i++){
if(mask >> i & 1) sum += b[i];
}
if(sum > limit) continue;
cntB.pub(sum);
}
ll ans = sz(cntA) + sz(cntB) + 1;
sort(all(cntA), greater<ll>());
sort(all(cntB));
for(int i = 0, j = 0; i < sz(cntA); i++){
while(j < sz(cntB) && cntA[i] + cntB[j] <= limit) j++;
ans += j;
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
Compilation message (stderr)
# | 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... |