B. Preparing Olympiad

https://codeforces.com/problemset/problem/550/B

Brute force problem

void solve(){
int n, l, r, x;
cin >> n >> l >> r >> x;

vector a(n);
for(auto&t : a){
cin >> t;
}

int ans = 0;

for (int i = 0; i < (1 << n); ++i){
if (popcount(i) < 2){
continue;
}
long long cur = 0;
int maxn = -1e9;
int minn = 1e9;
for (int j = 0; j < n; ++j){
if ((i >> j) & 1){
maxn = max(maxn, a[j]);
minn = min(minn, a[j]);
cur += a[j];
}
}
if (maxn - minn >= x && cur >= l && cur <= r){
ans ++;
}
}

cout << ans << '\n';
}

posted @ 2024-03-05 21:25  _Yxc  阅读(41)  评论(0)    收藏  举报