B. Preparing Olympiad

_Yxc發表於2024-03-05

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

Brute force problem

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

	vector<int> 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';
}

相關文章